-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6255783
commit 034739c
Showing
9 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
APIChatInputApplicationCommandInteraction, | ||
APIInteraction, | ||
InteractionType, | ||
} from "@discordjs/core"; | ||
|
||
interface Unko extends APIChatInputApplicationCommandInteraction { | ||
guild_id: string; | ||
} | ||
|
||
export function validate(i: APIInteraction): i is Unko { | ||
return !!(i.type === InteractionType.ApplicationCommand && i.guild_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
API, | ||
APIInteraction, | ||
RESTPostAPIChatInputApplicationCommandsJSONBody, | ||
} from "@discordjs/core"; | ||
import Ping from "./ping.js"; | ||
|
||
export const commands: ICommand[] = [new Ping()]; | ||
|
||
export interface ICommand { | ||
defition(): RESTPostAPIChatInputApplicationCommandsJSONBody; | ||
run(api: API, i: APIInteraction): Promise<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { API } from "@discordjs/core"; | ||
import { commands } from "./index.js"; | ||
|
||
export async function initCommands(api: API) { | ||
api.applicationCommands.bulkOverwriteGlobalCommands( | ||
(await api.applications.getCurrent()).id, | ||
commands.map((x) => x.defition()), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { SlashCommandBuilder } from "@discordjs/builders"; | ||
import { | ||
API, | ||
APIInteraction, | ||
MessageFlags, | ||
RESTPostAPIChatInputApplicationCommandsJSONBody, | ||
} from "@discordjs/core"; | ||
import { type ICommand } from "./index.js"; | ||
|
||
export default class Ping implements ICommand { | ||
defition(): RESTPostAPIChatInputApplicationCommandsJSONBody { | ||
return new SlashCommandBuilder() | ||
.setName("ping") | ||
.setDescription("Ping Pong") | ||
.toJSON(); | ||
} | ||
|
||
async run(api: API, i: APIInteraction): Promise<unknown> { | ||
return await api.interactions.editReply(i.application_id, i.token, { | ||
content: "Pong!", | ||
flags: MessageFlags.Ephemeral, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
GatewayInteractionCreateDispatchData, | ||
MessageFlags, | ||
WithIntrinsicProps, | ||
} from "@discordjs/core"; | ||
import { validate } from "../commands/helper.js"; | ||
import { commands } from "../commands/index.js"; | ||
|
||
export default async ({ | ||
api, | ||
data, | ||
}: WithIntrinsicProps<GatewayInteractionCreateDispatchData>) => { | ||
console.log(0); | ||
await api.interactions.defer(data.id, data.token); | ||
|
||
if (!validate(data)) return false; | ||
|
||
const command = commands.find((x) => x.defition().name === data.data.name); | ||
|
||
if (!command) | ||
return await api.interactions.followUp(data.application_id, data.token, { | ||
content: "古いコマンドを参照しています.世界を削除します.", | ||
flags: MessageFlags.Ephemeral, | ||
}); | ||
|
||
try { | ||
await command.run(api, data); | ||
} catch (e) { | ||
await api.interactions.followUp(data.application_id, data.token, { | ||
content: `エラーです. \`\`\`${ | ||
e instanceof Error ? e.message : String(e) | ||
}\`\`\``, | ||
flags: MessageFlags.Ephemeral, | ||
}); | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { GatewayReadyDispatchData, WithIntrinsicProps } from "@discordjs/core"; | ||
import { initCommands } from "../commands/init.js"; | ||
|
||
export default async ({ | ||
api, | ||
}: WithIntrinsicProps<GatewayReadyDispatchData>) => { | ||
await initCommands(api); | ||
|
||
console.log("ready!"); | ||
|
||
return true; | ||
}; |