fix: Renaming mutex name

This commit is contained in:
Siwoo Jeon 2025-04-05 17:39:35 +09:00
parent 9b32aaf581
commit a35ba84efc
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA

View file

@ -63,8 +63,8 @@ const (
Generals Category = "일반" Generals Category = "일반"
) )
var mutex1 *sync.Mutex = &sync.Mutex{} var commandMutex *sync.Mutex = &sync.Mutex{}
var mutex2 *sync.Mutex = &sync.Mutex{} var componentMutex *sync.Mutex = &sync.Mutex{}
func new() *DiscommandStruct { func new() *DiscommandStruct {
discommand := DiscommandStruct{ discommand := DiscommandStruct{
@ -76,40 +76,36 @@ func new() *DiscommandStruct {
} }
func (d *DiscommandStruct) LoadCommand(c *Command) { func (d *DiscommandStruct) LoadCommand(c *Command) {
mutex1.Lock() commandMutex.Lock()
d.Commands[c.Name] = c d.Commands[c.Name] = c
d.Aliases[c.Name] = c.Name d.Aliases[c.Name] = c.Name
for _, alias := range c.Aliases { for _, alias := range c.Aliases {
d.Aliases[alias] = c.Name d.Aliases[alias] = c.Name
} }
mutex1.Unlock() commandMutex.Unlock()
} }
func (d *DiscommandStruct) LoadComponent(c *Component) { func (d *DiscommandStruct) LoadComponent(c *Component) {
mutex2.Lock() componentMutex.Lock()
d.Components = append(d.Components, c) d.Components = append(d.Components, c)
mutex2.Unlock() componentMutex.Unlock()
} }
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) {
command := d.Commands[name] if command, ok := d.Commands[name]; ok {
if command == nil {
return
}
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) { func (d *DiscommandStruct) ChatInputRun(name string, s *discordgo.Session, i *discordgo.InteractionCreate) {
command := d.Commands[name] if command, ok := d.Commands[name]; ok {
if command == nil {
return
}
command.ChatInputRun(&ChatInputContext{s, &utils.InteractionCreate{ command.ChatInputRun(&ChatInputContext{s, &utils.InteractionCreate{
InteractionCreate: i, InteractionCreate: i,
Session: s, Session: s,
Options: utils.GetInteractionOptions(i), Options: utils.GetInteractionOptions(i),
}, command}) }, command})
}
} }
func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.InteractionCreate) { func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.InteractionCreate) {