-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
active.ts
94 lines (85 loc) · 2.51 KB
/
active.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
import * as app from "#app"
import guildTable from "#tables/guild.ts"
let used = false
export default new app.Command({
name: "active",
description: "Update the active list",
channelType: "guild",
middlewares: [
app.staffOnly,
app.hasConfigKey("active_role_id"),
app.isNotInUse(() => used),
],
flags: [
{
flag: "f",
name: "force",
description: "Force the update of all members",
},
],
options: [
app.option({
name: "period",
description: "The period to check (in hours)",
type: "number",
validate: (value) => value > 0,
validationErrorMessage: "The period must be greater than 0.",
}),
app.option({
name: "messageCount",
aliases: ["count"],
description: "The minimum message count",
type: "number",
validate: (value) => value > 0,
validationErrorMessage: "The period must be greater than 0.",
}),
],
async run(message) {
used = true
const config = await app.getGuild(message.guild, {
forceExists: true,
forceFetch: true,
})
const waiting = await message.channel.send(
`${app.emote(message, "Loading")} Fetching members...`,
)
if (message.args.period || message.args.messageCount) {
await guildTable.query.where("id", message.guild.id).update({
active_period: `${message.args.period ?? config.active_period}`,
active_message_count: `${message.args.messageCount ?? config.active_message_count}`,
})
}
await app.updateActive(message.guild, {
force: message.args.force,
period: message.args.period ?? +config.active_period,
messageCount: message.args.messageCount ?? +config.active_message_count,
onLog: (text) => waiting.edit(text),
guildConfig: config,
})
used = false
},
subs: [
new app.Command({
name: "leaderboard",
description: `Show the leaderboard of Activity`,
channelType: "guild",
aliases: ["ladder", "lb", "top", "rank"],
options: [
app.option({
name: "lines",
description: "Number of lines to show per page",
type: "number",
default: 15,
aliases: ["line", "count"],
validate: (value) => value > 0 && value <= 50,
}),
],
run: async (message) => {
const guild = await app.getGuild(message.guild, { forceExists: true })
app.activeLadder(guild._id).send(message.channel, {
pageLineCount: message.args.lines,
})
},
}),
],
})