-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Random): added component handler for subcommands
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/util" | ||
"strings" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The Component of the random package. | ||
type Component struct { | ||
randomBase | ||
data discordgo.MessageComponentInteractionData | ||
} | ||
|
||
// Handle handles the functionality of a component. | ||
func (c Component) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
c.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} | ||
c.member = i.Member | ||
c.user = i.User | ||
if i.Member != nil { | ||
c.user = i.Member.User | ||
} else if i.User != nil { | ||
c.member = &discordgo.Member{User: i.User} | ||
} | ||
c.data = i.MessageComponentData() | ||
|
||
ids := strings.Split(c.data.CustomID, ".") | ||
// pop the first level identifier | ||
util.ShiftL(ids) | ||
|
||
switch util.ShiftL(ids) { | ||
case "coin": | ||
c.subcommandCoin().handleComponent(ids) | ||
return | ||
case "dice": | ||
c.subcommandDice().handleComponent(ids) | ||
return | ||
case "teams": | ||
c.subcommandTeams().handleComponent(ids) | ||
return | ||
default: | ||
log.Printf("Unknown component interaction ID: %s", c.data.CustomID) | ||
} | ||
|
||
} | ||
|
||
// ID returns the custom ID of the modal to identify the module | ||
func (c Component) ID() string { | ||
return "random" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters