add game command

This commit is contained in:
lyx0 2021-10-16 18:48:59 +02:00
parent 27c8505ee0
commit be12a44d65
3 changed files with 37 additions and 2 deletions

26
pkg/commands/game.go Normal file
View file

@ -0,0 +1,26 @@
package commands
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/gempir/go-twitch-irc/v2"
log "github.com/sirupsen/logrus"
)
func Game(channel string, name string, client *twitch.Client) {
resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/twitch/channel/%s/game", name))
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
client.Say(channel, fmt.Sprintf("%s is playing: %s", name, string(body)))
}

View file

@ -75,6 +75,13 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient) commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient)
return return
} }
case "game":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()game [channel]")
return
} else {
commands.Game(message.Channel, cmdParams[1], twitchClient)
}
case "godoc": case "godoc":
if msgLen == 1 { if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()godoc [term]") twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
@ -96,7 +103,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
return return
case "pingme": case "pingme":
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient) commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
return
case "pyramid": case "pyramid":
if msgLen != 3 { if msgLen != 3 {
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]") twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")

View file

@ -42,13 +42,15 @@ func StrGenerateRandomNumber(max string) int {
} }
} }
// GenerateRandomNumber generates a random number from // GenerateRandomNumber returns a random number from
// a given max value as a int // a given max value as a int
func GenerateRandomNumber(max int) int { func GenerateRandomNumber(max int) int {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
return rand.Intn(max) return rand.Intn(max)
} }
// GenerateRandomNumberRange returns a random number
// over a given minimum and maximum range.
func GenerateRandomNumberRange(min int, max int) int { func GenerateRandomNumberRange(min int, max int) int {
return (rand.Intn(max-min) + min) return (rand.Intn(max-min) + min)
} }