-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
60 lines (54 loc) · 2.33 KB
/
main.ts
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
///<reference lib="deno.unstable" />
import { MESSAGE_TEXT } from "./constants.ts";
import { createBot, Intents, startBot } from "./deps.ts";
import { Secret } from "./secret.ts";
import {
createResultMessage,
createStartMessage,
getReactedMessage,
getReactingUserIds,
getReactionEmojis,
} from "./utils.ts";
const bot = createBot({
token: Secret.DISCORD_TOKEN,
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent,
events: {
ready: (_bot, payload) => {
console.log(`${payload.user.username} is ready!`);
},
},
});
bot.events.messageCreate = (bot, message) => {
if (message.content === "!health") {
bot.helpers.sendMessage(message.channelId, { content: "good!" });
}
};
// 指定時刻に1on1への参加を可否を聞くCron
// UTCとの時差が9時間あるので、これで13時にcronが動く
Deno.cron("participate", "0 4 * * *", () => {
bot.helpers.sendMessage(Secret.MY_CHANNEL_ID, { content: MESSAGE_TEXT });
});
// 開始時刻前になったらマッチ結果をお知らせしてくれるCron
// 21時に流す
// UTCとの時差が9時間あるので、これで21時にcronが動く
Deno.cron("result", "0 12 * * *", async () => {
const messages = await bot.helpers.getMessages(Secret.MY_CHANNEL_ID);
const reactedMessage = getReactedMessage({ messages });
const reactedEmojis = getReactionEmojis(reactedMessage);
const reactingUserIds = await getReactingUserIds({ bot, messageId: reactedMessage?.id, emojis: reactedEmojis });
const resultMessage = createResultMessage(reactingUserIds);
bot.helpers.sendMessage(Secret.MY_CHANNEL_ID, { content: resultMessage });
});
// 開催時刻に流れる
// 21時30分に流す
// UTCとの時差が9時間あるので、これで21時30分にcronが動く
Deno.cron("open", "30 12 * * *", async () => {
const messages = await bot.helpers.getMessages(Secret.MY_CHANNEL_ID);
const reactedMessage = getReactedMessage({ messages });
const reactedEmojis = getReactionEmojis(reactedMessage);
const reactingUserIds = await getReactingUserIds({ bot, messageId: reactedMessage?.id, emojis: reactedEmojis });
if (reactingUserIds.length === 0 || reactingUserIds.length === 1) return;
const startMessage = createStartMessage(reactingUserIds);
bot.helpers.sendMessage(Secret.MY_CHANNEL_ID, { content: startMessage });
});
await startBot(bot);