-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
91 lines (79 loc) · 2.96 KB
/
mod.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
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
import { createBot, Intents, startBot, sendMessage, editMessage, Message, addReaction, editBotStatus, ActivityTypes } from "https://deno.land/x/[email protected]/mod.ts"
import * as Brigadier from "npm:brigadier-ts"
import env from "./env.json" assert { type: "json" }
const sleep = (time: number) => new Promise((r) => setTimeout(r, time))
let threads: bigint[] = []
const dispatcher: Brigadier.CommandDispatcher<Message> = new Brigadier.CommandDispatcher()
const bot = createBot({
token: env.token,
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent,
events: {
ready() {
console.log("Successfully connected to gateway")
editBotStatus(bot, {
activities: [
{
createdAt: 0,
type: ActivityTypes.Game,
name: "m'uix"
}
],
status: "online"
})
},
async threadCreate(_, thread) {
if (threads.indexOf(thread.id) != -1) return
if (thread.guildId != BigInt("1101964863871406182")) return
threads.push(thread.id)
let message = await sendMessage(bot, thread.id, {
content: "Adding people to the thread..."
})
await sleep(500)
editMessage(bot, thread.id, message.id, {
content: "<@&1102016351813509261>, welcome!"
})
},
messageCreate(_, message) {
if (message.isFromBot || message.webhookId) return
if (!message.content.startsWith("#!")) return
try {
dispatcher.execute(message.content.substring(2), message)
} catch (err: any) {
sendMessage(bot, message.channelId, {
content: err.toString()
})
}
}
},
})
let pollEmotes = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣","8️⃣","9️⃣","🔟"]
async function poll(name: string, options: string[], channelId: bigint) {
if (options.length > 10) {
sendMessage(bot, channelId, {
content: "Poll cannot exceed 10 options."
})
return
}
let content = `@everyone: **Poll time!**\n> **${name}**\n`
let i = 0
for (let opt of options) {
content += `${pollEmotes[i]} ${opt.trim()}\n`
i++
}
const message = sendMessage(bot, channelId, { content })
i = 0
for (let _ in options) {
await sleep(100)
await addReaction(bot, channelId, (await message).id, pollEmotes[i])
i++
}
}
dispatcher.register(Brigadier.literal("poll").then(
Brigadier.argument("name", Brigadier.string()).then(
Brigadier.argument("options", Brigadier.greedyString()).executes((c) => {
poll(c.get("name"), c.get("options").split(","), c.getSource().channelId)
return 1
})
)
))
await startBot(bot)