From 663f5aa1386d79285e754d4a8f7c600a787c8c41 Mon Sep 17 00:00:00 2001 From: claustra01 Date: Sun, 17 Dec 2023 14:08:52 +0900 Subject: [PATCH 1/2] [add] command type enum --- src/usecase/types/commands.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/usecase/types/commands.ts b/src/usecase/types/commands.ts index af78911..4df207b 100644 --- a/src/usecase/types/commands.ts +++ b/src/usecase/types/commands.ts @@ -5,10 +5,14 @@ export interface Command { export const enum CommandList { ping = 'ping', + help = 'help', rate = 'rate', ranking = 'ranking', register = 'register', link = 'link', + result = 'result', + rollback = 'rollback', + recalculate = 'recalculate', } export const commands: Record = { @@ -16,6 +20,10 @@ export const commands: Record = { name: 'ping', requirePermission: false, }, + help: { + name: 'help', + requirePermission: false, + }, rate: { name: 'rate', requirePermission: false, @@ -32,4 +40,16 @@ export const commands: Record = { name: 'link', requirePermission: true, }, + result: { + name: 'result', + requirePermission: true, + }, + rollback: { + name: 'rollback', + requirePermission: true, + }, + recalculate: { + name: 'recalculate', + requirePermission: true, + }, }; From 7358c3890644372c8f120e3191d668db95651c3f Mon Sep 17 00:00:00 2001 From: claustra01 Date: Sun, 17 Dec 2023 14:09:08 +0900 Subject: [PATCH 2/2] [add] not implemented command template --- src/adapter/commands/help.ts | 8 ++++++ src/adapter/commands/recalculate.ts | 8 ++++++ src/adapter/commands/result.ts | 9 +++++++ src/adapter/commands/rollback.ts | 9 +++++++ src/infrastructure/discord.ts | 42 +++++++++++++++++++++++++++-- 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/adapter/commands/help.ts create mode 100644 src/adapter/commands/recalculate.ts create mode 100644 src/adapter/commands/result.ts create mode 100644 src/adapter/commands/rollback.ts diff --git a/src/adapter/commands/help.ts b/src/adapter/commands/help.ts new file mode 100644 index 0000000..d02728a --- /dev/null +++ b/src/adapter/commands/help.ts @@ -0,0 +1,8 @@ +import { Reply, ReplyType } from '../../usecase/types/reply'; + +export const commandHelp = (): Reply => { + return { + type: ReplyType.Error, + errorText: 'Error: Not Implemented', + }; +}; diff --git a/src/adapter/commands/recalculate.ts b/src/adapter/commands/recalculate.ts new file mode 100644 index 0000000..7b6c331 --- /dev/null +++ b/src/adapter/commands/recalculate.ts @@ -0,0 +1,8 @@ +import { Reply, ReplyType } from '../../usecase/types/reply'; + +export const commandRecalculate = (): Reply => { + return { + type: ReplyType.Error, + errorText: 'Error: Not Implemented', + }; +}; diff --git a/src/adapter/commands/result.ts b/src/adapter/commands/result.ts new file mode 100644 index 0000000..d5ff679 --- /dev/null +++ b/src/adapter/commands/result.ts @@ -0,0 +1,9 @@ +import { Reply, ReplyType } from '../../usecase/types/reply'; + +export const commandResult = (args: string[]): Reply => { + console.log(args); + return { + type: ReplyType.Error, + errorText: 'Error: Not Implemented', + }; +}; diff --git a/src/adapter/commands/rollback.ts b/src/adapter/commands/rollback.ts new file mode 100644 index 0000000..0272341 --- /dev/null +++ b/src/adapter/commands/rollback.ts @@ -0,0 +1,9 @@ +import { Reply, ReplyType } from '../../usecase/types/reply'; + +export const commandRollback = (args: string[]): Reply => { + console.log(args); + return { + type: ReplyType.Error, + errorText: 'Error: Not Implemented', + }; +}; diff --git a/src/infrastructure/discord.ts b/src/infrastructure/discord.ts index 0c0deb4..b0d2cbf 100644 --- a/src/infrastructure/discord.ts +++ b/src/infrastructure/discord.ts @@ -1,9 +1,13 @@ import { Client, GatewayIntentBits, Message, Partials } from 'discord.js'; +import { commandHelp } from '../adapter/commands/help'; import { commandLink } from '../adapter/commands/link'; import { commandPing } from '../adapter/commands/ping'; import { commandRanking } from '../adapter/commands/ranking'; import { commandRate } from '../adapter/commands/rate'; +import { commandRecalculate } from '../adapter/commands/recalculate'; import { commandRegister } from '../adapter/commands/register'; +import { commandResult } from '../adapter/commands/result'; +import { commandRollback } from '../adapter/commands/rollback'; import { config } from '../config/config'; import { generateReply } from '../usecase/functions/generateReply'; import { commands } from '../usecase/types/commands'; @@ -80,6 +84,15 @@ export const runDiscordBot = () => { message.reply(replyText); break; } + // help + case commands.help.name: { + if (!checkPermission(message, line, commands.ping.requirePermission)) + break; + const reply = commandHelp(); + const replyText = generateReply(reply, line); + message.reply(replyText); + break; + } // rate case commands.rate.name: { if (!checkPermission(message, line, commands.ping.requirePermission)) @@ -118,8 +131,33 @@ export const runDiscordBot = () => { message.reply(replyText); break; } - // other commands... - + // result + case commands.result.name: { + if (!checkPermission(message, line, commands.link.requirePermission)) + break; + const reply = await commandResult(commandText); + const replyText = generateReply(reply, line); + message.reply(replyText); + break; + } + // rollback + case commands.rollback.name: { + if (!checkPermission(message, line, commands.link.requirePermission)) + break; + const reply = await commandRollback(commandText); + const replyText = generateReply(reply, line); + message.reply(replyText); + break; + } + // recalculate + case commands.recalculate.name: { + if (!checkPermission(message, line, commands.link.requirePermission)) + break; + const reply = await commandRecalculate(); + const replyText = generateReply(reply, line); + message.reply(replyText); + break; + } // invalid commands default: { const invalidCommandError: Reply = {