Skip to content

Commit 5906bd9

Browse files
authored
Merge pull request #28 from Lumos-Programming/shion/fix-invalid-interaction-modal-event-handling
InteractionModalSubmitイベントに対する処理の修正 (#27)
2 parents 58b0948 + e97e92b commit 5906bd9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

cmd/exec.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ func (c *exec) Add(i SubCmd) {
2626
}
2727

2828
func (c *exec) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) {
29-
var name string
3029
switch i.Type {
3130
case discordgo.InteractionApplicationCommand:
32-
name = i.ApplicationCommandData().Name
31+
name := i.ApplicationCommandData().Name
32+
if h, ok := c.cmds[name]; ok {
33+
h.Handle(s, i)
34+
} else {
35+
log.Printf("unknown command: %s", name)
36+
}
37+
return
3338
case discordgo.InteractionModalSubmit:
34-
name = i.ModalSubmitData().CustomID
35-
}
36-
37-
if h, ok := c.cmds[name]; ok {
38-
h.Handle(s, i)
39-
} else {
40-
log.Printf("unknown command: %s", name)
39+
customID := i.ModalSubmitData().CustomID
40+
if h, ok := c.modals[customID]; ok {
41+
h.Handle(s, i)
42+
} else {
43+
log.Printf("unknown modal: %s", customID)
44+
}
45+
return
46+
default:
47+
log.Printf("unhandled interaction, type: %s, id: %s", i.Type, i.ID)
4148
}
4249
}

cmd/tryhackme-achievement/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
cmdName = "tryhackme-share"
13-
modalID = "tryhackme-share"
13+
modalID = "tryhackme-share-form"
1414
titleID = "challenge_title"
1515
urlID = "challenge_url"
1616
commentsID = "comments"
File renamed without changes.

0 commit comments

Comments
 (0)