Skip to content

Commit

Permalink
Add is_anyone_allowed flag to discord routes
Browse files Browse the repository at this point in the history
  • Loading branch information
xackery committed Oct 9, 2023
1 parent 9b7225e commit acfbd57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= v1.3.11
VERSION ?= v1.3.12
NAME := talkeq

# run a copy of talkeq
Expand Down
1 change: 1 addition & 0 deletions config/config_discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DiscordRoute struct {
GuildID string `toml:"guild_id,omitempty" desc:"Optional, and likely not needed to be set since guilddb file is better, destination guild ID to relay the discord message to"`
MessagePattern string `toml:"message_pattern" desc:"Destination message in. E.g. {{.Name}} says {{.ChannelName}}, '{{.Message}}"`
messagePatternTemplate *template.Template
IsAnyoneAllowed bool `toml:"is_anyone_allowed" desc:"Can anyone use this route? E.g., instead of IGN or a users.txt, anyone given access to provided channel will be able to relay in game using their discord name."`
}

// DiscordTrigger is custom discord triggering
Expand Down
25 changes: 23 additions & 2 deletions discord/discord_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,29 @@ func (t *Discord) handleMessage(s *discordgo.Session, m *discordgo.MessageCreate
}

if len(ign) == 0 {
tlog.Warn("[discord] ign not found, discarding")
return
for _, route := range t.config.Routes {
if !route.IsEnabled {
continue
}
if route.Trigger.ChannelID != m.ChannelID {
continue
}
if !route.IsAnyoneAllowed {
continue
}
member, err := s.GuildMember(m.GuildID, m.Author.ID)
if err != nil {
tlog.Warnf("[discord] guildMember failed for server_id %s, author_id %s: %s", m.GuildID, m.Author, err)
continue
}

ign = sanitize(member.Nick)
tlog.Debugf("[discord] ign not found, but anyone is allowed, using %s", ign)
}
if len(ign) == 0 {
tlog.Warn("[discord] ign not found, discarding")
return
}
}
routes := 0
for routeIndex, route := range t.config.Routes {
Expand Down

0 comments on commit acfbd57

Please sign in to comment.