diff --git a/cmd/bot/command.go b/cmd/bot/command.go index 5f820d9..a11d5d8 100644 --- a/cmd/bot/command.go +++ b/cmd/bot/command.go @@ -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 ", 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 ", tc) + return + } else { + commands.Seventv(target, cmdParams[1], tc) + return + } + case "7tv": + if msgLen < 2 { + common.Send(target, "Not enough arguments provided. Usage: ()seventv ", tc) + return + } else { + commands.Seventv(target, cmdParams[1], tc) + return + } case "thumbnail": if msgLen < 2 { common.Send(target, "Not enough arguments provided. Usage: ()thumbnail ", 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 } } diff --git a/pkg/commands/seventv.go b/pkg/commands/seventv.go new file mode 100644 index 0000000..f984e9b --- /dev/null +++ b/pkg/commands/seventv.go @@ -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) +} diff --git a/pkg/commands/xkcd.go b/pkg/commands/xkcd.go new file mode 100644 index 0000000..69d99cf --- /dev/null +++ b/pkg/commands/xkcd.go @@ -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) +}