From 55d09e27c15f2d94adede7c02cc2d7ece953f246 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Tue, 29 Apr 2025 22:52:16 +0900 Subject: [PATCH 1/7] chore: Fixing file tree --- main.go | 15 ++- scripts/dbMigrate.go | 192 +++++++++++++++++++++++++++++++++++ scripts/deleteAllCommands.go | 49 +++++++++ 3 files changed, 247 insertions(+), 9 deletions(-) create mode 100644 scripts/dbMigrate.go create mode 100644 scripts/deleteAllCommands.go diff --git a/main.go b/main.go index d6b4f50..20a8878 100644 --- a/main.go +++ b/main.go @@ -15,8 +15,7 @@ import ( "git.wh64.net/muffin/goMuffin/configs" "git.wh64.net/muffin/goMuffin/databases" "git.wh64.net/muffin/goMuffin/handler" - dbmigrate "git.wh64.net/muffin/goMuffin/scripts/dbMigrate" - deleteallcommands "git.wh64.net/muffin/goMuffin/scripts/deleteAllCommands" + "git.wh64.net/muffin/goMuffin/scripts" "github.com/bwmarrin/discordgo" ) @@ -26,11 +25,11 @@ func main() { if len(os.Args) > 1 { switch strings.ToLower(os.Args[1]) { case "dbmigrate": - dbmigrate.DBMigrate() + scripts.DBMigrate() case "deleteallcommands": - deleteallcommands.DeleteAllCommands() + scripts.DeleteAllCommands() default: - panic(fmt.Errorf("[goMuffin] 명령어 인자에는 dbmigrate나 deleteallcommands만 올 수 있어요.")) + log.Fatalln(fmt.Errorf("[goMuffin] 명령어 인자에는 dbmigrate나 deleteallcommands만 올 수 있어요")) } return } @@ -54,6 +53,7 @@ func main() { go dg.AddHandler(handler.InteractionCreate) dg.Open() + defer dg.Close() go func() { for { @@ -77,10 +77,7 @@ func main() { go dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand) } - defer func() { - dg.Close() - databases.Client.Disconnect(context.TODO()) - }() + defer databases.Client.Disconnect(context.TODO()) log.Println("[goMuffin] 봇이 실행되고 있어요. 버전:", configs.MUFFIN_VERSION) sc := make(chan os.Signal, 1) diff --git a/scripts/dbMigrate.go b/scripts/dbMigrate.go new file mode 100644 index 0000000..22fde88 --- /dev/null +++ b/scripts/dbMigrate.go @@ -0,0 +1,192 @@ +package scripts + +import ( + "context" + "database/sql" + "fmt" + "os" + "sync" + "time" + + "git.wh64.net/muffin/goMuffin/configs" + + _ "github.com/go-sql-driver/mysql" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" +) + +var wg sync.WaitGroup + +// 이 스크립트는 MariaDB -> MongoDB로의 전환을 위해 만들었음. +func DBMigrate() { + mariaURL := os.Getenv("PREVIOUS_DATABASE_URL") + mongoURL := configs.Config.DatabaseURL + dbName := configs.Config.DBName + + dbConnectionQuery := "?parseTime=true" + + wg.Add(3) + + // statement -> text + go func() { + defer wg.Done() + + newDataList := []any{} + mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) + if err != nil { + panic(err) + } + + mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) + if err != nil { + panic(err) + } + + defer mongoDB.Disconnect(context.TODO()) + defer mariaDB.Close() + rows, err := mariaDB.Query("select text, persona, created_at from statement;") + if err != nil { + panic(err) + } + + defer rows.Close() + + i := 1 + + for rows.Next() { + var text, persona string + var createdAt time.Time + + fmt.Printf("statement %d\n", i) + err = rows.Scan(&text, &persona, &createdAt) + if err != nil { + panic(err) + } + + if text == "" { + text = "살ㄹ려주세요" + } + + newDataList = append(newDataList, bson.M{ + "text": text, + "persona": persona, + "created_at": createdAt, + }) + i++ + } + _, err = mongoDB.Database(dbName).Collection("text").InsertMany(context.TODO(), newDataList) + if err != nil { + panic(err) + } + }() + + // nsfw_content -> text + go func() { + defer wg.Done() + + newDataList := []any{} + mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) + if err != nil { + panic(err) + } + + mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) + if err != nil { + panic(err) + } + + defer mongoDB.Disconnect(context.TODO()) + defer mariaDB.Close() + rows, err := mariaDB.Query("select text, persona, created_at from nsfw_content;") + if err != nil { + panic(err) + } + + defer rows.Close() + + i := 1 + + for rows.Next() { + var text, persona string + var createdAt time.Time + + fmt.Printf("nsfw_content %d\n", i) + err = rows.Scan(&text, &persona, &createdAt) + if err != nil { + panic(err) + } + + if text == "" { + text = "살ㄹ려주세요" + } + + newDataList = append(newDataList, bson.M{ + "text": text, + "persona": persona, + "created_at": createdAt, + }) + i++ + } + + _, err = mongoDB.Database(dbName).Collection("text").InsertMany(context.TODO(), newDataList) + if err != nil { + panic(err) + } + }() + + // learn -> learn + go func() { + defer wg.Done() + + newDataList := []any{} + mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) + if err != nil { + panic(err) + } + + mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) + if err != nil { + panic(err) + } + + defer mongoDB.Disconnect(context.TODO()) + defer mariaDB.Close() + rows, err := mariaDB.Query("select command, result, user_id, created_at from learn;") + if err != nil { + panic(err) + } + + defer rows.Close() + + i := 1 + + for rows.Next() { + var command, result, userId string + var createdAt time.Time + + fmt.Printf("learn %d\n", i) + err = rows.Scan(&command, &result, &userId, &createdAt) + if err != nil { + panic(err) + } + + newDataList = append(newDataList, bson.M{ + "command": command, + "result": result, + "user_id": userId, + "created_at": createdAt, + }) + i++ + } + + _, err = mongoDB.Database(dbName).Collection("learn").InsertMany(context.TODO(), newDataList) + if err != nil { + panic(err) + } + }() + + // 모든 고루틴이 끝날 떄 까지 대기 + wg.Wait() + fmt.Println("데이터 마이그레이션이 끝났어요.") +} diff --git a/scripts/deleteAllCommands.go b/scripts/deleteAllCommands.go new file mode 100644 index 0000000..5614974 --- /dev/null +++ b/scripts/deleteAllCommands.go @@ -0,0 +1,49 @@ +package scripts + +import ( + "flag" + "fmt" + "io" + "net/http" + "os" + "strings" + + "git.wh64.net/muffin/goMuffin/configs" + "github.com/bwmarrin/discordgo" +) + +func DeleteAllCommands() { + var answer string + id := flag.String("id", "", "디스코드 봇의 토큰") + + flag.Parse() + + fmt.Printf("정말로 모든 명령어를 삭제하시겠어요? [y/N]: ") + fmt.Scanf("%s", &answer) + if strings.ToLower(answer) != "y" && strings.ToLower(answer) != "yes" { + os.Exit(1) + } + + if *id == "" { + panic(fmt.Errorf("--id 플래그의 값이 필요해요.")) + } + + c := http.Client{} + req, err := http.NewRequest("PUT", discordgo.EndpointApplicationGlobalCommands(*id), nil) + if err != nil { + panic(err) + } + + req.Header.Add("Authorization", "Bot "+configs.Config.Bot.Token) + + resp, err := c.Do(req) + if err != nil { + panic(err) + } + + bytes, err := io.ReadAll(resp.Body) + if err != nil { + panic(err) + } + fmt.Println(string(bytes)) +} From b391bde9b67a2306f930b02276dc3e42b3b8c501 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Wed, 30 Apr 2025 18:29:31 +0900 Subject: [PATCH 2/7] fix: scripts folder --- scripts/dbMigrate/main.go | 192 ------------------------------ scripts/deleteAllCommands.go | 2 +- scripts/deleteAllCommands/main.go | 49 -------- 3 files changed, 1 insertion(+), 242 deletions(-) delete mode 100644 scripts/dbMigrate/main.go delete mode 100644 scripts/deleteAllCommands/main.go diff --git a/scripts/dbMigrate/main.go b/scripts/dbMigrate/main.go deleted file mode 100644 index f4ee301..0000000 --- a/scripts/dbMigrate/main.go +++ /dev/null @@ -1,192 +0,0 @@ -package dbmigrate - -import ( - "context" - "database/sql" - "fmt" - "os" - "sync" - "time" - - "git.wh64.net/muffin/goMuffin/configs" - - _ "github.com/go-sql-driver/mysql" - "go.mongodb.org/mongo-driver/v2/bson" - "go.mongodb.org/mongo-driver/v2/mongo" - "go.mongodb.org/mongo-driver/v2/mongo/options" -) - -var wg sync.WaitGroup - -// 이 스크립트는 MariaDB -> MongoDB로의 전환을 위해 만들었음. -func DBMigrate() { - mariaURL := os.Getenv("PREVIOUS_DATABASE_URL") - mongoURL := configs.Config.DatabaseURL - dbName := configs.Config.DBName - - dbConnectionQuery := "?parseTime=true" - - wg.Add(3) - - // statement -> text - go func() { - defer wg.Done() - - newDataList := []any{} - mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) - if err != nil { - panic(err) - } - - mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) - if err != nil { - panic(err) - } - - defer mongoDB.Disconnect(context.TODO()) - defer mariaDB.Close() - rows, err := mariaDB.Query("select text, persona, created_at from statement;") - if err != nil { - panic(err) - } - - defer rows.Close() - - i := 1 - - for rows.Next() { - var text, persona string - var createdAt time.Time - - fmt.Printf("statement %d\n", i) - err = rows.Scan(&text, &persona, &createdAt) - if err != nil { - panic(err) - } - - if text == "" { - text = "살ㄹ려주세요" - } - - newDataList = append(newDataList, bson.M{ - "text": text, - "persona": persona, - "created_at": createdAt, - }) - i++ - } - _, err = mongoDB.Database(dbName).Collection("text").InsertMany(context.TODO(), newDataList) - if err != nil { - panic(err) - } - }() - - // nsfw_content -> text - go func() { - defer wg.Done() - - newDataList := []any{} - mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) - if err != nil { - panic(err) - } - - mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) - if err != nil { - panic(err) - } - - defer mongoDB.Disconnect(context.TODO()) - defer mariaDB.Close() - rows, err := mariaDB.Query("select text, persona, created_at from nsfw_content;") - if err != nil { - panic(err) - } - - defer rows.Close() - - i := 1 - - for rows.Next() { - var text, persona string - var createdAt time.Time - - fmt.Printf("nsfw_content %d\n", i) - err = rows.Scan(&text, &persona, &createdAt) - if err != nil { - panic(err) - } - - if text == "" { - text = "살ㄹ려주세요" - } - - newDataList = append(newDataList, bson.M{ - "text": text, - "persona": persona, - "created_at": createdAt, - }) - i++ - } - - _, err = mongoDB.Database(dbName).Collection("text").InsertMany(context.TODO(), newDataList) - if err != nil { - panic(err) - } - }() - - // learn -> learn - go func() { - defer wg.Done() - - newDataList := []any{} - mariaDB, err := sql.Open("mysql", mariaURL+dbConnectionQuery) - if err != nil { - panic(err) - } - - mongoDB, err := mongo.Connect(options.Client().ApplyURI(mongoURL)) - if err != nil { - panic(err) - } - - defer mongoDB.Disconnect(context.TODO()) - defer mariaDB.Close() - rows, err := mariaDB.Query("select command, result, user_id, created_at from learn;") - if err != nil { - panic(err) - } - - defer rows.Close() - - i := 1 - - for rows.Next() { - var command, result, userId string - var createdAt time.Time - - fmt.Printf("learn %d\n", i) - err = rows.Scan(&command, &result, &userId, &createdAt) - if err != nil { - panic(err) - } - - newDataList = append(newDataList, bson.M{ - "command": command, - "result": result, - "user_id": userId, - "created_at": createdAt, - }) - i++ - } - - _, err = mongoDB.Database(dbName).Collection("learn").InsertMany(context.TODO(), newDataList) - if err != nil { - panic(err) - } - }() - - // 모든 고루틴이 끝날 떄 까지 대기 - wg.Wait() - fmt.Println("데이터 마이그레이션이 끝났어요.") -} diff --git a/scripts/deleteAllCommands.go b/scripts/deleteAllCommands.go index 5614974..6e325df 100644 --- a/scripts/deleteAllCommands.go +++ b/scripts/deleteAllCommands.go @@ -25,7 +25,7 @@ func DeleteAllCommands() { } if *id == "" { - panic(fmt.Errorf("--id 플래그의 값이 필요해요.")) + panic(fmt.Errorf("--id 플래그의 값이 필요해요")) } c := http.Client{} diff --git a/scripts/deleteAllCommands/main.go b/scripts/deleteAllCommands/main.go deleted file mode 100644 index 61b8a0c..0000000 --- a/scripts/deleteAllCommands/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package deleteallcommands - -import ( - "flag" - "fmt" - "io" - "net/http" - "os" - "strings" - - "git.wh64.net/muffin/goMuffin/configs" - "github.com/bwmarrin/discordgo" -) - -func DeleteAllCommands() { - var answer string - id := flag.String("id", "", "디스코드 봇의 토큰") - - flag.Parse() - - fmt.Printf("정말로 모든 명령어를 삭제하시겠어요? [y/N]: ") - fmt.Scanf("%s", &answer) - if strings.ToLower(answer) != "y" && strings.ToLower(answer) != "yes" { - os.Exit(1) - } - - if *id == "" { - panic(fmt.Errorf("--id 플래그의 값이 필요해요.")) - } - - c := http.Client{} - req, err := http.NewRequest("PUT", discordgo.EndpointApplicationGlobalCommands(*id), nil) - if err != nil { - panic(err) - } - - req.Header.Add("Authorization", "Bot "+configs.Config.Bot.Token) - - resp, err := c.Do(req) - if err != nil { - panic(err) - } - - bytes, err := io.ReadAll(resp.Body) - if err != nil { - panic(err) - } - fmt.Println(string(bytes)) -} From 62df6e516ebeece146ffdce7d5baf39435d654da Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Wed, 30 Apr 2025 18:53:56 +0900 Subject: [PATCH 3/7] chore: Add Makefile --- Makefile | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..21f51e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +APP_NAME := goMuffin +BIN_DIR := build + +EXT := +ifeq ($(OS),Windows_NT) + EXT := .exe +endif + +BIN := $(BIN_DIR)/$(APP_NAME)$(EXT) +PKG := git.wh64.net/muffin/goMuffin + +.PHONY: all build run fmt vet deps + +all: build + +build: + @mkdir -p $(BIN_DIR) + @go build -o $(BIN) $(PKG) + +run: + @go run $(PKG) + +clean: + @rm -rf $(BIN_DIR) + +deps: + @go mod tidy + +fmt: + @go fmt $(PKG) + +vet: + @go vet $(PKG) From ec2ced40497a258bd65e6f25dc03ddfce19009c5 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Wed, 30 Apr 2025 18:55:48 +0900 Subject: [PATCH 4/7] chore: Edit Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b56e274..bcb44f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.24.1 +FROM golang:1.24.2 RUN mkdir /app WORKDIR /app COPY . . -RUN go build -o build/goMuffin git.wh64.net/muffin/goMuffin +RUN make ENTRYPOINT [ "./build/goMuffin" ] \ No newline at end of file From 1fde3e5a2ec79b6aa4b1b7334a45854bd35dd27b Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Thu, 1 May 2025 19:51:21 +0900 Subject: [PATCH 5/7] fix: Category names --- commands/dataLength.go | 10 +++++----- commands/deleteLearnedData.go | 15 +++++++-------- commands/discommand.go | 4 ++-- commands/help.go | 9 ++++----- commands/information.go | 2 +- commands/learn.go | 5 ++--- commands/learnedDataList.go | 17 +++++++++-------- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/commands/dataLength.go b/commands/dataLength.go index 0c59a5b..e14ffaa 100644 --- a/commands/dataLength.go +++ b/commands/dataLength.go @@ -42,7 +42,7 @@ var DataLengthCommand *Command = &Command{ DetailedDescription: &DetailedDescription{ Usage: fmt.Sprintf("%s학습데이터량", configs.Config.Bot.Prefix), }, - Category: Generals, + Category: General, MessageRun: func(ctx *MsgContext) { dataLengthRun(ctx.Session, ctx.Msg) }, @@ -51,11 +51,11 @@ var DataLengthCommand *Command = &Command{ }, } -func getLength(data dataType, coll *mongo.Collection, filter bson.D) { +func getLength(dType dataType, coll *mongo.Collection, filter bson.D) { defer dataLengthWg.Done() var err error var cur *mongo.Cursor - var datas []bson.M + var data []bson.M cur, err = coll.Find(context.TODO(), filter) if err != nil { @@ -64,8 +64,8 @@ func getLength(data dataType, coll *mongo.Collection, filter bson.D) { defer cur.Close(context.TODO()) - cur.All(context.TODO(), &datas) - dataLengthCh <- chStruct{name: data, length: len(datas)} + cur.All(context.TODO(), &data) + dataLengthCh <- chStruct{name: dType, length: len(data)} } func dataLengthRun(s *discordgo.Session, m any) { diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index 8e6b4c6..105c928 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -29,19 +29,18 @@ var DeleteLearnedDataCommand *Command = &Command{ Usage: fmt.Sprintf("%s삭제 (삭제할 단어)", configs.Config.Bot.Prefix), Examples: []string{fmt.Sprintf("%s삭제 머핀", configs.Config.Bot.Prefix)}, }, - Category: Chattings, + Category: Chatting, MessageRun: func(ctx *MsgContext) { deleteLearnedDataRun(ctx.Command, ctx.Session, ctx.Msg, &ctx.Args) }, ChatInputRun: func(ctx *ChatInputContext) { - var args *[]string - deleteLearnedDataRun(ctx.Command, ctx.Session, ctx.Inter, args) + deleteLearnedDataRun(ctx.Command, ctx.Session, ctx.Inter, nil) }, } func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]string) { var command, userId, description string - var datas []databases.Learn + var data []databases.Learn var options []discordgo.SelectMenuOption switch m := m.(type) { @@ -94,9 +93,9 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin return } - cur.All(context.TODO(), &datas) + cur.All(context.TODO(), &data) - if len(datas) < 1 { + if len(data) < 1 { embed := &discordgo.MessageEmbed{ Title: "❌ 오류", Description: "해당 하는 지식ㅇ을 찾을 수 없어요.", @@ -114,8 +113,8 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin return } - for i := range len(datas) { - data := datas[i] + for i := range len(data) { + data := data[i] options = append(options, discordgo.SelectMenuOption{ Label: fmt.Sprintf("%d번 지식", i+1), diff --git a/commands/discommand.go b/commands/discommand.go index f69a5a7..3221306 100644 --- a/commands/discommand.go +++ b/commands/discommand.go @@ -59,8 +59,8 @@ type Component struct { } const ( - Chattings Category = "채팅" - Generals Category = "일반" + Chatting Category = "채팅" + General Category = "일반" ) var commandMutex sync.Mutex diff --git a/commands/help.go b/commands/help.go index b87aa8c..f022633 100644 --- a/commands/help.go +++ b/commands/help.go @@ -28,13 +28,12 @@ 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: Generals, + Category: General, MessageRun: func(ctx *MsgContext) { helpRun(ctx.Command, ctx.Session, ctx.Msg, &ctx.Args) }, ChatInputRun: func(ctx *ChatInputContext) { - var args *[]string - helpRun(ctx.Command, ctx.Session, ctx.Inter, args) + helpRun(ctx.Command, ctx.Session, ctx.Inter, nil) }, } @@ -76,8 +75,8 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { embed.Description = utils.CodeBlock( "md", fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s", - strings.Join(getCommandsByCategory(Discommand, Generals), "\n"), - strings.Join(getCommandsByCategory(Discommand, Chattings), "\n")), + strings.Join(getCommandsByCategory(Discommand, General), "\n"), + strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), ) switch m := m.(type) { diff --git a/commands/information.go b/commands/information.go index 9ea6d0e..479b4d7 100644 --- a/commands/information.go +++ b/commands/information.go @@ -17,7 +17,7 @@ var InformationCommand *Command = &Command{ DetailedDescription: &DetailedDescription{ Usage: fmt.Sprintf("%s정보", configs.Config.Bot.Prefix), }, - Category: Generals, + Category: General, MessageRun: func(ctx *MsgContext) { informationRun(ctx.Session, ctx.Msg) }, diff --git a/commands/learn.go b/commands/learn.go index 6003e25..483c7b6 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -55,13 +55,12 @@ var LearnCommand *Command = &Command{ fmt.Sprintf("%s배워 \"나의 아이디를 알려줘\" \"너의 아이디는 {user.id}야.\"", configs.Config.Bot.Prefix), }, }, - Category: Chattings, + Category: Chatting, MessageRun: func(ctx *MsgContext) { learnRun(ctx.Command, ctx.Session, ctx.Msg, &ctx.Args) }, ChatInputRun: func(ctx *ChatInputContext) { - var args *[]string - learnRun(ctx.Command, ctx.Session, ctx.Inter, args) + learnRun(ctx.Command, ctx.Session, ctx.Inter, nil) }, } diff --git a/commands/learnedDataList.go b/commands/learnedDataList.go index 6558203..9c3554c 100644 --- a/commands/learnedDataList.go +++ b/commands/learnedDataList.go @@ -17,13 +17,13 @@ var LearnedDataListCommand *Command = &Command{ ApplicationCommand: &discordgo.ApplicationCommand{ Type: discordgo.ChatApplicationCommand, Name: "리스트", - Description: "당신이 가ㄹ르쳐준 단어를 나열해요.", + Description: "당신이 가ㄹ르쳐준 지식을 나열해요.", }, Aliases: []string{"list", "목록", "지식목록"}, DetailedDescription: &DetailedDescription{ Usage: fmt.Sprintf("%s리스트", configs.Config.Bot.Prefix), }, - Category: Chattings, + Category: Chatting, MessageRun: func(ctx *MsgContext) { learnedDataListRun(ctx.Session, ctx.Msg) }, @@ -32,8 +32,8 @@ var LearnedDataListCommand *Command = &Command{ }, } -func getDescriptions(datas *[]databases.Learn) (descriptions []string) { - for _, data := range *datas { +func getDescriptions(data *[]databases.Learn) (descriptions []string) { + for _, data := range *data { descriptions = append(descriptions, fmt.Sprintf("- %s: %s", data.Command, data.Result)) } return @@ -41,7 +41,8 @@ func getDescriptions(datas *[]databases.Learn) (descriptions []string) { func learnedDataListRun(s *discordgo.Session, m any) { var userId, globalName, avatarUrl string - var datas []databases.Learn + var data []databases.Learn + switch m := m.(type) { case *discordgo.MessageCreate: userId = m.Author.ID @@ -52,7 +53,7 @@ func learnedDataListRun(s *discordgo.Session, m any) { userId = m.Member.User.ID globalName = m.Member.User.GlobalName - avatarUrl = m.User.AvatarURL("512") + avatarUrl = m.Member.User.AvatarURL("512") } cur, err := databases.Learns.Find(context.TODO(), bson.D{{Key: "user_id", Value: userId}}) @@ -95,11 +96,11 @@ func learnedDataListRun(s *discordgo.Session, m any) { defer cur.Close(context.TODO()) - cur.All(context.TODO(), &datas) + cur.All(context.TODO(), &data) embed := &discordgo.MessageEmbed{ Title: fmt.Sprintf("%s님이 알려주신 지식", globalName), - Description: utils.CodeBlock("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))), + Description: utils.CodeBlock("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(data), strings.Join(getDescriptions(&data), "\n"))), Color: utils.EmbedDefault, Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: avatarUrl, From 85b98787b1b08275e8b619bba6410577fda45f33 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sun, 4 May 2025 18:07:35 +0000 Subject: [PATCH 6/7] fix: Help command's examples --- commands/help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/help.go b/commands/help.go index f022633..4d1d3df 100644 --- a/commands/help.go +++ b/commands/help.go @@ -121,7 +121,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { if command.DetailedDescription.Examples != nil { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: "예시", - Value: utils.CodeBlock("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")), + Value: utils.CodeBlock("md", strings.Join(addPrefix(command.DetailedDescription.Examples), "\n")), }) } else { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ From 7f2cdf81762461dfa13ce36fc9d950989bb9554b Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sun, 4 May 2025 18:10:02 +0000 Subject: [PATCH 7/7] chore: bump version --- configs/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/version.go b/configs/version.go index 1cc5570..dcb0b48 100644 --- a/configs/version.go +++ b/configs/version.go @@ -7,7 +7,7 @@ import ( "git.wh64.net/muffin/goMuffin/utils" ) -const MUFFIN_VERSION = "5.0.0-gopher_release.250413a" +const MUFFIN_VERSION = "5.0.1-gopher_release.250505a" var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]