Skip to content

Commit

Permalink
feat: add GTENOR_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisgustavom1 committed Apr 1, 2023
1 parent 60600e7 commit 59a3771
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ FRONTEND_ROLE_ID=
BACKEND_ROLE_ID=
MOBILE_ROLE_ID=
FULLSTACK_ROLE_ID=
QA_ROLE_ID=
QA_ROLE_ID=
GTENOR_KEY=
8 changes: 5 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
GuildID string
ChannelID string
MessageID string
GTenorKey string
RemoveCommands bool
RoleMap map[string]string
}
Expand All @@ -25,6 +26,7 @@ func Load() (*Config, error) {
cfg.GuildID = os.Getenv("GUILD_ID")
cfg.ChannelID = os.Getenv("CHANNEL_ID")
cfg.MessageID = os.Getenv("MESSAGE_ID")
cfg.GTenorKey = os.Getenv("GTENOR_KEY")
cfg.RemoveCommands, err = strconv.ParseBool(os.Getenv("REMOVE_COMMANDS"))

if err != nil {
Expand All @@ -42,10 +44,10 @@ func Load() (*Config, error) {
return cfg, nil
}

func GetConfig() {
if !cfg {
func GetConfig() Config {
if cfg == nil {
log.Fatal("You must load the config")
}

return cfg
return *cfg
}
15 changes: 10 additions & 5 deletions handlers/friday.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"strings"
"time"
"io"
"net/http"
"strings"
"time"

"github.com/bwmarrin/discordgo"
"github.com/liverday/medeiro-tech-bot/config"
)

var (
Expand All @@ -21,6 +22,8 @@ var (
fallbackGifUrl = "https://tenor.com/view/dancing-random-duck-gif-25973520"
)

var cfg config.Config

type GTenorMinimalReturn struct {
Results []struct {
ID string `json:"id"`
Expand Down Expand Up @@ -65,6 +68,8 @@ type GTenorMinimalReturn struct {
}

func FridayHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
cfg = config.GetConfig()

if !strings.Contains(m.Content, fridayTrigger) {
return
}
Expand Down Expand Up @@ -100,15 +105,15 @@ func FridayHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSendComplex(m.ChannelID, message)
}

func getRandomGif(q string) (result GTenorMinimalReturn) {
func getRandomGif(search string) (result GTenorMinimalReturn) {
req, err := http.NewRequest("GET", gTenorUrl+"/random", nil)
if err != nil {
fmt.Println("Cannot make a new http Request", err)
}

query := req.URL.Query()
query.Add("q", q)
query.Add("key", "LIVDSRZULELA")
query.Add("q", search)
query.Add("key", cfg.GTenorKey)
query.Add("media_filter", "minimal")
query.Add("limit", "1")

Expand Down

0 comments on commit 59a3771

Please sign in to comment.