diff --git a/handler/messageCreate.go b/handler/messageCreate.go index 99fda87..fd0f3ee 100644 --- a/handler/messageCreate.go +++ b/handler/messageCreate.go @@ -14,7 +14,6 @@ import ( "git.wh64.net/muffin/goMuffin/utils" "github.com/bwmarrin/discordgo" "go.mongodb.org/mongo-driver/v2/bson" - "go.mongodb.org/mongo-driver/v2/mongo" ) func argParser(content string) (args []string) { @@ -109,9 +108,6 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { go func() { cur, err := databases.Database.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: content}}) if err != nil { - if err == mongo.ErrNilDocument { - learnData = []databases.Learn{} - } log.Fatalln(err) } @@ -131,27 +127,27 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { user, _ := s.User(data.UserId) result := resultParser(data.Result, s, m) - s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{ - Reference: m.Reference(), - Content: fmt.Sprintf("%s\n%s", result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username))), - AllowedMentions: &discordgo.MessageAllowedMentions{ + utils.NewMessageSender(m). + SetContent(fmt.Sprintf("%s\n%s", result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username)))). + SetAllowedMentions(discordgo.MessageAllowedMentions{ Roles: []string{}, Parse: []discordgo.AllowedMentionType{}, Users: []string{}, - }, - }) + }). + SetReply(true). + Send() return } - s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{ - Reference: m.Reference(), - Content: data[rand.Intn(len(data))].Text, - AllowedMentions: &discordgo.MessageAllowedMentions{ + utils.NewMessageSender(m). + SetContent(data[rand.Intn(len(data))].Text). + SetAllowedMentions(discordgo.MessageAllowedMentions{ Roles: []string{}, Parse: []discordgo.AllowedMentionType{}, Users: []string{}, - }, - }) + }). + SetReply(true). + Send() return } diff --git a/main.go b/main.go index 5422466..221d66a 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,20 @@ import ( "github.com/devproje/commando/types" ) +func init() { + go commands.Discommand.LoadCommand(commands.HelpCommand) + go commands.Discommand.LoadCommand(commands.DataLengthCommand) + go commands.Discommand.LoadCommand(commands.LearnCommand) + go commands.Discommand.LoadCommand(commands.LearnedDataListCommand) + go commands.Discommand.LoadCommand(commands.InformationCommand) + go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand) + + go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent) + go commands.Discommand.LoadComponent(components.PaginationEmbedComponent) + + go commands.Discommand.LoadModal(modals.PaginationEmbedModal) +} + func main() { command := commando.NewCommando(os.Args[1:]) config := configs.Config @@ -68,18 +82,6 @@ func main() { dg, _ := discordgo.New("Bot " + config.Bot.Token) - go commands.Discommand.LoadCommand(commands.HelpCommand) - go commands.Discommand.LoadCommand(commands.DataLengthCommand) - go commands.Discommand.LoadCommand(commands.LearnCommand) - go commands.Discommand.LoadCommand(commands.LearnedDataListCommand) - go commands.Discommand.LoadCommand(commands.InformationCommand) - go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand) - - go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent) - go commands.Discommand.LoadComponent(components.PaginationEmbedComponent) - - go commands.Discommand.LoadModal(modals.PaginationEmbedModal) - go dg.AddHandler(handler.MessageCreate) go dg.AddHandler(handler.InteractionCreate) diff --git a/utils/messageBuilder.go b/utils/messageBuilder.go index a17660e..3c211a8 100644 --- a/utils/messageBuilder.go +++ b/utils/messageBuilder.go @@ -8,12 +8,13 @@ type MessageCreate struct { } type MessageSender struct { - Embeds []*discordgo.MessageEmbed - Content string - Components []discordgo.MessageComponent - Ephemeral bool - Reply bool - m any + Embeds []*discordgo.MessageEmbed + Content string + Components []discordgo.MessageComponent + Ephemeral bool + Reply bool + AllowedMentions *discordgo.MessageAllowedMentions + m any } func NewMessageSender(m any) *MessageSender { @@ -45,6 +46,11 @@ func (s *MessageSender) SetReply(reply bool) *MessageSender { return s } +func (s *MessageSender) SetAllowedMentions(allowedMentions discordgo.MessageAllowedMentions) *MessageSender { + s.AllowedMentions = &allowedMentions + return s +} + func (s *MessageSender) Send() { switch m := s.m.(type) { case *MessageCreate: @@ -55,10 +61,11 @@ func (s *MessageSender) Send() { } m.Session.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{ - Content: s.Content, - Embeds: s.Embeds, - Components: s.Components, - Reference: reference, + Content: s.Content, + Embeds: s.Embeds, + Components: s.Components, + AllowedMentions: s.AllowedMentions, + Reference: reference, }) return case *InteractionCreate: @@ -83,5 +90,6 @@ func (s *MessageSender) Send() { Components: s.Components, Flags: flags, }) + return } }