generated from didinele/typescript-docker-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
7 changed files
with
71 additions
and
20 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
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
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,3 @@ | ||
# command-framework/handlers | ||
|
||
This folder contains some useful bot-agnostic handlers that we can use in any bot in the monorepo. |
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,45 @@ | ||
import { API, InteractionContextType, type APIInteraction } from '@discordjs/core'; | ||
import { injectable } from 'inversify'; | ||
import type { Env } from '../../util/Env.js'; | ||
import type { ApplicationCommandHandler, HandlerModule, ICommandHandler } from '../ICommandHandler.js'; | ||
|
||
@injectable() | ||
export default class DevHandler implements HandlerModule { | ||
public constructor( | ||
private readonly api: API, | ||
private readonly handler: ICommandHandler, | ||
private readonly env: Env, | ||
) {} | ||
|
||
public register() { | ||
this.handler.register({ | ||
interactions: [ | ||
{ | ||
name: 'deploy', | ||
description: 'Deploy commands', | ||
options: [], | ||
contexts: [InteractionContextType.BotDM], | ||
}, | ||
], | ||
applicationCommands: [['deploy:none:none', this.handleDeploy]], | ||
}); | ||
} | ||
|
||
private readonly handleDeploy: ApplicationCommandHandler = async (interaction: APIInteraction) => { | ||
if (!interaction.user) { | ||
throw new Error('Command /deploy was ran in non-dm.'); | ||
} | ||
|
||
if (!this.env.admins.has(interaction.user.id)) { | ||
await this.api.interactions.reply(interaction.id, interaction.token, { | ||
content: 'You are not authorized to use this command', | ||
}); | ||
|
||
return; | ||
} | ||
|
||
await this.handler.deployCommands(); | ||
|
||
await this.api.interactions.reply(interaction.id, interaction.token, { content: 'Successfully deployed commands' }); | ||
}; | ||
} |
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