From bd2f1dfc069f7ca113406f8bd4ad0e6503e1bc51 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sun, 1 Jun 2025 13:23:05 +0900 Subject: [PATCH] feat: Add reload prompt command --- commands/dataLength.go | 4 ++-- commands/deleteLearnedData.go | 3 ++- commands/discommand.go | 16 +++++++++------- commands/help.go | 3 ++- commands/information.go | 3 ++- commands/learn.go | 3 ++- commands/learnedDataList.go | 3 ++- commands/reloadPrompt.go | 36 +++++++++++++++++++++++++++++++++++ main.go | 5 +++++ 9 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 commands/reloadPrompt.go diff --git a/commands/dataLength.go b/commands/dataLength.go index bdd6b93..41990f0 100644 --- a/commands/dataLength.go +++ b/commands/dataLength.go @@ -29,7 +29,6 @@ const ( userLearn ) -// var dataLengthCh chan chStruct = make(chan chStruct) var dataLengthWg sync.WaitGroup var DataLengthCommand *Command = &Command{ @@ -42,7 +41,8 @@ var DataLengthCommand *Command = &Command{ DetailedDescription: &DetailedDescription{ Usage: fmt.Sprintf("%s학습데이터량", configs.Config.Bot.Prefix), }, - Category: General, + Category: General, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { dataLengthRun(ctx.Msg.Session, ctx.Msg, ctx.Msg.Author.Username, ctx.Msg.Author.ID) }, diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index 7c2800e..ec55d32 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -29,7 +29,8 @@ var DeleteLearnedDataCommand *Command = &Command{ Usage: fmt.Sprintf("%s삭제 (삭제할 단어)", configs.Config.Bot.Prefix), Examples: []string{fmt.Sprintf("%s삭제 머핀", configs.Config.Bot.Prefix)}, }, - Category: Chatting, + Category: Chatting, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { command := strings.Join(*ctx.Args, " ") if command == "" { diff --git a/commands/discommand.go b/commands/discommand.go index ea9998a..107c6eb 100644 --- a/commands/discommand.go +++ b/commands/discommand.go @@ -24,11 +24,12 @@ type DetailedDescription struct { type Command struct { *discordgo.ApplicationCommand - Aliases []string - DetailedDescription *DetailedDescription - Category Category - MessageRun messageRun - ChatInputRun chatInputRun + Aliases []string + DetailedDescription *DetailedDescription + Category Category + RegisterApplicationCommand bool + MessageRun messageRun + ChatInputRun chatInputRun } type DiscommandStruct struct { @@ -70,8 +71,9 @@ type Modal struct { } const ( - Chatting Category = "채팅" - General Category = "일반" + Chatting Category = "채팅" + General Category = "일반" + DeveloperOnly Category = "개발자 전용" ) var ( diff --git a/commands/help.go b/commands/help.go index d6fbd26..c4c21df 100644 --- a/commands/help.go +++ b/commands/help.go @@ -28,7 +28,8 @@ var HelpCommand *Command = &Command{ Usage: fmt.Sprintf("%s도움말 [명령어]", configs.Config.Bot.Prefix), Examples: []string{fmt.Sprintf("%s도움말", configs.Config.Bot.Prefix), fmt.Sprintf("%s도움말 배워", configs.Config.Bot.Prefix)}, }, - Category: General, + Category: General, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { helpRun(ctx.Msg.Session, ctx.Msg, strings.Join(*ctx.Args, " ")) }, diff --git a/commands/information.go b/commands/information.go index 9788875..8a3251c 100644 --- a/commands/information.go +++ b/commands/information.go @@ -16,7 +16,8 @@ var InformationCommand *Command = &Command{ DetailedDescription: &DetailedDescription{ Usage: fmt.Sprintf("%s정보", configs.Config.Bot.Prefix), }, - Category: General, + Category: General, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { informationRun(ctx.Msg.Session, ctx.Msg) }, diff --git a/commands/learn.go b/commands/learn.go index 9b4e00c..81580b7 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -56,7 +56,8 @@ var LearnCommand *Command = &Command{ fmt.Sprintf("%s배워 \"나의 아이디를 알려줘\" \"너의 아이디는 {user.id}야.\"", configs.Config.Bot.Prefix), }, }, - Category: Chatting, + Category: Chatting, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { if len(*ctx.Args) < 2 { utils.NewMessageSender(ctx.Msg). diff --git a/commands/learnedDataList.go b/commands/learnedDataList.go index 80d5739..537b8fa 100644 --- a/commands/learnedDataList.go +++ b/commands/learnedDataList.go @@ -56,7 +56,8 @@ var LearnedDataListCommand *Command = &Command{ fmt.Sprintf("%s리스트 대답:머핀", configs.Config.Bot.Prefix), }, }, - Category: Chatting, + Category: Chatting, + RegisterApplicationCommand: true, MessageRun: func(ctx *MsgContext) { var length int diff --git a/commands/reloadPrompt.go b/commands/reloadPrompt.go new file mode 100644 index 0000000..536a910 --- /dev/null +++ b/commands/reloadPrompt.go @@ -0,0 +1,36 @@ +package commands + +import ( + "log" + + "git.wh64.net/muffin/goMuffin/chatbot" + "git.wh64.net/muffin/goMuffin/utils" + "github.com/bwmarrin/discordgo" +) + +var ReloadPromptCommand *Command = &Command{ + ApplicationCommand: &discordgo.ApplicationCommand{ + Name: "프롬프트재설정", + Description: "프롬프트를 다시 불러와요.", + }, + Category: DeveloperOnly, + RegisterApplicationCommand: false, + MessageRun: func(ctx *MsgContext) { + err := chatbot.ChatBot.ReloadPrompt() + if err != nil { + log.Fatalln(err) + utils.NewMessageSender(ctx.Msg). + AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "프롬프트를 다시 불러오는 데 문제가 생겼어요."})). + SetComponentsV2(true). + SetReply(true). + Send() + return + } + + utils.NewMessageSender(ctx.Msg). + AddComponents(utils.GetSuccessContainer(discordgo.TextDisplay{Content: "프롬프트를 다시 불러왔어요."})). + SetComponentsV2(true). + SetReply(true). + Send() + }, +} diff --git a/main.go b/main.go index a4c9bb5..ec068e8 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func init() { go commands.Discommand.LoadCommand(commands.LearnedDataListCommand) go commands.Discommand.LoadCommand(commands.InformationCommand) go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand) + go commands.Discommand.LoadCommand(commands.ReloadPromptCommand) go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent) go commands.Discommand.LoadComponent(components.PaginationEmbedComponent) @@ -120,6 +121,10 @@ func main() { } } + if !cmd.RegisterApplicationCommand { + continue + } + go dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand) }