mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add game command
This commit is contained in:
parent
27c8505ee0
commit
be12a44d65
26
pkg/commands/game.go
Normal file
26
pkg/commands/game.go
Normal 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)))
|
||||
}
|
|
@ -75,6 +75,13 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
|
|||
commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient)
|
||||
return
|
||||
}
|
||||
case "game":
|
||||
if msgLen == 1 {
|
||||
twitchClient.Say(message.Channel, "Usage: ()game [channel]")
|
||||
return
|
||||
} else {
|
||||
commands.Game(message.Channel, cmdParams[1], twitchClient)
|
||||
}
|
||||
case "godoc":
|
||||
if msgLen == 1 {
|
||||
twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
|
||||
|
@ -96,7 +103,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
|
|||
return
|
||||
case "pingme":
|
||||
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
|
||||
|
||||
return
|
||||
case "pyramid":
|
||||
if msgLen != 3 {
|
||||
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")
|
||||
|
|
|
@ -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
|
||||
func GenerateRandomNumber(max int) int {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return rand.Intn(max)
|
||||
}
|
||||
|
||||
// GenerateRandomNumberRange returns a random number
|
||||
// over a given minimum and maximum range.
|
||||
func GenerateRandomNumberRange(min int, max int) int {
|
||||
return (rand.Intn(max-min) + min)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue