Skip to content

Commit

Permalink
Get remaining modules to be env flagged
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Dec 31, 2023
1 parent 9f73989 commit ff1933e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/factoids/factoids.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package factoids

import (
"errors"
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/lordralex/absol/api"
"github.com/lordralex/absol/api/database"
"github.com/lordralex/absol/api/env"
"github.com/lordralex/absol/api/logger"
"gorm.io/gorm"
"slices"
"strings"
"time"
)
Expand All @@ -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)}
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions modules/twitch/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down

0 comments on commit ff1933e

Please sign in to comment.