From ff1933e68269b01556d86a35b751aabd5bbc7585 Mon Sep 17 00:00:00 2001 From: Joshua Taylor Date: Sun, 31 Dec 2023 09:19:51 -0600 Subject: [PATCH] Get remaining modules to be env flagged --- modules/factoids/factoids.go | 9 ++++++++- modules/twitch/command.go | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/factoids/factoids.go b/modules/factoids/factoids.go index ad7be61..a88fbf3 100644 --- a/modules/factoids/factoids.go +++ b/modules/factoids/factoids.go @@ -1,6 +1,7 @@ package factoids import ( + "errors" "fmt" "github.com/bwmarrin/discordgo" "github.com/lordralex/absol/api" @@ -8,6 +9,7 @@ import ( "github.com/lordralex/absol/api/env" "github.com/lordralex/absol/api/logger" "gorm.io/gorm" + "slices" "strings" "time" ) @@ -28,6 +30,11 @@ func RunCommand(ds *discordgo.Session, mc *discordgo.MessageCreate, cmd string, return } + guilds := env.GetStringArray("factoids.guilds", ";") + if !slices.Contains(guilds, mc.GuildID) { + return + } + factoids := make([]string, 0) if cmd == "" { factoids = []string{strings.ToLower(cmd)} @@ -70,7 +77,7 @@ func RunCommand(ds *discordgo.Session, mc *discordgo.MessageCreate, cmd string, var data []Factoid err = db.Where("name IN (?)", factoids).Find(&data).Error - if gorm.ErrRecordNotFound == err || (err == nil && len(data) == 0) { + if errors.Is(err, gorm.ErrRecordNotFound) || (err == nil && len(data) == 0) { _ = SendWithSelfDelete(ds, mc.ChannelID, "No factoid with the given name was found: "+strings.Join(factoids, ", ")) return } else if err != nil { diff --git a/modules/twitch/command.go b/modules/twitch/command.go index d11c8c9..92e6ce9 100644 --- a/modules/twitch/command.go +++ b/modules/twitch/command.go @@ -6,12 +6,14 @@ import ( "errors" "fmt" "github.com/bwmarrin/discordgo" + "github.com/lordralex/absol/api" "github.com/lordralex/absol/api/env" "github.com/lordralex/absol/api/logger" "golang.org/x/oauth2/clientcredentials" "golang.org/x/oauth2/twitch" "net/http" "net/url" + "slices" "sync" "time" ) @@ -27,6 +29,13 @@ func init() { } func RunCommand(ds *discordgo.Session, mc *discordgo.MessageCreate, cmd string, args []string) { + channel := api.GetChannel(ds, mc.ChannelID) + + guilds := env.GetStringArray("twitch.guilds", ";") + if !slices.Contains(guilds, mc.GuildID) && channel.Type != discordgo.ChannelTypeDM { + return + } + var err error if len(args) != 1 {