mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add xkcd command
This commit is contained in:
parent
ea39e55342
commit
82927a97dd
|
@ -96,7 +96,7 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
}
|
||||
case "ffz":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()ffz [emote name]", tc)
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()ffz <emote name>", tc)
|
||||
return
|
||||
} else {
|
||||
commands.Ffz(target, cmdParams[1], tc)
|
||||
|
@ -120,6 +120,22 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
commands.Preview(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
case "seventv":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()seventv <emote name>", tc)
|
||||
return
|
||||
} else {
|
||||
commands.Seventv(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
case "7tv":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()seventv <emote name>", tc)
|
||||
return
|
||||
} else {
|
||||
commands.Seventv(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
case "thumbnail":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", tc)
|
||||
|
@ -135,5 +151,14 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
} else {
|
||||
commands.Tweet(target, cmdParams[1], tc)
|
||||
}
|
||||
case "rxkcd":
|
||||
commands.RandomXkcd(target, tc)
|
||||
return
|
||||
case "randomxkcd":
|
||||
commands.RandomXkcd(target, tc)
|
||||
return
|
||||
case "xkcd":
|
||||
commands.Xkcd(target, tc)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
14
pkg/commands/seventv.go
Normal file
14
pkg/commands/seventv.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v3"
|
||||
"github.com/lyx0/nourybot/pkg/common"
|
||||
)
|
||||
|
||||
func Seventv(target, emote string, tc *twitch.Client) {
|
||||
reply := fmt.Sprintf("https://7tv.app/emotes?query=%s", emote)
|
||||
|
||||
common.Send(target, reply, tc)
|
||||
}
|
60
pkg/commands/xkcd.go
Normal file
60
pkg/commands/xkcd.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v3"
|
||||
"github.com/lyx0/nourybot/pkg/common"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type xkcdResponse struct {
|
||||
Num int `json:"num"`
|
||||
SafeTitle string `json:"safe_title"`
|
||||
Img string `json:"img"`
|
||||
}
|
||||
|
||||
func Xkcd(target string, tc *twitch.Client) {
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
response, err := http.Get("https://xkcd.com/info.0.json")
|
||||
if err != nil {
|
||||
sugar.Error(err)
|
||||
}
|
||||
responseData, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
sugar.Error(err)
|
||||
}
|
||||
var responseObject xkcdResponse
|
||||
json.Unmarshal(responseData, &responseObject)
|
||||
|
||||
reply := fmt.Sprint("Current Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img)
|
||||
|
||||
common.Send(target, reply, tc)
|
||||
}
|
||||
|
||||
func RandomXkcd(target string, tc *twitch.Client) {
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
comicNum := fmt.Sprint(common.GenerateRandomNumber(2655))
|
||||
|
||||
response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json"))
|
||||
if err != nil {
|
||||
sugar.Error(err)
|
||||
}
|
||||
responseData, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
sugar.Error(err)
|
||||
}
|
||||
var responseObject xkcdResponse
|
||||
json.Unmarshal(responseData, &responseObject)
|
||||
|
||||
reply := fmt.Sprint("Random Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img)
|
||||
|
||||
common.Send(target, reply, tc)
|
||||
}
|
Loading…
Reference in a new issue