-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore-bot.js
More file actions
143 lines (132 loc) · 4.44 KB
/
score-bot.js
File metadata and controls
143 lines (132 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import dotenv from "dotenv";
dotenv.config();
import Discord from "discord.js";
import fetch from "node-fetch";
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("message", async (msg) => {
const resp = msg.content.split(" ");
if (resp.length !== 2) return;
const BASE_URL = "https://competitive-coding-api.herokuapp.com/api/";
var CURR_URL = "";
var count = 0;
var chef_count = 0;
var spoj_count = 0;
var force_count = 0;
var bit_count = 0;
// --------------------------------------------- codechef-count ----------------------------------------- //
if (resp[0] === "@" || resp[0] === "&") {
CURR_URL = BASE_URL + "codechef/" + resp[1];
const response = await fetch(CURR_URL);
var count_t = await response.json();
if (count_t.status !== "Failed") {
chef_count = count_t.fully_solved.count;
if (resp[0] === "@") {
msg.reply(
resp[1] +
" successfully submitted " +
chef_count +
" problems at codechef. "
);
}
} else {
if (resp[0] === "@")
msg.reply(
"OOPS! Invalid codechef handle, type . command to know more. "
);
}
}
// --------------------------------------------- spoj-count -------------------------------------------- //
if (resp[0] === "#" || resp[0] === "&") {
CURR_URL = BASE_URL + "spoj/" + resp[1];
const response = await fetch(CURR_URL);
var count_t = await response.json();
if (count_t.status !== "Failed") {
spoj_count = count_t.solved.length;
if (resp[0] === "#") {
msg.reply(
resp[1] +
" successfully submitted " +
spoj_count +
" problems at spoj. "
);
}
} else {
if (resp[0] === "#")
msg.reply("OOPS! Invalid spoj handle, type . command to know more.");
}
}
// --------------------------------------------- interviewbit-count ----------------------------------- //
if (resp[0] === "*" || resp[0] === "&") {
CURR_URL = BASE_URL + "interviewbit/" + resp[1];
const response = await fetch(CURR_URL);
var count_t = await response.json();
if (count_t.status !== "Failed") {
bit_count = count_t.score;
if (resp[0] === "*") {
msg.reply(
resp[1] +
" successfully submitted " +
bit_count +
" problems at interviewbit."
);
}
} else {
if (resp[0] === "*")
msg.reply(
"OOPS! Invalid interviewbit handle, type . command to know more."
);
}
}
// --------------------------------------------- codeforces-count ------------------------------------------- //
if (resp[0] === "!" || resp[0] === "&") {
CURR_URL =
"https://codeforces.com/api/user.status?handle=" +
resp[1] +
"&from=1&count=1000";
const response = await fetch(CURR_URL);
var count_t = await response.json();
if (count_t.status !== "Failed") {
for (var i = 0; i < count_t.result.length; i++) {
if (count_t.result[i].verdict === "OK") {
force_count += 1;
}
}
if (resp[0] === "!") {
msg.reply(
resp[1] +
" successfully submitted " +
force_count +
" problems at codeforces."
);
}
} else {
if (resp[0] === "!")
msg.reply(
"OOPS! Invalid codeforces handle, type . command to know more."
);
}
}
// --------------------------------------------- overall-count ------------------------------------------- //
if (resp[0] === "&") {
count = chef_count + spoj_count + force_count + bit_count;
msg.reply(
resp[1] + " successfully submitted overall " + count + " problems."
);
}
// --------------------------------------------- command ------------------------------------------------ //
var cmd_msg = "";
if (resp[0] === "." && resp[1] == "command") {
cmd_msg +=
"\nHi there! am here to help you out, follow the commands to get score.\n\n";
cmd_msg += "For Codechef: @ <codechef_handle_name>\n";
cmd_msg += "For Codeforces: ! <codeforces_handle_name>\n";
cmd_msg += "For Spoj: # <spoj_handle_name>\n";
cmd_msg += "For Interviewbit: * <interviewbit_handle_name>\n\n";
cmd_msg += "For Overall score: & <handle_name>\n\n";
msg.reply(cmd_msg);
}
});
client.login(process.env.TOKEN);