diff --git a/data/lang/de.yaml b/data/lang/de.yaml index dcdcae5..7774ac3 100644 --- a/data/lang/de.yaml +++ b/data/lang/de.yaml @@ -144,6 +144,7 @@ discord.command: option.teams.option.team_amount: gruppenanzahl option.teams.option.team_amount.description: Wie viele Gruppen sollen erstellt werden? + msg.error.not_author: Das ist die Nachricht von %s. Du kannst das nicht verwenden! msg.dice.roll: Du hast eine %d gewürfelt. msg.teams.missing_option: "Fehler: Du musst entweder die Gruppengröße oder die Gruppenanzahl angeben!" msg.teams.multiple_options: "Fehler: Du kannst nicht gleichzeitig die Gruppengröße und die Gruppenanzahl angeben!" diff --git a/data/lang/en.yaml b/data/lang/en.yaml index d5bda76..ab84f87 100644 --- a/data/lang/en.yaml +++ b/data/lang/en.yaml @@ -144,6 +144,7 @@ discord.command: option.teams.option.team_amount: amount option.teams.option.team_amount.description: How many teams should be created? + msg.error.not_author: This is the message of %s. You can't use this here! msg.dice.roll: You rolled a %d msg.teams.missing_option: "Error: You need to specify either the team size or the team amount!" msg.teams.multiple_options: "Error: You can't specify both the team size and the team amount at the same time!" diff --git a/modules/random/component.go b/modules/random/component.go index 371514c..7fcdecd 100644 --- a/modules/random/component.go +++ b/modules/random/component.go @@ -25,6 +25,12 @@ func (c Component) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) } c.data = i.MessageComponentData() + if c.Interaction.Message.Type == discordgo.MessageTypeChatInputCommand { + c.originalAuthor = c.Interaction.Message.Interaction.User + } else { + c.originalAuthor = c.Interaction.Message.Author + } + ids := strings.Split(c.data.CustomID, ".") // pop the first level identifier util.ShiftL(ids) diff --git a/modules/random/handleSubcommandCoin.go b/modules/random/handleSubcommandCoin.go index 910a077..ed6b0d3 100644 --- a/modules/random/handleSubcommandCoin.go +++ b/modules/random/handleSubcommandCoin.go @@ -50,6 +50,10 @@ func (cmd subcommandCoin) handle() { func (cmd subcommandCoin) handleComponent(ids []string) { switch id := util.ShiftL(ids); id { case "reflip": + if cmd.originalAuthor.ID != cmd.user.ID { + cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.error.not_author"), cmd.originalAuthor.Mention()) + return + } cmd.ReplyComplexUpdate(cmd.flip()) return default: diff --git a/modules/random/handleSubcommandDice.go b/modules/random/handleSubcommandDice.go index 2c301d5..dcf7d4b 100644 --- a/modules/random/handleSubcommandDice.go +++ b/modules/random/handleSubcommandDice.go @@ -82,6 +82,10 @@ func (cmd subcommandDice) handle() { func (cmd subcommandDice) handleComponent(ids []string) { switch id := util.ShiftL(ids); id { case "reroll": + if cmd.originalAuthor.ID != cmd.user.ID { + cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.error.not_author"), cmd.originalAuthor.Mention()) + return + } diceRange, _ := strconv.Atoi(util.ShiftL(ids)) cmd.ReplyComplexUpdate(cmd.roll(diceRange)) return diff --git a/modules/random/handleSubcommandTeams.go b/modules/random/handleSubcommandTeams.go index 7fb37b5..21ea3c9 100644 --- a/modules/random/handleSubcommandTeams.go +++ b/modules/random/handleSubcommandTeams.go @@ -144,6 +144,10 @@ func (cmd subcommandTeams) handle() { func (cmd subcommandTeams) handleComponent(ids []string) { switch id := util.ShiftL(ids); id { case "resplit_size": + if cmd.originalAuthor.ID != cmd.user.ID { + cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.error.not_author"), cmd.originalAuthor.Mention()) + return + } teamSize, _ := strconv.Atoi(util.ShiftL(ids)) members, _, err := cmd.parseTeamEmbeds(cmd.Interaction.Message.Embeds) if err != nil { @@ -155,6 +159,10 @@ func (cmd subcommandTeams) handleComponent(ids []string) { cmd.ReplyComplexUpdate(cmd.splitTeamsSize(members, teamSize)) return case "resplit_amount": + if cmd.originalAuthor.ID != cmd.user.ID { + cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.error.not_author"), cmd.originalAuthor.Mention()) + return + } members, n, err := cmd.parseTeamEmbeds(cmd.Interaction.Message.Embeds) if err != nil { log.Printf("ERROR: could not parse team embeds: %+v", err) diff --git a/modules/random/randombase.go b/modules/random/randombase.go index 7053ab4..388390e 100644 --- a/modules/random/randombase.go +++ b/modules/random/randombase.go @@ -12,4 +12,6 @@ type randomBase struct { util.InteractionUtil member *discordgo.Member user *discordgo.User + + originalAuthor *discordgo.User }