Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(#22): update discordx to 11.1.8 #26

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"discord-api-types": "^0.36.2",
"discord-oauth2": "^2.10.0",
"discord.js": "^14.0.3",
"discordx": "^10.0.0",
"discordx": "^11.1.8",
"dotenv": "^16.0.1",
"fast-folder-size": "^1.7.0",
"fs": "^0.0.1-security",
Expand Down
7 changes: 4 additions & 3 deletions src/commands/Admin/prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export default class PrefixCommand {
private db: Database,
) {}

@Slash('prefix', { description:
'Here goes the command description!'
@Slash({
name: 'prefix',
description: 'Here goes the command description!'
})
@Guard(
UserPermissions(['Administrator'])
)
async prefix(
@SlashOption('prefix', { required: false, type: ApplicationCommandOptionType.String }) prefix: string | undefined,
@SlashOption({ name: 'prefix', type: ApplicationCommandOptionType.String, required: false }) prefix: string | undefined,
interaction: CommandInteraction,
{ localize }: InteractionData
) {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/General/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export default class HelpCommand {
this.loadCategories()
}

@Slash('help', { description:
'Get global help about the bot and its commands'
@Slash({
name: 'help',
description: 'Get global help about the bot and its commands'
})
help(interaction: CommandInteraction, client: Client, { sanitizedLocale }: InteractionData): void {

Expand All @@ -32,7 +33,9 @@ export default class HelpCommand {
})
}

@SelectMenuComponent('help-category-selector')
@SelectMenuComponent({
id: 'help-category-selector'
})
async selectCategory(interaction: SelectMenuInteraction, client: Client, { sanitizedLocale }: InteractionData) {

const category = interaction.values[0]
Expand Down
5 changes: 3 additions & 2 deletions src/commands/General/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { generalConfig } from "@config"
@Category('General')
export default class InviteCommand {

@Slash('invite', { description:
'A simple invite command!'
@Slash({
name: 'invite',
description: 'A simple invite command!'
})
@Guard()
invite(interaction: CommandInteraction, { localize }: InteractionData): void {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/General/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { Slash, Discord } from "@decorators"
@Category('General')
export default class PingCommand {

@Slash('ping', { description:
'Pong!'
@Slash({
name: 'ping',
description: 'Pong!'
})
async ping(
interaction: CommandInteraction,
Expand Down
7 changes: 4 additions & 3 deletions src/commands/General/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ export default class StatsCommand {
private stats: Stats
) {}

@Slash('stats', { description:
'Here goes the command description!'
@Slash({
name: 'stats',
description: 'Here goes the command description!'
})
async statsHandler(
@SlashOption('days') days: number,
@SlashOption({ name: 'days' }) days: number,
interaction: CommandInteraction,
{ localize }: InteractionData
) {
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Owner/maintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import { CommandInteraction } from "discord.js"
@Discord()
export default class MaintenanceCommand {

@Slash("maintenance", { description:
'Set the bot in maintenance mode.'
@Slash({
name: 'maintenance',
description: 'Set the bot in maintenance mode.'
})
@Guard(
Disabled
)
async maintenance(
@SlashOption('state') state: boolean,
@SlashOption({ name: 'state' }) state: boolean,
interaction: CommandInteraction,
{ localize }: InteractionData
) {

await setMaintenance(state)

const locale = getLocaleFromInteraction(interaction)
simpleSuccessEmbed(
interaction,
localize['COMMANDS']['MAINTENANCE']['SUCCESS']({
Expand Down
6 changes: 4 additions & 2 deletions src/commands/Owner/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { Disabled, Guard } from "@guards"
@Discord()
export default class TestsCommand {

@Slash('test')
@Slash({
name: 'test'
})
@Guard(
Disabled
)
Expand All @@ -15,7 +17,7 @@ export default class TestsCommand {
console.log('test invoked')
}

@ContextMenu(ApplicationCommandType.User, 'help')
@ContextMenu({ type: ApplicationCommandType.User, name: 'help'})
async contextMenu(interaction: CommandInteraction) {

console.log('contextMenu invoked')
Expand Down
1 change: 0 additions & 1 deletion src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Maintenance } from '@guards'
import { Guild, User } from '@entities'
import { On, Guard, Discord } from '@decorators'
import { syncUser } from '@utils/functions'
import { getLocaleFromInteraction, L } from '@i18n'

@Discord()
@injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'reflect-metadata'
import 'dotenv/config'

import { container } from 'tsyringe'
import { DIService, Client } from 'discordx'
import { DIService, Client, tsyringeDependencyRegistryEngine } from 'discordx'
import { importx } from '@discordx/importer'

import { Database, ImagesUpload, ErrorHandler, Logger, WebSocket } from '@services'
Expand All @@ -25,7 +25,7 @@ async function run() {
await db.initialize()

// init the client
DIService.container = container
DIService.engine = tsyringeDependencyRegistryEngine.setInjector(container)
const client = new Client(clientConfig)
container.registerInstance(Client, client)

Expand Down
5 changes: 3 additions & 2 deletions src/utils/decorators/On.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiscordEvents, EventOptions, MethodDecoratorEx, DOn, MetadataStorage } from 'discordx'
import { EventOptions, MethodDecoratorEx, DOn, MetadataStorage } from 'discordx'

/**
* Handle both discord and custom events with a defined handler
Expand All @@ -21,8 +21,9 @@ export const On = (event: string, options?: EventOptions): MethodDecoratorEx =>
const clazz = target as unknown as new () => unknown
const on = DOn.create({
botIds: options?.botIds,
event: event as DiscordEvents,
event: event,
once: false,
rest: false
}).decorate(clazz.constructor, key, descriptor?.value)

MetadataStorage.instance.addOn(on)
Expand Down
31 changes: 31 additions & 0 deletions src/utils/decorators/Once.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EventOptions, MethodDecoratorEx, DOn, MetadataStorage } from 'discordx'

/**
* Handle both discord and custom events only **once** with a defined handler
* @param event - event name
* @param options - event parameters
* ___
*
* [View Documentation](https://discord-ts.js.org/docs/decorators/general/on)
*
* @category Decorator
*/
export const Once = (event: string, options?: EventOptions): MethodDecoratorEx => {

return function <T>(
target: Record<string, T>,
key: string,
descriptor?: PropertyDescriptor
) {

const clazz = target as unknown as new () => unknown
const on = DOn.create({
botIds: options?.botIds,
event: event,
once: true,
rest: false
}).decorate(clazz.constructor, key, descriptor?.value)

MetadataStorage.instance.addOn(on)
}
}
14 changes: 5 additions & 9 deletions src/utils/decorators/Slash.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Locale } from 'discord-api-types/v9'
import { IGuild, Slash as SlashX, VerifyName } from 'discordx'
import { ApplicationCommandOptions as DXApplicationCommandOptions, IGuild, Slash as SlashX, VerifyName } from 'discordx'

enum AdditionnalLocaleString {
English = 'en'
}

type LocalizationMap = Partial<Record<`${Locale | AdditionnalLocaleString}`, string>>

type ApplicationCommandOptions = {
botIds?: string[]
defaultPermission?: boolean
description?: string
type ApplicationCommandOptions = Modify<DXApplicationCommandOptions, {
descriptionLocalizations?: LocalizationMap
guilds?: IGuild[]
nameLocalizations?: LocalizationMap
}
}>

/**
* Handle a slash command with a defined nam
Expand All @@ -26,7 +22,7 @@ type ApplicationCommandOptions = {
*
* @category Decorator
*/
export const Slash = <T extends string>(name?: VerifyName<T>, options?: ApplicationCommandOptions) => {
export const Slash = (options: ApplicationCommandOptions) => {

// convert 'en' localizations to 'en-US' and 'en-GB'
if (options?.nameLocalizations?.['en']) {
Expand All @@ -40,5 +36,5 @@ export const Slash = <T extends string>(name?: VerifyName<T>, options?: Applicat
delete options.descriptionLocalizations['en']
}

return SlashX(name, options)
return SlashX(options)
}
2 changes: 1 addition & 1 deletion src/utils/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export {
Guard,
Guild,
ModalComponent,
Once,
SelectMenuComponent,
SimpleCommand,
SimpleCommandOption,
Expand All @@ -16,6 +15,7 @@ export {
} from 'discordx'

export * from './On'
export * from './Once'
export * from './Slash'
export * from './Schedule'
export * from './WSOn'
1 change: 1 addition & 0 deletions src/utils/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Modify<T, R> = Omit<T, keyof R> & R