Compare commits
6 commits
d9a4105fa9
...
5d79a22ebb
Author | SHA1 | Date | |
---|---|---|---|
5d79a22ebb | |||
0583945249 | |||
25aae0c8cb | |||
d96ae87d86 | |||
6bb97c9ebd | |||
143b97f476 |
13 changed files with 95 additions and 88 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
@ -37,7 +38,7 @@ var DataLengthCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
Aliases: []string{"학습데이터량", "데이터량", "학습량"},
|
Aliases: []string{"학습데이터량", "데이터량", "학습량"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 학습데이터량",
|
Usage: fmt.Sprintf("%s학습데이터량", configs.Config.Bot.Prefix),
|
||||||
},
|
},
|
||||||
Category: Generals,
|
Category: Generals,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
@ -48,30 +49,12 @@ var DataLengthCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLength(data dataType, userId string) {
|
func getLength(data dataType, coll *mongo.Collection, filter bson.D) {
|
||||||
var err error
|
var err error
|
||||||
var cur *mongo.Cursor
|
var cur *mongo.Cursor
|
||||||
var datas []bson.M
|
var datas []bson.M
|
||||||
|
|
||||||
switch data {
|
cur, err = coll.Find(context.TODO(), filter)
|
||||||
case text:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{{}})
|
|
||||||
case muffin:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{{Key: "persona", Value: "muffin"}})
|
|
||||||
case nsfw:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{
|
|
||||||
{
|
|
||||||
Key: "persona",
|
|
||||||
Value: bson.M{
|
|
||||||
"$regex": "^user",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
case learn:
|
|
||||||
cur, err = databases.Learns.Find(context.TODO(), bson.D{{}})
|
|
||||||
case userLearn:
|
|
||||||
cur, err = databases.Learns.Find(context.TODO(), bson.D{{Key: "user_id", Value: userId}})
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -112,11 +95,18 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
go getLength(text, "")
|
go getLength(text, databases.Texts, bson.D{{}})
|
||||||
go getLength(muffin, "")
|
go getLength(muffin, databases.Texts, bson.D{{Key: "persona", Value: "muffin"}})
|
||||||
go getLength(nsfw, "")
|
go getLength(nsfw, databases.Texts, bson.D{
|
||||||
go getLength(learn, "")
|
{
|
||||||
go getLength(userLearn, userId)
|
Key: "persona",
|
||||||
|
Value: bson.M{
|
||||||
|
"$regex": "^user",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
go getLength(learn, databases.Learns, bson.D{{}})
|
||||||
|
go getLength(userLearn, databases.Learns, bson.D{{Key: "user_id", Value: userId}})
|
||||||
|
|
||||||
for range 5 {
|
for range 5 {
|
||||||
resp := <-ch
|
resp := <-ch
|
||||||
|
@ -133,6 +123,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
userLearnLength = resp.length
|
userLearnLength = resp.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(ch)
|
||||||
|
|
||||||
sum := textLength + learnLength
|
sum := textLength + learnLength
|
||||||
|
|
||||||
|
@ -140,7 +131,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
// 지금은 임시방편
|
// 지금은 임시방편
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: "저장된 데이터량",
|
Title: "저장된 데이터량",
|
||||||
Description: "총합: " + utils.InlineCode(strconv.Itoa(sum)) + "개",
|
Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))),
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
|
@ -163,7 +154,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: username + "님이 가르쳐준 데이터량",
|
Name: fmt.Sprintf("%s님이 가르쳐준 데이터량", username),
|
||||||
Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개",
|
Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개",
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,9 +2,10 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
@ -26,8 +27,8 @@ var DeleteLearnedDataCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
Aliases: []string{"잊어", "지워"},
|
Aliases: []string{"잊어", "지워"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 삭제 (삭제할 단어)",
|
Usage: fmt.Sprintf("%s삭제 (삭제할 단어)", configs.Config.Bot.Prefix),
|
||||||
Examples: []string{"머핀아 삭제 머핀"},
|
Examples: []string{fmt.Sprintf("%s삭제 머핀", configs.Config.Bot.Prefix)},
|
||||||
},
|
},
|
||||||
Category: Chattings,
|
Category: Chattings,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
@ -121,18 +122,17 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
data := datas[i]
|
data := datas[i]
|
||||||
|
|
||||||
options = append(options, discordgo.SelectMenuOption{
|
options = append(options, discordgo.SelectMenuOption{
|
||||||
Label: strconv.Itoa(i+1) + "번 지식",
|
Label: fmt.Sprintf("%d번 지식", i+1),
|
||||||
Description: data.Result,
|
Description: data.Result,
|
||||||
Value: utils.DeleteLearnedData + data.Id.Hex() + `&No.` + strconv.Itoa(i+1),
|
Value: fmt.Sprintf("%s%s&No.%d", utils.DeleteLearnedData, data.Id.Hex(), i+1),
|
||||||
})
|
})
|
||||||
description += strconv.Itoa(i+1) + ". " + data.Result + "\n"
|
description += fmt.Sprintf("%d. %s\n", i+1, data.Result)
|
||||||
}
|
}
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: command + " 삭제",
|
Title: fmt.Sprintf("%s 삭제", command),
|
||||||
Description: utils.CodeBlockWithLanguage("md", "# "+command+" 에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n"+
|
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)),
|
||||||
description),
|
Color: int(utils.EDefault),
|
||||||
Color: int(utils.EDefault),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
components := []discordgo.MessageComponent{
|
components := []discordgo.MessageComponent{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/configs"
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
@ -33,8 +34,8 @@ var HelpCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
Aliases: []string{"도움", "명령어", "help"},
|
Aliases: []string{"도움", "명령어", "help"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 도움말 [명령어]",
|
Usage: fmt.Sprintf("%s도움말 [명령어]", configs.Config.Bot.Prefix),
|
||||||
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
Examples: []string{fmt.Sprintf("%s도움말", configs.Config.Bot.Prefix), fmt.Sprintf("%s도움말 배워", configs.Config.Bot.Prefix)},
|
||||||
},
|
},
|
||||||
Category: Generals,
|
Category: Generals,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
@ -50,7 +51,7 @@ func getCommandsByCategory(d *DiscommandStruct, category Category) []string {
|
||||||
commands := []string{}
|
commands := []string{}
|
||||||
for _, command := range d.Commands {
|
for _, command := range d.Commands {
|
||||||
if command.Category == category {
|
if command.Category == category {
|
||||||
commands = append(commands, "- "+command.Name+": "+command.Description)
|
commands = append(commands, fmt.Sprintf("- %s: %s", command.Name, command.Description))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commands
|
return commands
|
||||||
|
@ -61,7 +62,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Footer: &discordgo.MessageEmbedFooter{
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
Text: "버전:" + configs.MUFFIN_VERSION,
|
Text: fmt.Sprintf("버전: %s", configs.MUFFIN_VERSION),
|
||||||
},
|
},
|
||||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
URL: s.State.User.AvatarURL("512"),
|
URL: s.State.User.AvatarURL("512"),
|
||||||
|
@ -82,13 +83,12 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if commandName == "" || Discommand.Commands[commandName] == nil {
|
if commandName == "" || Discommand.Commands[commandName] == nil {
|
||||||
embed.Title = s.State.User.Username + "의 도움말"
|
embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username)
|
||||||
embed.Description = utils.CodeBlockWithLanguage(
|
embed.Description = utils.CodeBlockWithLanguage(
|
||||||
"md",
|
"md",
|
||||||
"# 일반\n"+
|
fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s",
|
||||||
strings.Join(getCommandsByCategory(Discommand, Generals), "\n")+
|
strings.Join(getCommandsByCategory(Discommand, Generals), "\n"),
|
||||||
"\n\n# 채팅\n"+
|
strings.Join(getCommandsByCategory(Discommand, Chattings), "\n")),
|
||||||
strings.Join(getCommandsByCategory(Discommand, Chattings), "\n"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
|
@ -107,7 +107,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
command := Discommand.Commands[commandName]
|
command := Discommand.Commands[commandName]
|
||||||
|
|
||||||
embed.Title = s.State.User.Username + "의 " + command.Name + " 도움말"
|
embed.Title = fmt.Sprintf("%s의 %s 도움말", s.State.User.Username, command.Name)
|
||||||
embed.Fields = []*discordgo.MessageEmbedField{
|
embed.Fields = []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
Name: "설명",
|
Name: "설명",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/configs"
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
@ -11,10 +12,10 @@ import (
|
||||||
var InformationCommand *Command = &Command{
|
var InformationCommand *Command = &Command{
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
Name: "정보",
|
Name: "정보",
|
||||||
Description: "머핀봇의 정보를 알ㄹ려줘요.",
|
Description: "해당 봇의 정보를 알ㄹ려줘요.",
|
||||||
},
|
},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 정보",
|
Usage: fmt.Sprintf("%s정보", configs.Config.Bot.Prefix),
|
||||||
},
|
},
|
||||||
Category: Generals,
|
Category: Generals,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
@ -28,11 +29,11 @@ var InformationCommand *Command = &Command{
|
||||||
func informationRun(s *discordgo.Session, m any) {
|
func informationRun(s *discordgo.Session, m any) {
|
||||||
owner, _ := s.User(configs.Config.Bot.OwnerId)
|
owner, _ := s.User(configs.Config.Bot.OwnerId)
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: s.State.User.Username + "의 정보",
|
Title: fmt.Sprintf("%s의 정보", s.State.User.Username),
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
Name: "운영 체제",
|
Name: "운영 체제",
|
||||||
Value: utils.InlineCode(runtime.GOOS + " " + runtime.GOARCH),
|
Value: utils.InlineCode(fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "제작자",
|
Name: "제작자",
|
||||||
|
|
|
@ -35,10 +35,11 @@ var LearnCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
Aliases: []string{"공부"},
|
Aliases: []string{"공부"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 배워 (등록할 단어) (대답)",
|
Usage: fmt.Sprintf("%s배워 (등록할 단어) (대답)", configs.Config.Bot.Prefix),
|
||||||
Examples: []string{"머핀아 배워 안녕 안녕!",
|
Examples: []string{
|
||||||
"머핀아 배워 \"야 죽을래?\" \"아니요 ㅠㅠㅠ\"",
|
fmt.Sprintf("%s배워 안녕 안녕!", configs.Config.Bot.Prefix),
|
||||||
"머핀아 배워 미간은_누구야? 이봇의_개발자요",
|
fmt.Sprintf("%s배워 \"야 죽을래?\" \"아니요 ㅠㅠㅠ\"", configs.Config.Bot.Prefix),
|
||||||
|
fmt.Sprintf("%s배워 미간은_누구야? 이봇의_개발자요", configs.Config.Bot.Prefix),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Category: Chattings,
|
Category: Chattings,
|
||||||
|
@ -53,7 +54,7 @@ var LearnCommand *Command = &Command{
|
||||||
|
|
||||||
func addPrefix(arr []string) (newArr []string) {
|
func addPrefix(arr []string) (newArr []string) {
|
||||||
for _, item := range arr {
|
for _, item := range arr {
|
||||||
newArr = append(newArr, "- "+item)
|
newArr = append(newArr, fmt.Sprintf("- %s", item))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
disallows := []string{
|
disallows := []string{
|
||||||
"@everyone",
|
"@everyone",
|
||||||
"@here",
|
"@here",
|
||||||
"<@" + configs.Config.Bot.OwnerId + ">"}
|
fmt.Sprintf("<@%s>", configs.Config.Bot.OwnerId),
|
||||||
|
}
|
||||||
|
|
||||||
for _, ig := range ignores {
|
for _, ig := range ignores {
|
||||||
if strings.Contains(command, ig) {
|
if strings.Contains(command, ig) {
|
||||||
|
@ -191,7 +193,7 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: "✅ 성공",
|
Title: "✅ 성공",
|
||||||
Description: hangul.GetJosa(command, hangul.EUL_REUL) + " 배웠어요.",
|
Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)),
|
||||||
Color: int(utils.ESuccess),
|
Color: int(utils.ESuccess),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ package commands
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
@ -21,7 +21,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
Aliases: []string{"list", "목록", "지식목록"},
|
Aliases: []string{"list", "목록", "지식목록"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 리스트",
|
Usage: fmt.Sprintf("%s리스트", configs.Config.Bot.Prefix),
|
||||||
},
|
},
|
||||||
Category: Chattings,
|
Category: Chattings,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
@ -34,7 +34,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
|
|
||||||
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
||||||
for _, data := range *datas {
|
for _, data := range *datas {
|
||||||
descriptions = append(descriptions, "- "+data.Command+": "+data.Result)
|
descriptions = append(descriptions, fmt.Sprintf("- %s: %s", data.Command, data.Result))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: globalName + "님이 알려주신 지식",
|
Title: fmt.Sprintf("%s님이 알려주신 지식", globalName),
|
||||||
Description: utils.CodeBlockWithLanguage("md", "# 총 "+strconv.Itoa(len(datas))+"개에요.\n"+strings.Join(getDescriptions(&datas), "\n")),
|
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))),
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
URL: avatarUrl,
|
URL: avatarUrl,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package components
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/commands"
|
"git.wh64.net/muffin/goMuffin/commands"
|
||||||
|
@ -68,7 +69,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{
|
Embeds: &[]*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
Title: "✅ 삭제 완료",
|
Title: "✅ 삭제 완료",
|
||||||
Description: itemId + "번을 삭ㅈ제했어요.",
|
Description: fmt.Sprintf("%s번을 삭ㅈ제했어요.", itemId),
|
||||||
Color: int(utils.ESuccess),
|
Color: int(utils.ESuccess),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type botConfig struct {
|
type botConfig struct {
|
||||||
Token string
|
Token string
|
||||||
Prefix string
|
Prefix string
|
||||||
|
@ -29,23 +28,35 @@ type MuffinConfig struct {
|
||||||
func loadConfig() *MuffinConfig {
|
func loadConfig() *MuffinConfig {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("[goMuffin] 봇의 설절파일을 불러올 수가 없어요.")
|
log.Println("[goMuffin] 봇의 설절파일을 불러올 수가 없어요.")
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
config := MuffinConfig{Bot: botConfig{}, Train: trainConfig{}}
|
config := &MuffinConfig{Bot: botConfig{}, Train: trainConfig{}}
|
||||||
setConfig(&config)
|
setConfig(config)
|
||||||
|
|
||||||
return &config
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRequiredValue(key string) string {
|
||||||
|
value := os.Getenv(key)
|
||||||
|
if value == "" {
|
||||||
|
log.Fatalln(fmt.Sprintf("[goMuffin] .env 파일에서 필요한 %s값이 없어요.", key))
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func getValue(key string) string {
|
||||||
|
return os.Getenv(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setConfig(config *MuffinConfig) {
|
func setConfig(config *MuffinConfig) {
|
||||||
config.Bot.Prefix = os.Getenv("BOT_PREFIX")
|
config.Bot.Prefix = getRequiredValue("BOT_PREFIX")
|
||||||
config.Bot.Token = os.Getenv("BOT_TOKEN")
|
config.Bot.Token = getRequiredValue("BOT_TOKEN")
|
||||||
config.Bot.OwnerId = os.Getenv("BOT_OWNER_ID")
|
config.Bot.OwnerId = getRequiredValue("BOT_OWNER_ID")
|
||||||
|
|
||||||
config.Train.UserID = os.Getenv("TRAIN_USER_ID")
|
config.Train.UserID = getValue("TRAIN_USER_ID")
|
||||||
|
|
||||||
config.DatabaseURL = os.Getenv("DATABASE_URL")
|
config.DatabaseURL = getRequiredValue("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config *MuffinConfig = loadConfig()
|
var Config *MuffinConfig = loadConfig()
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MUFFIN_VERSION = "0.0.0-gopher_canary.250331b"
|
const MUFFIN_VERSION = "0.0.0-gopher_dev.250403a"
|
||||||
|
|
||||||
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module git.wh64.net/muffin/goMuffin
|
module git.wh64.net/muffin/goMuffin
|
||||||
|
|
||||||
go 1.23.2
|
go 1.24.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/LoperLee/golang-hangul-toolkit v1.1.0
|
github.com/LoperLee/golang-hangul-toolkit v1.1.0
|
||||||
|
|
|
@ -2,6 +2,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -65,7 +66,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
||||||
Text: content,
|
Text: content,
|
||||||
Persona: "user:" + m.Author.Username,
|
Persona: fmt.Sprintf("user:%s", m.Author.Username),
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -104,11 +105,12 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
for range 2 {
|
for range 2 {
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
close(ch)
|
||||||
|
|
||||||
if x > 2 && len(learnDatas) != 0 {
|
if x > 2 && len(learnDatas) != 0 {
|
||||||
data := learnDatas[rand.Intn(len(learnDatas))]
|
data := learnDatas[rand.Intn(len(learnDatas))]
|
||||||
user, _ := s.User(data.UserId)
|
user, _ := s.User(data.UserId)
|
||||||
s.ChannelMessageSendReply(m.ChannelID, data.Result+"\n"+utils.InlineCode(user.Username+"님이 알려주셨어요."), m.Reference())
|
s.ChannelMessageSendReply(m.ChannelID, fmt.Sprintf("%s\n%s", data.Result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username))), m.Reference())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
main.go
5
main.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -22,7 +21,7 @@ func main() {
|
||||||
|
|
||||||
dg, err := discordgo.New("Bot " + config.Bot.Token)
|
dg, err := discordgo.New("Bot " + config.Bot.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("[goMuffin] 봇의 세션을 만들수가 없어요.")
|
log.Println("[goMuffin] 봇의 세션을 만들수가 없어요.")
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fmt.Println("[goMuffin] 봇이 실행되고 있어요. 버전:", configs.MUFFIN_VERSION)
|
log.Println("[goMuffin] 봇이 실행되고 있어요. 버전:", configs.MUFFIN_VERSION)
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
<-sc
|
<-sc
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ const (
|
||||||
RelativeTime = "R"
|
RelativeTime = "R"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InlineCode(str string) string {
|
func InlineCode(content string) string {
|
||||||
return "`" + str + "`"
|
return fmt.Sprintf("`%s`", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeBlockWithLanguage(language string, content string) string {
|
func CodeBlockWithLanguage(language string, content string) string {
|
||||||
return "```" + language + "\n" + content + "\n" + "```"
|
return fmt.Sprintf("```%s\n%s\n```", language, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeBlock(content string) string {
|
func CodeBlock(content string) string {
|
||||||
|
@ -31,9 +31,9 @@ func CodeBlock(content string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Time(time *time.Time) string {
|
func Time(time *time.Time) string {
|
||||||
return "<t:" + strconv.FormatInt(time.Unix(), 10) + ">"
|
return fmt.Sprintf("<t:%d>", time.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeWithStyle(time *time.Time, style string) string {
|
func TimeWithStyle(time *time.Time, style string) string {
|
||||||
return "<t:" + strconv.FormatInt(time.Unix(), 10) + ":" + style + ">"
|
return fmt.Sprintf("<t:%d:%s>", time.Unix(), style)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue