From 3202183d8e7df96cf9a66ba441db8f1533a37cea Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sat, 8 Mar 2025 18:22:32 +0900 Subject: [PATCH] chore: Add type Context --- src/commands/dataLength.ts | 5 ++--- src/commands/deleteLearnedData.ts | 6 ++---- src/commands/learn.ts | 6 ++---- src/lib/context.ts | 3 +++ 4 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 src/lib/context.ts diff --git a/src/commands/dataLength.ts b/src/commands/dataLength.ts index ef7b5e5..08f0546 100644 --- a/src/commands/dataLength.ts +++ b/src/commands/dataLength.ts @@ -1,3 +1,4 @@ +import type { Context } from '../lib/context' import { Learn, Text } from '../lib/databases' import { ApplyOptions } from '@sapphire/decorators' import { Command } from '@sapphire/framework' @@ -33,9 +34,7 @@ export default class DataLengthCommand extends Command { return await this._run(interaction) } - private async _run( - ctx: Message | ChatInputCommandInteraction<'cached'>, - ) { + private async _run(ctx: Context) { let userId: string let username: string diff --git a/src/commands/deleteLearnedData.ts b/src/commands/deleteLearnedData.ts index 4dc3c87..633fca3 100644 --- a/src/commands/deleteLearnedData.ts +++ b/src/commands/deleteLearnedData.ts @@ -1,3 +1,4 @@ +import type { Context } from '../lib/context' import { MuffinCustomId } from '../lib/customId' import { Learn } from '../lib/databases' import { ApplyOptions } from '@sapphire/decorators' @@ -49,10 +50,7 @@ export default class DeleteLearnedData extends Command { return await this._run(interaction) } - private async _run( - ctx: Message | ChatInputCommandInteraction<'cached'>, - args?: Args, - ) { + private async _run(ctx: Context, args?: Args) { let command: string | undefined let userId: string diff --git a/src/commands/learn.ts b/src/commands/learn.ts index d50362c..f5c38db 100644 --- a/src/commands/learn.ts +++ b/src/commands/learn.ts @@ -1,3 +1,4 @@ +import type { Context } from '../lib/context' import { Learn } from '../lib/databases' import { ApplyOptions } from '@sapphire/decorators' import { Args, Command } from '@sapphire/framework' @@ -53,10 +54,7 @@ export default class LearnCommand extends Command { return await this._run(interaction) } - private async _run( - ctx: Message | ChatInputCommandInteraction<'cached'>, - args?: Args, - ) { + private async _run(ctx: Context, args?: Args) { const userId = ctx instanceof Message ? ctx.author.id : ctx.user.id let command: string | undefined let result: string | undefined diff --git a/src/lib/context.ts b/src/lib/context.ts new file mode 100644 index 0000000..3b27168 --- /dev/null +++ b/src/lib/context.ts @@ -0,0 +1,3 @@ +import type { ChatInputCommandInteraction, Message } from 'discord.js' + +export type Context = Message | ChatInputCommandInteraction<'cached'>