Skip to content

Commit c454cf5

Browse files
committed
Make admin commands available in discord
1 parent fa9ee23 commit c454cf5

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

src/commands/admin/emojidump.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default class TestGuideCommand extends Command {
2525
}
2626

2727
async run(source: CommandSource): Promise<SendMessage | undefined> {
28-
2928
const entries = source.guild?.emojis.cache.entries()
3029
if (!entries)
3130
return undefined

src/commands/admin/thread.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { CommandInteraction, Message } from "discord.js"
1+
import { CommandInteraction, Message, Snowflake } from "discord.js"
22
import log4js from "log4js"
33
import config from "../../data/config.json"
44
import Command from "../../utils/Command"
5-
import { SendMessage } from "../../utils/Types"
5+
import { CommandSource, SendMessage } from "../../utils/Types"
66
import { sendMessage } from "../../utils/Utils"
77

88

@@ -16,18 +16,24 @@ export default class ThreadCommand extends Command {
1616
help: "Create a new thread, can only be used in own Discord. Bot developer only.",
1717
usage: "thread <name>",
1818
aliases: [],
19-
options: []
19+
options: [{
20+
name: "name",
21+
description: "Name of thread",
22+
type: "STRING",
23+
required: true
24+
}]
2025
})
2126
}
2227

2328
async runInteraction(source: CommandInteraction): Promise<SendMessage | undefined> {
24-
return sendMessage(source, "Slash command not supported")
29+
return this.run(source, source.user.id, source.options.getString("name", true))
2530
}
2631

2732
async runMessage(source: Message, args: string[]): Promise<SendMessage | undefined> {
28-
const id = source.author.id
29-
let name = args.join(" ")
33+
return this.run(source, source.author.id, args.join(" "))
34+
}
3035

36+
async run(source: CommandSource, id: Snowflake, name: string): Promise<SendMessage | undefined> {
3137
if (!config.admins.includes(id))
3238
return sendMessage(source, "This command is only for the bot developer", undefined, true)
3339

@@ -42,11 +48,15 @@ export default class ThreadCommand extends Command {
4248
name = `[${type}] ${name}`
4349

4450
Logger.info(`Creating thread ${name} for ${id} in ${channel.id} (${channel.guild.name})`)
45-
await source.startThread({
51+
const msg = await channel.send({ content: `<@${id}>: ${name}` })
52+
await msg.startThread({
4653
name,
4754
autoArchiveDuration: "MAX"
4855
})
49-
if (source.pinnable)
50-
await source.pin()
56+
57+
if (msg.pinnable)
58+
await msg.pin()
59+
60+
return sendMessage(source, "Done!", undefined, true)
5161
}
5262
}

src/events/ready.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import client from "../main"
22
import log4js from "log4js"
33
import { ApplicationCommandData } from "discord.js"
44
import config from "../data/config.json"
5+
import Command from "../utils/Command"
56

67
const Logger = log4js.getLogger("ready")
78

@@ -17,31 +18,30 @@ export async function handle(): Promise<void> {
1718
client.newsManager.fetchNews().catch(e => Logger.error(e))
1819

1920
if (!client.application?.owner) await client.application?.fetch()
20-
const cmds: ApplicationCommandData[] = client.commands
21-
.array()
22-
.filter(cmd => cmd.category !== "Admin")
23-
.map(cmd => {
24-
const help = (cmd.shortHelp ?? cmd.help).split("\n")[0]
25-
const name = cmd.commandName
26-
27-
if (help.length > 99)
28-
Logger.error(`${name}'s description is too long'`)
29-
30-
return {
31-
name,
32-
options: cmd.options,
33-
description: help.substring(0, 100),
34-
// TODO default permissions?
35-
}
36-
})
21+
const cmds = client.commands.array()
3722

3823
try {
39-
if (config.production)
40-
await client.application?.commands.set(cmds)
41-
else
42-
await client.guilds.cache.get("247122362942619649")?.commands.set(cmds)
24+
if (config.production) {
25+
await client.application?.commands.set(cmds.filter(cmd => cmd.category !== "Admin").map(mapCommand))
26+
await client.guilds.cache.get("616569685370077192")?.commands.set(cmds.filter(cmd => cmd.category === "Admin").map(mapCommand))
27+
} else
28+
await client.guilds.cache.get("247122362942619649")?.commands.set(cmds.map(mapCommand))
4329
Logger.info(`Commands registered for ${config.production}`)
4430
} catch (error) {
4531
Logger.error("Unnable to register commands")
4632
}
4733
}
34+
35+
function mapCommand(cmd: Command): ApplicationCommandData {
36+
const help = (cmd.shortHelp ?? cmd.help).split("\n")[0]
37+
const name = cmd.commandName
38+
39+
if (help.length > 99)
40+
Logger.error(`${name}'s description is too long'`)
41+
42+
return {
43+
name,
44+
options: cmd.options,
45+
description: help.substring(0, 100),
46+
}
47+
}

0 commit comments

Comments
 (0)