-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
labs.ts
147 lines (135 loc) · 3.78 KB
/
labs.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
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
144
145
146
147
import * as app from "#app"
import lab from "#tables/lab.ts"
import guild from "#tables/guild.ts"
export default new app.Command({
name: "labs",
aliases: ["lab", "affiliations", "affiliation"],
description: "Get a lab invite link",
channelType: "guild",
positional: [
{
name: "name",
description: "A part of lab name",
type: "string",
},
],
async run(message) {
if (!message.args.name) return app.sendCommandDetails(message, this as any)
const labs = await lab.query.select("guild_id", "title", "url")
const guilds = await guild.query.select("id", "_id").where(
"_id",
"in",
labs.map((lab) => lab.guild_id),
)
const result = guilds.filter((guild) =>
message.client.guilds.cache
.get(guild.id)
?.name.toLowerCase()
.includes(message.args.name.toLowerCase()),
)
if (!result)
return message.channel.send(`${app.emote(message, "Cross")} No lab found`)
const labResult = labs.find((lab) => lab.guild_id === result[0]._id)
if (!labResult)
return message.channel.send(`${app.emote(message, "Cross")} No lab found`)
return message.channel.send(`${labResult.title} ${labResult.url}`)
},
subs: [
new app.Command({
name: "add",
aliases: ["set"],
description: "Add a lab",
channelType: "guild",
botOwnerOnly: true,
positional: [
{
name: "url",
description: "Lab invite url",
type: "string",
required: true,
},
],
options: [
{
name: "id",
description: "The guild id",
type: "string",
},
],
rest: {
name: "title",
description: "The displayed text",
required: true,
},
async run(message) {
const guild = message.args.id
? await app.getGuild({ id: message.args.id })
: await app.getGuild(message.guild, { forceExists: true })
if (!guild)
return message.channel.send(
`${app.emote(message, "Cross")} Incorrect guild id`,
)
await lab.query
.insert({
guild_id: guild._id,
url: message.args.url,
title: message.args.title,
})
.onConflict("guild_id")
.merge(["url", "title"])
return message.channel.send(
`${app.emote(message, "CheckMark")} Successfully added **${
message.args.id
? message.client.guilds.cache.get(message.args.id)?.name
: message.guild.name
}**`,
)
},
}),
new app.Command({
name: "update",
aliases: ["refresh"],
description: "Update all affiliations",
channelType: "guild",
botOwnerOnly: true,
cooldown: {
duration: 10000,
type: app.CooldownType.Global,
},
positional: [
app.positional({
name: "packSize",
description: "How many labs to send per message",
type: "number",
validate: (value) => value > 0 && value <= 12,
default: 10,
}),
],
async run(message) {
await app.updateLabsInAffiliationChannels(
message,
message.args.packSize,
)
message.triggerCooldown()
},
}),
new app.Command({
name: "list",
aliases: ["all"],
description: "List all labs",
channelType: "guild",
positional: [
{
name: "packSize",
description: "How many labs to send per message",
type: "number",
validate: (value: number) => value > 0 && value <= 12,
default: "10",
},
],
async run(message) {
await app.sendLabList(message.channel, message.args.packSize)
},
}),
],
})