Skip to content

Commit

Permalink
add discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Feb 4, 2024
1 parent e9f35f7 commit 14ae923
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion file/User.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"USERID_SET": ["223796"]
"USERID_SET": ["223796", "223798", "151204"]
}
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "discord.js";
import { Client, TextChannel } from "discord.js";
import { IntentOptions } from "./config/IntentOptions";
import * as dotenv from "dotenv";
import { Query } from "./query";
Expand All @@ -13,9 +13,13 @@ dotenv.config();
(async () => {
const BOT = new Client({intents: IntentOptions});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let channel : TextChannel | undefined;

await BOT.login(process.env.BOT_TOKEN);
BOT.on("ready", () => {
console.log("Bot is ready!");
channel = BOT.channels.cache.get(process.env.BOT_CHANNEL_ID!) as TextChannel;
});

const query : Query = await Query.init();
Expand All @@ -26,16 +30,19 @@ dotenv.config();
for (const user of userQueue) {
const newProblemSets = await getAcceptSet(user.Id);
if (!user.equalSets(newProblemSets)) {
console.log("User " + user.Name + " has new accepted problems!");
channel?.send(`User ${user.Name} has new accepted problems!`);
const diff = user.diffSets(newProblemSets);
for (const problem of diff) {
console.log("New problem: " + query.getProblem(problem)!.title);
const newProblem = query.getProblem(problem);
channel?.send(
`New problem: ${newProblem!.title}\n` +
`Tags: ${newProblem!.tags}\n` +
`URL: ${process.env.CSES_URL}${newProblem!.url}`
);
}
user.updateAccept(diff);
}
}
await new Promise(resolve => setTimeout(resolve, 1000 * 5));
}


})();

0 comments on commit 14ae923

Please sign in to comment.