From a35ba84efc6cd969d024936d7fbd49801aed956e Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sat, 5 Apr 2025 17:39:35 +0900 Subject: [PATCH] fix: Renaming mutex name --- commands/discommand.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/commands/discommand.go b/commands/discommand.go index b17e5d7..f2e9b4b 100644 --- a/commands/discommand.go +++ b/commands/discommand.go @@ -63,8 +63,8 @@ const ( Generals Category = "일반" ) -var mutex1 *sync.Mutex = &sync.Mutex{} -var mutex2 *sync.Mutex = &sync.Mutex{} +var commandMutex *sync.Mutex = &sync.Mutex{} +var componentMutex *sync.Mutex = &sync.Mutex{} func new() *DiscommandStruct { discommand := DiscommandStruct{ @@ -76,40 +76,36 @@ func new() *DiscommandStruct { } func (d *DiscommandStruct) LoadCommand(c *Command) { - mutex1.Lock() + commandMutex.Lock() d.Commands[c.Name] = c d.Aliases[c.Name] = c.Name for _, alias := range c.Aliases { d.Aliases[alias] = c.Name } - mutex1.Unlock() + commandMutex.Unlock() } func (d *DiscommandStruct) LoadComponent(c *Component) { - mutex2.Lock() + componentMutex.Lock() d.Components = append(d.Components, c) - mutex2.Unlock() + componentMutex.Unlock() } func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, m *discordgo.MessageCreate, args []string) { - command := d.Commands[name] - if command == nil { - return + if command, ok := d.Commands[name]; ok { + command.MessageRun(&MsgContext{s, m, args, command}) } - command.MessageRun(&MsgContext{s, m, args, command}) } func (d *DiscommandStruct) ChatInputRun(name string, s *discordgo.Session, i *discordgo.InteractionCreate) { - command := d.Commands[name] - if command == nil { - return + if command, ok := d.Commands[name]; ok { + command.ChatInputRun(&ChatInputContext{s, &utils.InteractionCreate{ + InteractionCreate: i, + Session: s, + Options: utils.GetInteractionOptions(i), + }, command}) } - command.ChatInputRun(&ChatInputContext{s, &utils.InteractionCreate{ - InteractionCreate: i, - Session: s, - Options: utils.GetInteractionOptions(i), - }, command}) } func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.InteractionCreate) {