feat: Add switch mode command
This commit is contained in:
parent
bd2f1dfc06
commit
ec429b5c6e
5 changed files with 105 additions and 51 deletions
|
@ -34,7 +34,7 @@ func New(s *discordgo.Session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatBot = &Chatbot{
|
ChatBot = &Chatbot{
|
||||||
Mode: ChatbotDefault,
|
Mode: ChatbotAI,
|
||||||
Gemini: gemini,
|
Gemini: gemini,
|
||||||
s: s,
|
s: s,
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,27 @@ func (c *Chatbot) SetMode(mode ChatbotMode) *Chatbot {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Chatbot) SwitchMode() *Chatbot {
|
||||||
|
switch c.Mode {
|
||||||
|
case ChatbotAI:
|
||||||
|
c.SetMode(ChatbotMuffin)
|
||||||
|
case ChatbotMuffin:
|
||||||
|
c.SetMode(ChatbotAI)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Chatbot) ModeString() string {
|
||||||
|
switch c.Mode {
|
||||||
|
case ChatbotAI:
|
||||||
|
return "AI모드"
|
||||||
|
case ChatbotMuffin:
|
||||||
|
return "머핀 모드"
|
||||||
|
default:
|
||||||
|
return "알 수 없음"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Chatbot) ReloadPrompt() error {
|
func (c *Chatbot) ReloadPrompt() error {
|
||||||
bin, err := os.ReadFile(configs.Config.Chatbot.Gemini.PromptPath)
|
bin, err := os.ReadFile(configs.Config.Chatbot.Gemini.PromptPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,7 +141,7 @@ func getDefaultResponse(s *discordgo.Session, question string) string {
|
||||||
func getAIResponse(question string) string {
|
func getAIResponse(question string) string {
|
||||||
result, err := ChatBot.Gemini.Models.GenerateContent(context.TODO(), configs.Config.Chatbot.Gemini.Model, genai.Text(question), ChatBot.config)
|
result, err := ChatBot.Gemini.Models.GenerateContent(context.TODO(), configs.Config.Chatbot.Gemini.Model, genai.Text(question), ChatBot.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ChatBot.Mode = ChatbotDefault
|
ChatBot.Mode = ChatbotMuffin
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return "AI에 문제가 생겼ㅇ어요."
|
return "AI에 문제가 생겼ㅇ어요."
|
||||||
}
|
}
|
||||||
|
@ -129,7 +150,7 @@ func getAIResponse(question string) string {
|
||||||
|
|
||||||
func (c *Chatbot) GetResponse(question string) string {
|
func (c *Chatbot) GetResponse(question string) string {
|
||||||
switch c.Mode {
|
switch c.Mode {
|
||||||
case ChatbotDefault:
|
case ChatbotMuffin:
|
||||||
return getDefaultResponse(c.s, question)
|
return getDefaultResponse(c.s, question)
|
||||||
default:
|
default:
|
||||||
return getAIResponse(question)
|
return getAIResponse(question)
|
||||||
|
|
|
@ -4,5 +4,5 @@ type ChatbotMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChatbotAI ChatbotMode = iota
|
ChatbotAI ChatbotMode = iota
|
||||||
ChatbotDefault
|
ChatbotMuffin
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package commands
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
@ -118,6 +119,15 @@ func (d *DiscommandStruct) LoadModal(m *Modal) {
|
||||||
|
|
||||||
func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, m *discordgo.MessageCreate, args []string) {
|
func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, m *discordgo.MessageCreate, args []string) {
|
||||||
if command, ok := d.Commands[name]; ok {
|
if command, ok := d.Commands[name]; ok {
|
||||||
|
if command.Category == DeveloperOnly && m.Author.ID != configs.Config.Bot.OwnerId {
|
||||||
|
utils.NewMessageSender(&utils.MessageCreate{MessageCreate: m, Session: s}).
|
||||||
|
AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "해당 명령어는 개발자만 사용 가능해요."})).
|
||||||
|
SetComponentsV2(true).
|
||||||
|
SetReply(true).
|
||||||
|
Send()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
command.MessageRun(&MsgContext{&utils.MessageCreate{
|
command.MessageRun(&MsgContext{&utils.MessageCreate{
|
||||||
MessageCreate: m,
|
MessageCreate: m,
|
||||||
Session: s,
|
Session: s,
|
||||||
|
|
27
commands/switchMode.go
Normal file
27
commands/switchMode.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/chatbot"
|
||||||
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SwitchModeCommand *Command = &Command{
|
||||||
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
|
Name: "모드전환",
|
||||||
|
Description: "머핀봇의 대답을 변경합니다.",
|
||||||
|
},
|
||||||
|
Category: DeveloperOnly,
|
||||||
|
RegisterApplicationCommand: false,
|
||||||
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
chatbot.ChatBot.SwitchMode()
|
||||||
|
|
||||||
|
utils.NewMessageSender(ctx.Msg).
|
||||||
|
AddComponents(utils.GetSuccessContainer(discordgo.TextDisplay{Content: fmt.Sprintf("모드를 %s로 바꾸었어요.", chatbot.ChatBot.ModeString())})).
|
||||||
|
SetComponentsV2(true).
|
||||||
|
SetReply(true).
|
||||||
|
Send()
|
||||||
|
},
|
||||||
|
}
|
90
main.go
90
main.go
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -16,7 +16,10 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/handler"
|
"git.wh64.net/muffin/goMuffin/handler"
|
||||||
"git.wh64.net/muffin/goMuffin/modals"
|
"git.wh64.net/muffin/goMuffin/modals"
|
||||||
|
"git.wh64.net/muffin/goMuffin/scripts"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/devproje/commando"
|
||||||
|
"github.com/devproje/commando/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -27,6 +30,7 @@ func init() {
|
||||||
go commands.Discommand.LoadCommand(commands.InformationCommand)
|
go commands.Discommand.LoadCommand(commands.InformationCommand)
|
||||||
go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand)
|
go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand)
|
||||||
go commands.Discommand.LoadCommand(commands.ReloadPromptCommand)
|
go commands.Discommand.LoadCommand(commands.ReloadPromptCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.SwitchModeCommand)
|
||||||
|
|
||||||
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
||||||
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
||||||
|
@ -35,52 +39,48 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// command := commando.NewCommando(os.Args[1:])
|
command := commando.NewCommando(os.Args[1:])
|
||||||
config := configs.Config
|
config := configs.Config
|
||||||
|
|
||||||
// if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
// command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
|
command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
|
||||||
// types.OptionData{
|
types.OptionData{
|
||||||
// Name: "id",
|
Name: "id",
|
||||||
// Desc: "봇의 디스코드 아이디",
|
Desc: "봇의 디스코드 아이디",
|
||||||
// Type: types.STRING,
|
Type: types.STRING,
|
||||||
// },
|
},
|
||||||
// types.OptionData{
|
types.OptionData{
|
||||||
// Name: "isYes",
|
Name: "isYes",
|
||||||
// Short: []string{"y"},
|
Short: []string{"y"},
|
||||||
// Type: types.BOOLEAN,
|
Type: types.BOOLEAN,
|
||||||
// },
|
},
|
||||||
// )
|
)
|
||||||
|
|
||||||
// command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
|
command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
|
||||||
// types.OptionData{
|
types.OptionData{
|
||||||
// Name: "type",
|
Name: "type",
|
||||||
// Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
|
Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
|
||||||
// Type: types.STRING,
|
Type: types.STRING,
|
||||||
// },
|
},
|
||||||
// types.OptionData{
|
types.OptionData{
|
||||||
// Name: "export-path",
|
Name: "export-path",
|
||||||
// Desc: "데이터를 저장할 위치를 지정합니다.",
|
Desc: "데이터를 저장할 위치를 지정합니다.",
|
||||||
// Type: types.STRING,
|
Type: types.STRING,
|
||||||
// },
|
},
|
||||||
// types.OptionData{
|
types.OptionData{
|
||||||
// Name: "refined",
|
Name: "refined",
|
||||||
// Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
|
Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
|
||||||
// Type: types.BOOLEAN,
|
Type: types.BOOLEAN,
|
||||||
// },
|
},
|
||||||
// )
|
)
|
||||||
|
|
||||||
// err := command.Execute()
|
err := command.Execute()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// _, _ = fmt.Fprintln(os.Stderr, err)
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||||
// os.Exit(1)
|
os.Exit(1)
|
||||||
// }
|
}
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
isAI := flag.Bool("ai", false, "시작할 때 AI모드로 설정합니다.")
|
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
dg, _ := discordgo.New("Bot " + config.Bot.Token)
|
dg, _ := discordgo.New("Bot " + config.Bot.Token)
|
||||||
|
|
||||||
|
@ -95,10 +95,6 @@ func main() {
|
||||||
|
|
||||||
chatbot.New(dg)
|
chatbot.New(dg)
|
||||||
|
|
||||||
if *isAI {
|
|
||||||
chatbot.ChatBot.SetMode(chatbot.ChatbotAI)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer dg.Close()
|
defer dg.Close()
|
||||||
|
|
||||||
// 봇의 상태메세지 변경
|
// 봇의 상태메세지 변경
|
||||||
|
|
Loading…
Reference in a new issue