From 833eee0c99a8c7490e579dce567cb599bfafec8e Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:25:47 +0200 Subject: [PATCH 01/10] start with rewrite --- cmd/bot/bot.go | 62 ++------ cmd/main.go | 31 +++- pkg/api/aiden/aiden.go | 30 ---- pkg/api/ivr/firstline.go | 47 ------ pkg/api/ivr/followage.go | 47 ------ pkg/api/ivr/profilepicture.go | 44 ------ pkg/api/ivr/subage.go | 70 --------- pkg/api/ivr/userid.go | 40 ----- pkg/api/numbersapi.go | 34 ----- pkg/api/randomcat.go | 30 ---- pkg/api/randomdog.go | 30 ---- pkg/api/randomfox.go | 31 ---- pkg/api/randomxkcd.go | 35 ----- pkg/api/xkcd.go | 27 ---- pkg/commands/botstatus.go | 20 --- pkg/commands/bttvemotes.go | 19 --- pkg/commands/coinflip.go | 16 -- pkg/commands/color.go | 14 -- pkg/commands/echo.go | 7 - pkg/commands/eightball.go | 17 --- pkg/commands/ffzemotes.go | 20 --- pkg/commands/fill.go | 25 --- pkg/commands/firstline.go | 17 --- pkg/commands/followage.go | 16 -- pkg/commands/game.go | 20 --- pkg/commands/godocs.go | 13 -- pkg/commands/number.go | 16 -- pkg/commands/ping.go | 18 --- pkg/commands/pingme.go | 14 -- pkg/commands/profilepicture.go | 18 --- pkg/commands/pyramid.go | 49 ------ pkg/commands/randomcat.go | 12 -- pkg/commands/randomdog.go | 12 -- pkg/commands/randomfox.go | 12 -- pkg/commands/randomxkcd.go | 11 -- pkg/commands/subage.go | 18 --- pkg/commands/thumbnail.go | 16 -- pkg/commands/title.go | 19 --- pkg/commands/uptime.go | 21 --- pkg/commands/userid.go | 11 -- pkg/commands/weather.go | 20 --- pkg/commands/xd.go | 7 - pkg/commands/xkcd.go | 12 -- pkg/handlers/command.go | 267 +-------------------------------- pkg/handlers/privatemessage.go | 12 +- pkg/handlers/whisper.go | 14 -- pkg/humanize/time.go | 13 -- pkg/utils/utils.go | 79 ---------- 48 files changed, 50 insertions(+), 1383 deletions(-) delete mode 100644 pkg/api/aiden/aiden.go delete mode 100644 pkg/api/ivr/firstline.go delete mode 100644 pkg/api/ivr/followage.go delete mode 100644 pkg/api/ivr/profilepicture.go delete mode 100644 pkg/api/ivr/subage.go delete mode 100644 pkg/api/ivr/userid.go delete mode 100644 pkg/api/numbersapi.go delete mode 100644 pkg/api/randomcat.go delete mode 100644 pkg/api/randomdog.go delete mode 100644 pkg/api/randomfox.go delete mode 100644 pkg/api/randomxkcd.go delete mode 100644 pkg/api/xkcd.go delete mode 100644 pkg/commands/botstatus.go delete mode 100644 pkg/commands/bttvemotes.go delete mode 100644 pkg/commands/coinflip.go delete mode 100644 pkg/commands/color.go delete mode 100644 pkg/commands/echo.go delete mode 100644 pkg/commands/eightball.go delete mode 100644 pkg/commands/ffzemotes.go delete mode 100644 pkg/commands/fill.go delete mode 100644 pkg/commands/firstline.go delete mode 100644 pkg/commands/followage.go delete mode 100644 pkg/commands/game.go delete mode 100644 pkg/commands/godocs.go delete mode 100644 pkg/commands/number.go delete mode 100644 pkg/commands/ping.go delete mode 100644 pkg/commands/pingme.go delete mode 100644 pkg/commands/profilepicture.go delete mode 100644 pkg/commands/pyramid.go delete mode 100644 pkg/commands/randomcat.go delete mode 100644 pkg/commands/randomdog.go delete mode 100644 pkg/commands/randomfox.go delete mode 100644 pkg/commands/randomxkcd.go delete mode 100644 pkg/commands/subage.go delete mode 100644 pkg/commands/thumbnail.go delete mode 100644 pkg/commands/title.go delete mode 100644 pkg/commands/uptime.go delete mode 100644 pkg/commands/userid.go delete mode 100644 pkg/commands/weather.go delete mode 100644 pkg/commands/xd.go delete mode 100644 pkg/commands/xkcd.go delete mode 100644 pkg/handlers/whisper.go delete mode 100644 pkg/humanize/time.go delete mode 100644 pkg/utils/utils.go diff --git a/cmd/bot/bot.go b/cmd/bot/bot.go index 5845575..1480910 100644 --- a/cmd/bot/bot.go +++ b/cmd/bot/bot.go @@ -4,63 +4,33 @@ import ( "time" twitch "github.com/gempir/go-twitch-irc/v2" - cfg "github.com/lyx0/nourybot/pkg/config" - "github.com/lyx0/nourybot/pkg/handlers" - log "github.com/sirupsen/logrus" ) type Bot struct { - twitchClient *twitch.Client - cfg *cfg.Config + TwitchClient *twitch.Client Uptime time.Time } -func NewBot(cfg *cfg.Config) *Bot { - - log.Info("fn Newbot") - twitchClient := twitch.NewClient(cfg.Username, cfg.Oauth) - - return &Bot{ - cfg: cfg, - twitchClient: twitchClient, - } +type Channel struct { + Name string } -func (b *Bot) Connect() error { - log.Info("fn Connect") - - b.Uptime = time.Now() - - b.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { - handlers.HandlePrivateMessage(message, b.twitchClient, b.cfg, b.Uptime) - }) - - b.twitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) { - handlers.HandleWhisperMessage(message, b.twitchClient) - }) - - err := b.twitchClient.Connect() - if err != nil { - log.Error("Error Connecting from Twitch: ", err) +func (b *Bot) Send(target, text string) { + if len(text) == 0 { + return } - return err -} + // if message[0] == '.' || message[0] == '/' { + // message = ". " + message + // } -func (b *Bot) Disconnect() error { - err := b.twitchClient.Disconnect() - if err != nil { - log.Error("Error Disconnecting from Twitch: ", err) + if len(text) > 500 { + firstMessage := text[0:499] + secondMessage := text[499:] + b.TwitchClient.Say(target, firstMessage) + b.TwitchClient.Say(target, secondMessage) + return } - return err -} - -func (b *Bot) Say(channel string, message string) { - b.twitchClient.Say(channel, message) -} - -func (b *Bot) Join(channel string) { - log.Info("fn Join") - b.twitchClient.Join(channel) + b.TwitchClient.Say(target, text) } diff --git a/cmd/main.go b/cmd/main.go index 990c7b8..88376ec 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,17 +1,38 @@ package main import ( + "fmt" + "time" + + "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" "github.com/lyx0/nourybot/pkg/config" + "github.com/lyx0/nourybot/pkg/handlers" ) +var nb *bot.Bot + func main() { - cfg := config.LoadConfig() - nb := bot.NewBot(cfg) + conf := config.LoadConfig() - nb.Join("nourybot") + nb = &bot.Bot{ + TwitchClient: twitch.NewClient(conf.Username, conf.Oauth), + Uptime: time.Now(), + } - nb.Say("nourybot", "HeyGuys") + nb.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { + // If channelID is missing something must have gone wrong. + channelID := message.Tags["room-id"] + if channelID == "" { + fmt.Printf("Missing room-id tag in message") + return + } - nb.Connect() + // So that the bot doesn't repeat itself. + if message.Tags["user-id"] == "596581605" { + return + } + + handlers.PrivateMessage(message, nb) + }) } diff --git a/pkg/api/aiden/aiden.go b/pkg/api/aiden/aiden.go deleted file mode 100644 index 497f46e..0000000 --- a/pkg/api/aiden/aiden.go +++ /dev/null @@ -1,30 +0,0 @@ -package aiden - -import ( - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -var ( - basePath = "https://customapi.aidenwallis.co.uk/" -) - -func ApiCall(uri string) (string, error) { - resp, err := http.Get(fmt.Sprint(basePath + uri)) - if err != nil { - log.Error(err) - return "Something went wrong FeelsBadMan", err - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - return "Something went wrong FeelsBadMan", err - } - return string(body), nil -} diff --git a/pkg/api/ivr/firstline.go b/pkg/api/ivr/firstline.go deleted file mode 100644 index 3f2ae15..0000000 --- a/pkg/api/ivr/firstline.go +++ /dev/null @@ -1,47 +0,0 @@ -package ivr - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type firstLineApiResponse struct { - User string `json:"user"` - Message string `json:"message"` - Time string `json:"time"` - Error string `json:"error"` -} - -var ( - firstLineBaseUrl = "https://api.ivr.fi/logs/firstmessage" -) - -func FirstLine(streamer string, username string) (string, error) { - resp, err := http.Get(fmt.Sprintf("%s/%s/%s", firstLineBaseUrl, streamer, username)) - if err != nil { - log.Error(err) - return "Something went wrong FeelsBadMan", err - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - } - - var responseObject firstLineApiResponse - json.Unmarshal(body, &responseObject) - - // User or channel was not found - if responseObject.Error != "" { - return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil - } else { - return fmt.Sprintf(username + ": " + responseObject.Message + " (" + responseObject.Time + " ago)."), nil - } - -} diff --git a/pkg/api/ivr/followage.go b/pkg/api/ivr/followage.go deleted file mode 100644 index 2ab1ea9..0000000 --- a/pkg/api/ivr/followage.go +++ /dev/null @@ -1,47 +0,0 @@ -package ivr - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -// https://api.ivr.fi -type followageApiResponse struct { - User string `json:"user"` - UserID string `json:"userid"` - Channel string `json:"channel"` - ChannelId string `json:"channelid"` - FollowedAt string `json:"followedAt"` - Error string `json:"error"` -} - -func Followage(streamer string, username string) (string, error) { - resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/subage/%s/%s", username, streamer)) - if err != nil { - log.Error(err) - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - } - - var responseObject followageApiResponse - json.Unmarshal(body, &responseObject) - - // User or channel was not found - if responseObject.Error != "" { - return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil - } else if responseObject.FollowedAt == "" { - return fmt.Sprintf(username + " is not following " + streamer), nil - } else { - d := responseObject.FollowedAt[:10] - return fmt.Sprintf(username + " has been following " + streamer + " since " + d + "."), nil - } -} diff --git a/pkg/api/ivr/profilepicture.go b/pkg/api/ivr/profilepicture.go deleted file mode 100644 index 5494996..0000000 --- a/pkg/api/ivr/profilepicture.go +++ /dev/null @@ -1,44 +0,0 @@ -package ivr - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -// https://api.ivr.fi -type pfpApiResponse struct { - Logo string `json:"logo"` - Error string `json:"error"` -} - -var ( - baseUrl = "https://api.ivr.fi/twitch/resolve" -) - -func ProfilePicture(username string) (string, error) { - resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, username)) - if err != nil { - log.Error(err) - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - } - - var responseObject pfpApiResponse - json.Unmarshal(body, &responseObject) - - // User not found - if responseObject.Error != "" { - return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil - } else { - return fmt.Sprintf(responseObject.Logo), nil - } -} diff --git a/pkg/api/ivr/subage.go b/pkg/api/ivr/subage.go deleted file mode 100644 index 1c03781..0000000 --- a/pkg/api/ivr/subage.go +++ /dev/null @@ -1,70 +0,0 @@ -package ivr - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type subageApiResponse struct { - User string `json:"user"` - UserID string `json:"userId"` - Channel string `json:"channel"` - ChannelId string `json:"channelid"` - SubageHidden bool `json:"hidden"` - Subscribed bool `json:"subscribed"` - FollowedAt string `json:"followedAt"` - Cumulative cumulative `json:"cumulative"` - Streak subStreak `json:"streak"` - Error string `json:"error"` -} - -type cumulative struct { - Months int `json:"months"` -} - -type subStreak struct { - Months int `json:"months"` -} - -var ( - subageBaseUrl = "https://api.ivr.fi/twitch/subage" -) - -func Subage(username string, streamer string) (string, error) { - resp, err := http.Get(fmt.Sprintf("%s/%s/%s", subageBaseUrl, username, streamer)) - if err != nil { - log.Error(err) - return "Something went wrong FeelsBadMan", err - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - } - - var responseObject subageApiResponse - json.Unmarshal(body, &responseObject) - - // User or channel was not found - if responseObject.Error != "" { - reply := fmt.Sprintf(responseObject.Error + " FeelsBadMan") - // client.Say(channel, fmt.Sprintf(responseObject.Error+" FeelsBadMan")) - return reply, nil - } - - if responseObject.SubageHidden { - - reply := fmt.Sprintf(username + " has their subscription status hidden. FeelsBadMan") - return reply, nil - } else { - months := fmt.Sprint(responseObject.Cumulative.Months) - reply := fmt.Sprintf(username + " has been subscribed to " + streamer + " for " + months + " months.") - return reply, nil - } -} diff --git a/pkg/api/ivr/userid.go b/pkg/api/ivr/userid.go deleted file mode 100644 index 80c8e7c..0000000 --- a/pkg/api/ivr/userid.go +++ /dev/null @@ -1,40 +0,0 @@ -package ivr - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -// https://api.ivr.fi -type uidApiResponse struct { - Id string `json:"id"` - Error string `json:"error"` -} - -func Userid(username string) string { - resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/resolve/%s", username)) - if err != nil { - log.Error(err) - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Error(err) - } - - var responseObject uidApiResponse - json.Unmarshal(body, &responseObject) - - // User not found - if responseObject.Error != "" { - return fmt.Sprintf(responseObject.Error + " FeelsBadMan") - } else { - return fmt.Sprintf(responseObject.Id) - } -} diff --git a/pkg/api/numbersapi.go b/pkg/api/numbersapi.go deleted file mode 100644 index e1d4799..0000000 --- a/pkg/api/numbersapi.go +++ /dev/null @@ -1,34 +0,0 @@ -package api - -import ( - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -func RandomNumber() string { - response, err := http.Get("http://numbersapi.com/random/trivia") - if err != nil { - log.Error(err) - } - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - - return string(responseData) -} - -func Number(number string) string { - response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number))) - if err != nil { - log.Error(err) - } - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - return string(responseData) -} diff --git a/pkg/api/randomcat.go b/pkg/api/randomcat.go deleted file mode 100644 index efede29..0000000 --- a/pkg/api/randomcat.go +++ /dev/null @@ -1,30 +0,0 @@ -package api - -import ( - "encoding/json" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type randomCatResponse struct { - File string `json:"file"` -} - -func RandomCat() string { - response, err := http.Get("https://aws.random.cat/meow") - if err != nil { - log.Error(err) - } - - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - - var responseObject randomCatResponse - json.Unmarshal(responseData, &responseObject) - - return string(responseObject.File) -} diff --git a/pkg/api/randomdog.go b/pkg/api/randomdog.go deleted file mode 100644 index 7b17af5..0000000 --- a/pkg/api/randomdog.go +++ /dev/null @@ -1,30 +0,0 @@ -package api - -import ( - "encoding/json" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type randomDogResponse struct { - Url string `json:"url"` -} - -func RandomDog() string { - response, err := http.Get("https://random.dog/woof.json") - if err != nil { - log.Error(err) - } - - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - - var responseObject randomDogResponse - json.Unmarshal(responseData, &responseObject) - - return string(responseObject.Url) -} diff --git a/pkg/api/randomfox.go b/pkg/api/randomfox.go deleted file mode 100644 index 6a4bfc5..0000000 --- a/pkg/api/randomfox.go +++ /dev/null @@ -1,31 +0,0 @@ -package api - -import ( - "encoding/json" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type randomFoxResponse struct { - Image string `json:"image"` - Link string `json:"link"` -} - -func RandomFox() string { - response, err := http.Get("https://randomfox.ca/floof/") - if err != nil { - log.Error(err) - } - - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - - var responseObject randomFoxResponse - json.Unmarshal(responseData, &responseObject) - - return string(responseObject.Image) -} diff --git a/pkg/api/randomxkcd.go b/pkg/api/randomxkcd.go deleted file mode 100644 index 0384758..0000000 --- a/pkg/api/randomxkcd.go +++ /dev/null @@ -1,35 +0,0 @@ -package api - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - "github.com/lyx0/nourybot/pkg/utils" - log "github.com/sirupsen/logrus" -) - -type XkcdResponse struct { - Num int `json:"num"` - SafeTitle string `json:"safe_title"` - Img string `json:"img"` -} - -func RandomXkcd() string { - comicNum := fmt.Sprint(utils.GenerateRandomNumber(2468)) - response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json")) - if err != nil { - log.Error(err) - } - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - var responseObject XkcdResponse - json.Unmarshal(responseData, &responseObject) - - reply := fmt.Sprint("Random Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img) - - return reply -} diff --git a/pkg/api/xkcd.go b/pkg/api/xkcd.go deleted file mode 100644 index 6a3776d..0000000 --- a/pkg/api/xkcd.go +++ /dev/null @@ -1,27 +0,0 @@ -package api - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -func Xkcd() string { - response, err := http.Get("https://xkcd.com/info.0.json") - if err != nil { - log.Error(err) - } - responseData, err := ioutil.ReadAll(response.Body) - if err != nil { - log.Error(err) - } - var responseObject XkcdResponse - json.Unmarshal(responseData, &responseObject) - - reply := fmt.Sprint("Current Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img) - - return reply -} diff --git a/pkg/commands/botstatus.go b/pkg/commands/botstatus.go deleted file mode 100644 index 1632da4..0000000 --- a/pkg/commands/botstatus.go +++ /dev/null @@ -1,20 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func BotStatus(channel string, name string, client *twitch.Client) { - resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/botStatus/%s?includeLimits=1", name)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - - client.Say(channel, resp) - -} diff --git a/pkg/commands/bttvemotes.go b/pkg/commands/bttvemotes.go deleted file mode 100644 index db389c8..0000000 --- a/pkg/commands/bttvemotes.go +++ /dev/null @@ -1,19 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func BttvEmotes(channel string, client *twitch.Client) { - resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/bttv", channel)) - if err != nil { - log.Error(err) - client.Say(channel, "Something went wrong FeelsBadMan") - } - - client.Say(channel, string(resp)) -} diff --git a/pkg/commands/coinflip.go b/pkg/commands/coinflip.go deleted file mode 100644 index c713041..0000000 --- a/pkg/commands/coinflip.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/utils" -) - -func Coinflip(channel string, client *twitch.Client) { - result := utils.GenerateRandomNumber(2) - - if result == 1 { - client.Say(channel, "Heads") - } else { - client.Say(channel, "Tails") - } -} diff --git a/pkg/commands/color.go b/pkg/commands/color.go deleted file mode 100644 index 1740603..0000000 --- a/pkg/commands/color.go +++ /dev/null @@ -1,14 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" -) - -func Color(message twitch.PrivateMessage, client *twitch.Client) { - reply := fmt.Sprintf("@%v, your color is %v", message.User.DisplayName, message.User.Color) - - client.Say(message.Channel, reply) - -} diff --git a/pkg/commands/echo.go b/pkg/commands/echo.go deleted file mode 100644 index cb615bb..0000000 --- a/pkg/commands/echo.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/gempir/go-twitch-irc/v2" - -func Echo(channel string, message string, client *twitch.Client) { - client.Say(channel, message) -} diff --git a/pkg/commands/eightball.go b/pkg/commands/eightball.go deleted file mode 100644 index 47aa4ea..0000000 --- a/pkg/commands/eightball.go +++ /dev/null @@ -1,17 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func EightBall(channel string, client *twitch.Client) { - resp, err := aiden.ApiCall("api/v1/misc/8ball") - if err != nil { - log.Error(err) - client.Say(channel, "Something went wrong FeelsBadMan") - } - - client.Say(channel, string(resp)) -} diff --git a/pkg/commands/ffzemotes.go b/pkg/commands/ffzemotes.go deleted file mode 100644 index 7ab9fdd..0000000 --- a/pkg/commands/ffzemotes.go +++ /dev/null @@ -1,20 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func FfzEmotes(channel string, client *twitch.Client) { - - resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/ffz", channel)) - if err != nil { - log.Error(err) - client.Say(channel, "Something went wrong FeelsBadMan") - } - - client.Say(channel, string(resp)) -} diff --git a/pkg/commands/fill.go b/pkg/commands/fill.go deleted file mode 100644 index c5f6379..0000000 --- a/pkg/commands/fill.go +++ /dev/null @@ -1,25 +0,0 @@ -package commands - -import ( - "fmt" - "strings" - - "github.com/gempir/go-twitch-irc/v2" -) - -func Fill(channel string, emote string, client *twitch.Client) { - if emote[0] == '.' || emote[0] == '/' { - client.Say(channel, ":tf:") - return - } - - // Get the length of the emote - emoteLength := (len(emote) + 1) - - // Check how often the emote fits into a single message - repeatCount := (499 / emoteLength) - - reply := strings.Repeat(fmt.Sprintf(emote+" "), repeatCount) - client.Say(channel, reply) - -} diff --git a/pkg/commands/firstline.go b/pkg/commands/firstline.go deleted file mode 100644 index f387e24..0000000 --- a/pkg/commands/firstline.go +++ /dev/null @@ -1,17 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/ivr" -) - -func Firstline(channel string, streamer string, username string, client *twitch.Client) { - ivrResponse, err := ivr.FirstLine(streamer, username) - if err != nil { - client.Say(channel, fmt.Sprint(err)) - return - } - client.Say(channel, ivrResponse) -} diff --git a/pkg/commands/followage.go b/pkg/commands/followage.go deleted file mode 100644 index 0825050..0000000 --- a/pkg/commands/followage.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/ivr" -) - -func Followage(channel string, streamer string, username string, client *twitch.Client) { - ivrResponse, err := ivr.Followage(streamer, username) - if err != nil { - client.Say(channel, fmt.Sprint(err)) - } - client.Say(channel, ivrResponse) -} diff --git a/pkg/commands/game.go b/pkg/commands/game.go deleted file mode 100644 index 797e11c..0000000 --- a/pkg/commands/game.go +++ /dev/null @@ -1,20 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func Game(channel string, name string, client *twitch.Client) { - - game, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/game", name)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - reply := fmt.Sprintf("@%s was last seen playing: %s", name, game) - client.Say(channel, reply) -} diff --git a/pkg/commands/godocs.go b/pkg/commands/godocs.go deleted file mode 100644 index 65da7e2..0000000 --- a/pkg/commands/godocs.go +++ /dev/null @@ -1,13 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" -) - -func Godocs(channel string, searchTerm string, client *twitch.Client) { - resp := fmt.Sprintf("https://godocs.io/?q=%s", searchTerm) - - client.Say(channel, resp) -} diff --git a/pkg/commands/number.go b/pkg/commands/number.go deleted file mode 100644 index 11942b9..0000000 --- a/pkg/commands/number.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func RandomNumber(channel string, client *twitch.Client) { - reply := api.RandomNumber() - client.Say(channel, string(reply)) -} - -func Number(channel string, number string, client *twitch.Client) { - reply := api.Number(number) - client.Say(channel, string(reply)) -} diff --git a/pkg/commands/ping.go b/pkg/commands/ping.go deleted file mode 100644 index 78a0ced..0000000 --- a/pkg/commands/ping.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "fmt" - "time" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/humanize" - "github.com/lyx0/nourybot/pkg/utils" -) - -func Ping(channel string, client *twitch.Client, uptime time.Time) { - commandCount := fmt.Sprint(utils.GetCommandsUsed()) - botUptime := humanize.Time(uptime) - - reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v", commandCount, botUptime) - client.Say(channel, reply) -} diff --git a/pkg/commands/pingme.go b/pkg/commands/pingme.go deleted file mode 100644 index 26cc98c..0000000 --- a/pkg/commands/pingme.go +++ /dev/null @@ -1,14 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" -) - -func Pingme(channel string, user string, client *twitch.Client) { - response := fmt.Sprintf("@%s", user) - - client.Say(channel, response) - -} diff --git a/pkg/commands/profilepicture.go b/pkg/commands/profilepicture.go deleted file mode 100644 index e52f412..0000000 --- a/pkg/commands/profilepicture.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/ivr" -) - -func ProfilePicture(channel string, target string, client *twitch.Client) { - reply, err := ivr.ProfilePicture(target) - if err != nil { - client.Say(channel, fmt.Sprint(err)) - return - } - - client.Say(channel, reply) -} diff --git a/pkg/commands/pyramid.go b/pkg/commands/pyramid.go deleted file mode 100644 index aa2e7e7..0000000 --- a/pkg/commands/pyramid.go +++ /dev/null @@ -1,49 +0,0 @@ -package commands - -import ( - "fmt" - "strconv" - "strings" - - "github.com/gempir/go-twitch-irc/v2" -) - -func Pyramid(channel string, size string, emote string, client *twitch.Client) { - if size[0] == '.' || size[0] == '/' { - client.Say(channel, ":tf:") - return - } - - if emote[0] == '.' || emote[0] == '/' { - client.Say(channel, ":tf:") - return - } - - pyramidSize, err := strconv.Atoi(size) - pyramidEmote := fmt.Sprint(emote + " ") - - if err != nil { - client.Say(channel, "Something went wrong") - } - - if pyramidSize == 1 { - client.Say(channel, fmt.Sprint(pyramidEmote+"...")) - return - } - - if pyramidSize > 20 { - client.Say(channel, "Max pyramid size is 20") - return - } - - for i := 0; i <= pyramidSize; i++ { - pyramidMessageAsc := strings.Repeat(pyramidEmote, i) - // fmt.Println(pyramidMessageAsc) - client.Say(channel, pyramidMessageAsc) - } - for j := pyramidSize - 1; j >= 0; j-- { - pyramidMessageDesc := strings.Repeat(pyramidEmote, j) - // fmt.Println(pyramidMessageDesc) - client.Say(channel, pyramidMessageDesc) - } -} diff --git a/pkg/commands/randomcat.go b/pkg/commands/randomcat.go deleted file mode 100644 index 2987d56..0000000 --- a/pkg/commands/randomcat.go +++ /dev/null @@ -1,12 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func RandomCat(channel string, client *twitch.Client) { - reply := api.RandomCat() - - client.Say(channel, reply) -} diff --git a/pkg/commands/randomdog.go b/pkg/commands/randomdog.go deleted file mode 100644 index ece7677..0000000 --- a/pkg/commands/randomdog.go +++ /dev/null @@ -1,12 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func RandomDog(channel string, client *twitch.Client) { - reply := api.RandomDog() - - client.Say(channel, reply) -} diff --git a/pkg/commands/randomfox.go b/pkg/commands/randomfox.go deleted file mode 100644 index 97c7e5e..0000000 --- a/pkg/commands/randomfox.go +++ /dev/null @@ -1,12 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func RandomFox(channel string, client *twitch.Client) { - reply := api.RandomFox() - - client.Say(channel, reply) -} diff --git a/pkg/commands/randomxkcd.go b/pkg/commands/randomxkcd.go deleted file mode 100644 index 0dffb1a..0000000 --- a/pkg/commands/randomxkcd.go +++ /dev/null @@ -1,11 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func RandomXkcd(channel string, client *twitch.Client) { - reply := api.RandomXkcd() - client.Say(channel, reply) -} diff --git a/pkg/commands/subage.go b/pkg/commands/subage.go deleted file mode 100644 index c101818..0000000 --- a/pkg/commands/subage.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/ivr" -) - -func Subage(channel string, username string, streamer string, client *twitch.Client) { - - ivrResponse, err := ivr.Subage(username, streamer) - if err != nil { - client.Say(channel, fmt.Sprint(err)) - return - } - client.Say(channel, ivrResponse) -} diff --git a/pkg/commands/thumbnail.go b/pkg/commands/thumbnail.go deleted file mode 100644 index 311257c..0000000 --- a/pkg/commands/thumbnail.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/utils" -) - -func Thumbnail(channel string, target string, client *twitch.Client) { - imageHeight := utils.GenerateRandomNumberRange(1040, 1080) - imageWidth := utils.GenerateRandomNumberRange(1890, 1920) - response := fmt.Sprintf("https://static-cdn.jtvnw.net/previews-ttv/live_user_%v-%vx%v.jpg", target, imageWidth, imageHeight) - - client.Say(channel, response) -} diff --git a/pkg/commands/title.go b/pkg/commands/title.go deleted file mode 100644 index 0a69bea..0000000 --- a/pkg/commands/title.go +++ /dev/null @@ -1,19 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func Title(channel string, target string, client *twitch.Client) { - title, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/title", target)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - reply := fmt.Sprintf("%s title is: %s", target, title) - client.Say(channel, reply) -} diff --git a/pkg/commands/uptime.go b/pkg/commands/uptime.go deleted file mode 100644 index 12bcbbf..0000000 --- a/pkg/commands/uptime.go +++ /dev/null @@ -1,21 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func Uptime(channel string, name string, client *twitch.Client) { - - resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/uptime", name)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - - client.Say(channel, resp) - -} diff --git a/pkg/commands/userid.go b/pkg/commands/userid.go deleted file mode 100644 index 2cdaf0e..0000000 --- a/pkg/commands/userid.go +++ /dev/null @@ -1,11 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/ivr" -) - -func Userid(channel string, target string, client *twitch.Client) { - reply := ivr.Userid(target) - client.Say(channel, reply) -} diff --git a/pkg/commands/weather.go b/pkg/commands/weather.go deleted file mode 100644 index 7dffced..0000000 --- a/pkg/commands/weather.go +++ /dev/null @@ -1,20 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api/aiden" - log "github.com/sirupsen/logrus" -) - -func Weather(channel string, location string, client *twitch.Client) { - - reply, err := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - client.Say(channel, reply) - -} diff --git a/pkg/commands/xd.go b/pkg/commands/xd.go deleted file mode 100644 index 1afda65..0000000 --- a/pkg/commands/xd.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/gempir/go-twitch-irc/v2" - -func Xd(channel string, client *twitch.Client) { - client.Say(channel, "xd") -} diff --git a/pkg/commands/xkcd.go b/pkg/commands/xkcd.go deleted file mode 100644 index 646dd91..0000000 --- a/pkg/commands/xkcd.go +++ /dev/null @@ -1,12 +0,0 @@ -package commands - -import ( - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/api" -) - -func Xkcd(channel string, client *twitch.Client) { - reply := api.Xkcd() - client.Say(channel, reply) - -} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 9da2edf..5e1dd1b 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -1,271 +1,14 @@ package handlers import ( - "strings" - "time" - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/commands" - "github.com/lyx0/nourybot/pkg/utils" - log "github.com/sirupsen/logrus" + "github.com/lyx0/nourybot/cmd/bot" + "github.com/sirupsen/logrus" ) -// HandleCommand receives a twitch.PrivateMessage from -// HandlePrivateMessage where it found a command in it. -// HandleCommand passes on the message to the specific -// command handler for further action. -func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, uptime time.Time) { - log.Info("fn HandleCommand") +func Command(message twitch.PrivateMessage, nb *bot.Bot) { + logrus.Info("fn Command") - // Counter that increments on every command call. - utils.CommandUsed() + nb.Send("nourybot", "xd") - // commandName is the actual command name without the prefix. - commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:]) - - // cmdParams are additional command inputs. - // example: - // weather san antonio - // is - // commandName cmdParams[0] cmdParams[1] - cmdParams := strings.SplitN(message.Message, " ", 500) - - // msgLen is the amount of words in the message without the prefix. - // Useful for checking if enough cmdParams are given. - msgLen := len(strings.SplitN(message.Message, " ", -2)) - - switch commandName { - case "": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Why yes, that's my prefix :)") - return - } - case "botstatus": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()botstatus [username]") - return - } else { - commands.BotStatus(message.Channel, cmdParams[1], twitchClient) - return - } - case "bttvemotes": - commands.BttvEmotes(message.Channel, twitchClient) - return - case "cf": - commands.Coinflip(message.Channel, twitchClient) - return - case "coin": - commands.Coinflip(message.Channel, twitchClient) - return - case "coinflip": - commands.Coinflip(message.Channel, twitchClient) - return - case "color": - commands.Color(message, twitchClient) - return - case "mycolor": - commands.Color(message, twitchClient) - return - case "echo": - commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient) - return - case "8ball": - commands.EightBall(message.Channel, twitchClient) - return - case "ffzemotes": - commands.FfzEmotes(message.Channel, twitchClient) - return - case "fill": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()fill [emote]") - return - } else { - commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient) - return - } - case "firstline": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()firstline [channel] [user]") - return - } else if msgLen == 2 { - commands.Firstline(message.Channel, message.Channel, cmdParams[1], twitchClient) - return - } else { - commands.Firstline(message.Channel, cmdParams[1], cmdParams[2], twitchClient) - return - } - case "fl": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()firstline [channel] [user]") - return - } else if msgLen == 2 { - commands.Firstline(message.Channel, message.Channel, cmdParams[1], twitchClient) - return - } else { - commands.Firstline(message.Channel, cmdParams[1], cmdParams[2], twitchClient) - return - } - case "followage": - if msgLen <= 2 { - twitchClient.Say(message.Channel, "Usage: ()followage [channel] [user]") - return - } else { - commands.Followage(message.Channel, cmdParams[1], cmdParams[2], 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]") - return - } else { - commands.Godocs(message.Channel, message.Message[8:len(message.Message)], twitchClient) - return - } - case "godocs": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()godoc [term]") - return - } else { - commands.Godocs(message.Channel, message.Message[9:len(message.Message)], twitchClient) - return - } - case "num": - if msgLen == 1 { - commands.RandomNumber(message.Channel, twitchClient) - } else { - commands.Number(message.Channel, cmdParams[1], twitchClient) - } - case "number": - if msgLen == 1 { - commands.RandomNumber(message.Channel, twitchClient) - } else { - commands.Number(message.Channel, cmdParams[1], twitchClient) - } - case "ping": - commands.Ping(message.Channel, twitchClient, uptime) - return - case "pingme": - commands.Pingme(message.Channel, message.User.DisplayName, twitchClient) - return - case "preview": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()preview [channel]") - return - } else { - commands.Thumbnail(message.Channel, cmdParams[1], twitchClient) - return - } - case "profilepicture": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()profilepicture [user]") - return - } - commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient) - return - case "pfp": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()pfp [user]") - return - } - commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient) - return - case "pyramid": - if msgLen != 3 { - twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]") - } else if utils.ElevatedPrivsMessage(message) { - commands.Pyramid(message.Channel, cmdParams[1], cmdParams[2], twitchClient) - } else { - twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan") - } - case "randomcat": - commands.RandomCat(message.Channel, twitchClient) - return - case "randomdog": - commands.RandomDog(message.Channel, twitchClient) - return - case "randomfox": - commands.RandomFox(message.Channel, twitchClient) - return - case "randomxkcd": - commands.RandomXkcd(message.Channel, twitchClient) - return - case "subage": - if msgLen < 3 { - twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]") - return - } else { - commands.Subage(message.Channel, cmdParams[1], cmdParams[2], twitchClient) - return - } - case "thumb": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]") - return - } else { - commands.Thumbnail(message.Channel, cmdParams[1], twitchClient) - return - } - case "thumbnail": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]") - return - } else { - commands.Thumbnail(message.Channel, cmdParams[1], twitchClient) - return - } - case "title": - if msgLen == 1 { - commands.Title(message.Channel, message.Channel, twitchClient) - return - } else { - commands.Title(message.Channel, cmdParams[1], twitchClient) - return - } - case "uptime": - if msgLen == 1 { - commands.Uptime(message.Channel, message.Channel, twitchClient) - return - } else { - commands.Uptime(message.Channel, cmdParams[1], twitchClient) - return - } - case "uid": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()uid [username]") - return - } else { - commands.Userid(message.Channel, cmdParams[1], twitchClient) - return - } - case "userid": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()userid [username]") - return - } else { - commands.Userid(message.Channel, cmdParams[1], twitchClient) - return - } - case "weather": - if msgLen == 1 { - twitchClient.Say(message.Channel, "Usage: ()weather [location]") - return - } else { - commands.Weather(message.Channel, message.Message[9:len(message.Message)], twitchClient) - return - } - case "xd": - commands.Xd(message.Channel, twitchClient) - return - - case "xkcd": - commands.Xkcd(message.Channel, twitchClient) - return - } } diff --git a/pkg/handlers/privatemessage.go b/pkg/handlers/privatemessage.go index fabb72a..c18cb64 100644 --- a/pkg/handlers/privatemessage.go +++ b/pkg/handlers/privatemessage.go @@ -1,10 +1,8 @@ package handlers import ( - "time" - "github.com/gempir/go-twitch-irc/v2" - "github.com/lyx0/nourybot/pkg/config" + "github.com/lyx0/nourybot/cmd/bot" log "github.com/sirupsen/logrus" ) @@ -12,7 +10,7 @@ import ( // *twitch.Client and *config.Config and has the logic to decide if the provided // PrivateMessage is a command or not and passes it on accordingly. // Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua -func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client, cfg *config.Config, uptime time.Time) { +func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) { log.Info("fn HandlePrivateMessage") // log.Info(message) @@ -28,10 +26,6 @@ func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client, // Message was sent from the Bot. Don't act on it // so that we don't repeat ourself. - botUserId := cfg.BotUserId - if message.Tags["user-id"] == botUserId { - return - } // Since our command prefix is () ignore every message // that is less than 2 @@ -40,7 +34,7 @@ func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client, // Message starts with (), pass it on to // the command handler. if message.Message[:2] == "()" { - HandleCommand(message, client, uptime) + Command(message, nb) return } } diff --git a/pkg/handlers/whisper.go b/pkg/handlers/whisper.go deleted file mode 100644 index d8e10a9..0000000 --- a/pkg/handlers/whisper.go +++ /dev/null @@ -1,14 +0,0 @@ -package handlers - -import ( - "github.com/gempir/go-twitch-irc/v2" - log "github.com/sirupsen/logrus" -) - -func HandleWhisperMessage(whisper twitch.WhisperMessage, client *twitch.Client) { - log.Info("fn HandleWhisperMessage") - log.Info(whisper) - if whisper.Message == "xd" { - client.Whisper(whisper.User.Name, "xd") - } -} diff --git a/pkg/humanize/time.go b/pkg/humanize/time.go deleted file mode 100644 index 811a4f6..0000000 --- a/pkg/humanize/time.go +++ /dev/null @@ -1,13 +0,0 @@ -package humanize - -import ( - "time" - - "github.com/dustin/go-humanize" -) - -// Time returns a more human readable -// time as a string for a given time.Time -func Time(t time.Time) string { - return humanize.Time(t) -} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go deleted file mode 100644 index bf1642d..0000000 --- a/pkg/utils/utils.go +++ /dev/null @@ -1,79 +0,0 @@ -package utils - -import ( - "fmt" - "math/rand" - "strconv" - "time" - - "github.com/gempir/go-twitch-irc/v2" -) - -var ( - tempCommands = 0 -) - -// CommandUsed is called on every command and -// Incremenents tempCommands by 1 -func CommandUsed() { - tempCommands++ -} - -// GetCommandsUsed gets tempCommands and -// returns it. Only used in ping command -func GetCommandsUsed() int { - return tempCommands -} - -// StrGenerateRandomNumber generates a random number from -// a given max value as a string -func StrGenerateRandomNumber(max string) int { - num, err := strconv.Atoi(max) - if num < 1 { - return 0 - } - - if err != nil { - fmt.Printf("Supplied value %v is not a number", num) - return 0 - } else { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(num) - } -} - -// 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) -} - -// ElevatedPrivsMessage is checking a given message twitch.PrivateMessage -// if it came from a moderator/vip/or broadcaster and returns a bool -func ElevatedPrivsMessage(message twitch.PrivateMessage) bool { - if message.User.Badges["moderator"] == 1 || - message.User.Badges["vip"] == 1 || - message.User.Badges["broadcaster"] == 1 { - return true - } else { - return false - } -} - -// ModPrivsMessage is checking a given message twitch.PrivateMessage -// if it came from a moderator or broadcaster and returns a bool -func ModPrivsMessage(message twitch.PrivateMessage) bool { - if message.User.Badges["moderator"] == 1 || - message.User.Badges["broadcaster"] == 1 { - return true - } else { - return false - } -} From cf4e4b64e4344fbe7837c4f3d998eff497abf19f Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:33:08 +0200 Subject: [PATCH 02/10] add commands --- cmd/main.go | 3 +++ pkg/handlers/command.go | 28 +++++++++++++++++++++++++++- pkg/handlers/privatemessage.go | 5 +---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 88376ec..47cabbc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -35,4 +35,7 @@ func main() { handlers.PrivateMessage(message, nb) }) + + nb.TwitchClient.Join("nourybot") + nb.TwitchClient.Connect() } diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 5e1dd1b..b891f5c 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -1,6 +1,8 @@ package handlers import ( + "strings" + "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" "github.com/sirupsen/logrus" @@ -9,6 +11,30 @@ import ( func Command(message twitch.PrivateMessage, nb *bot.Bot) { logrus.Info("fn Command") - nb.Send("nourybot", "xd") + // commandName is the actual command name without the prefix. + commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:]) + + // cmdParams are additional command inputs. + // example: + // weather san antonio + // is + // commandName cmdParams[0] cmdParams[1] + cmdParams := strings.SplitN(message.Message, " ", 500) + + // msgLen is the amount of words in the message without the prefix. + // Useful for checking if enough cmdParams are given. + msgLen := len(strings.SplitN(message.Message, " ", -2)) + + switch commandName { + case "": + if msgLen == 1 { + nb.Send(message.Channel, "xd") + } + case "echo": + if msgLen != 1 { + nb.Send(message.Channel, cmdParams[1]) + return + } + } } diff --git a/pkg/handlers/privatemessage.go b/pkg/handlers/privatemessage.go index c18cb64..81670c5 100644 --- a/pkg/handlers/privatemessage.go +++ b/pkg/handlers/privatemessage.go @@ -11,7 +11,7 @@ import ( // PrivateMessage is a command or not and passes it on accordingly. // Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) { - log.Info("fn HandlePrivateMessage") + log.Info("fn PrivateMessage") // log.Info(message) // roomId is the Twitch UserID of the channel the message @@ -24,9 +24,6 @@ func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) { return } - // Message was sent from the Bot. Don't act on it - // so that we don't repeat ourself. - // Since our command prefix is () ignore every message // that is less than 2 if len(message.Message) >= 2 { From 3f5e24f8a07dfe2e95d9a2fc44c587681343282b Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:39:22 +0200 Subject: [PATCH 03/10] add ping command --- pkg/commands/ping.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pkg/commands/ping.go diff --git a/pkg/commands/ping.go b/pkg/commands/ping.go new file mode 100644 index 0000000..2844bcd --- /dev/null +++ b/pkg/commands/ping.go @@ -0,0 +1,14 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" +) + +func Ping(target string, nb *bot.Bot) { + + reply := fmt.Sprintf("Pong! :) Last restart: %v", nb.Uptime) + + nb.Send(target, reply) +} From 1e4e56ddf69877c24d9c89ec661cb2644644c328 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:39:25 +0200 Subject: [PATCH 04/10] add ping command --- pkg/handlers/command.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index b891f5c..06e7df1 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -5,6 +5,7 @@ import ( "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/commands" "github.com/sirupsen/logrus" ) @@ -35,6 +36,8 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { nb.Send(message.Channel, cmdParams[1]) return } + case "ping": + commands.Ping(message.Channel, nb) } } From bfd206e064d7582ac8beb024b7db04388d3ffdaf Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:44:52 +0200 Subject: [PATCH 05/10] add my humanize package --- pkg/humanize/time.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pkg/humanize/time.go diff --git a/pkg/humanize/time.go b/pkg/humanize/time.go new file mode 100644 index 0000000..811a4f6 --- /dev/null +++ b/pkg/humanize/time.go @@ -0,0 +1,13 @@ +package humanize + +import ( + "time" + + "github.com/dustin/go-humanize" +) + +// Time returns a more human readable +// time as a string for a given time.Time +func Time(t time.Time) string { + return humanize.Time(t) +} From d10fa74a05785827b30bd343eeaf446f64de5dc4 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:44:56 +0200 Subject: [PATCH 06/10] add my old utils --- pkg/utils/utils.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 pkg/utils/utils.go diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go new file mode 100644 index 0000000..bf1642d --- /dev/null +++ b/pkg/utils/utils.go @@ -0,0 +1,79 @@ +package utils + +import ( + "fmt" + "math/rand" + "strconv" + "time" + + "github.com/gempir/go-twitch-irc/v2" +) + +var ( + tempCommands = 0 +) + +// CommandUsed is called on every command and +// Incremenents tempCommands by 1 +func CommandUsed() { + tempCommands++ +} + +// GetCommandsUsed gets tempCommands and +// returns it. Only used in ping command +func GetCommandsUsed() int { + return tempCommands +} + +// StrGenerateRandomNumber generates a random number from +// a given max value as a string +func StrGenerateRandomNumber(max string) int { + num, err := strconv.Atoi(max) + if num < 1 { + return 0 + } + + if err != nil { + fmt.Printf("Supplied value %v is not a number", num) + return 0 + } else { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(num) + } +} + +// 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) +} + +// ElevatedPrivsMessage is checking a given message twitch.PrivateMessage +// if it came from a moderator/vip/or broadcaster and returns a bool +func ElevatedPrivsMessage(message twitch.PrivateMessage) bool { + if message.User.Badges["moderator"] == 1 || + message.User.Badges["vip"] == 1 || + message.User.Badges["broadcaster"] == 1 { + return true + } else { + return false + } +} + +// ModPrivsMessage is checking a given message twitch.PrivateMessage +// if it came from a moderator or broadcaster and returns a bool +func ModPrivsMessage(message twitch.PrivateMessage) bool { + if message.User.Badges["moderator"] == 1 || + message.User.Badges["broadcaster"] == 1 { + return true + } else { + return false + } +} From 8c0b51894f54259c33f710990fe5e6a403c432fa Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:45:01 +0200 Subject: [PATCH 07/10] add ping command --- pkg/commands/ping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/commands/ping.go b/pkg/commands/ping.go index 2844bcd..7f3845d 100644 --- a/pkg/commands/ping.go +++ b/pkg/commands/ping.go @@ -4,11 +4,15 @@ import ( "fmt" "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/humanize" + "github.com/lyx0/nourybot/pkg/utils" ) func Ping(target string, nb *bot.Bot) { + commandCount := fmt.Sprint(utils.GetCommandsUsed()) + botUptime := humanize.Time(nb.Uptime) - reply := fmt.Sprintf("Pong! :) Last restart: %v", nb.Uptime) + reply := fmt.Sprintf("Pong! :) Commands Used: %v, Last restart: %v", commandCount, botUptime) nb.Send(target, reply) } From 88aa450b47852f96e3c062bdcb91701d3396297b Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 22:58:09 +0200 Subject: [PATCH 08/10] add a bunch of commands --- pkg/api/aiden/aiden.go | 30 ++++++++++++++++++++++++++++++ pkg/api/randomxkcd.go | 35 +++++++++++++++++++++++++++++++++++ pkg/api/xkcd.go | 27 +++++++++++++++++++++++++++ pkg/commands/randomxkcd.go | 11 +++++++++++ pkg/commands/weather.go | 20 ++++++++++++++++++++ pkg/commands/xkcd.go | 13 +++++++++++++ pkg/handlers/command.go | 16 ++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 pkg/api/aiden/aiden.go create mode 100644 pkg/api/randomxkcd.go create mode 100644 pkg/api/xkcd.go create mode 100644 pkg/commands/randomxkcd.go create mode 100644 pkg/commands/weather.go create mode 100644 pkg/commands/xkcd.go diff --git a/pkg/api/aiden/aiden.go b/pkg/api/aiden/aiden.go new file mode 100644 index 0000000..497f46e --- /dev/null +++ b/pkg/api/aiden/aiden.go @@ -0,0 +1,30 @@ +package aiden + +import ( + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +var ( + basePath = "https://customapi.aidenwallis.co.uk/" +) + +func ApiCall(uri string) (string, error) { + resp, err := http.Get(fmt.Sprint(basePath + uri)) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan", err + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan", err + } + return string(body), nil +} diff --git a/pkg/api/randomxkcd.go b/pkg/api/randomxkcd.go new file mode 100644 index 0000000..0384758 --- /dev/null +++ b/pkg/api/randomxkcd.go @@ -0,0 +1,35 @@ +package api + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + "github.com/lyx0/nourybot/pkg/utils" + log "github.com/sirupsen/logrus" +) + +type XkcdResponse struct { + Num int `json:"num"` + SafeTitle string `json:"safe_title"` + Img string `json:"img"` +} + +func RandomXkcd() string { + comicNum := fmt.Sprint(utils.GenerateRandomNumber(2468)) + response, err := http.Get(fmt.Sprint("http://xkcd.com/" + comicNum + "/info.0.json")) + if err != nil { + log.Error(err) + } + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + var responseObject XkcdResponse + json.Unmarshal(responseData, &responseObject) + + reply := fmt.Sprint("Random Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img) + + return reply +} diff --git a/pkg/api/xkcd.go b/pkg/api/xkcd.go new file mode 100644 index 0000000..6a3776d --- /dev/null +++ b/pkg/api/xkcd.go @@ -0,0 +1,27 @@ +package api + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +func Xkcd() string { + response, err := http.Get("https://xkcd.com/info.0.json") + if err != nil { + log.Error(err) + } + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + var responseObject XkcdResponse + json.Unmarshal(responseData, &responseObject) + + reply := fmt.Sprint("Current Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img) + + return reply +} diff --git a/pkg/commands/randomxkcd.go b/pkg/commands/randomxkcd.go new file mode 100644 index 0000000..23573dc --- /dev/null +++ b/pkg/commands/randomxkcd.go @@ -0,0 +1,11 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomXkcd(channel string, nb *bot.Bot) { + reply := api.RandomXkcd() + nb.Send(channel, reply) +} diff --git a/pkg/commands/weather.go b/pkg/commands/weather.go new file mode 100644 index 0000000..1f0ad1f --- /dev/null +++ b/pkg/commands/weather.go @@ -0,0 +1,20 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func Weather(channel string, location string, nb *bot.Bot) { + + reply, err := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location)) + if err != nil { + nb.Send(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + nb.Send(channel, reply) + +} diff --git a/pkg/commands/xkcd.go b/pkg/commands/xkcd.go new file mode 100644 index 0000000..1768851 --- /dev/null +++ b/pkg/commands/xkcd.go @@ -0,0 +1,13 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func Xkcd(channel string, nb *bot.Bot) { + reply := api.Xkcd() + + nb.Send(channel, reply) + +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 06e7df1..c7c39a6 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -36,8 +36,24 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { nb.Send(message.Channel, cmdParams[1]) return } + case "randomxkcd": + commands.RandomXkcd(message.Channel, nb) + return case "ping": commands.Ping(message.Channel, nb) + return + + case "weather": + if msgLen == 1 { + nb.Send(message.Channel, "Usage: ()weather [location]") + return + } else { + commands.Weather(message.Channel, message.Message[9:len(message.Message)], nb) + return + } + case "xkcd": + commands.Xkcd(message.Channel, nb) + return } } From 7bc69ff5e065e83b7e346e60c310cb9c36291eff Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 23:27:55 +0200 Subject: [PATCH 09/10] add more commands --- cmd/main.go | 3 +- pkg/api/ivr/firstline.go | 47 ++++++++++++++++++ pkg/api/ivr/followage.go | 47 ++++++++++++++++++ pkg/commands/botstatus.go | 19 ++++++++ pkg/commands/bttvemotes.go | 19 ++++++++ pkg/commands/coinflip.go | 16 +++++++ pkg/commands/color.go | 15 ++++++ pkg/commands/echo.go | 7 +++ pkg/commands/eightball.go | 17 +++++++ pkg/commands/ffzemotes.go | 20 ++++++++ pkg/commands/fill.go | 25 ++++++++++ pkg/commands/firstline.go | 17 +++++++ pkg/commands/followage.go | 16 +++++++ pkg/commands/game.go | 20 ++++++++ pkg/handlers/command.go | 98 ++++++++++++++++++++++++++++++++++---- 15 files changed, 376 insertions(+), 10 deletions(-) create mode 100644 pkg/api/ivr/firstline.go create mode 100644 pkg/api/ivr/followage.go create mode 100644 pkg/commands/botstatus.go create mode 100644 pkg/commands/bttvemotes.go create mode 100644 pkg/commands/coinflip.go create mode 100644 pkg/commands/color.go create mode 100644 pkg/commands/echo.go create mode 100644 pkg/commands/eightball.go create mode 100644 pkg/commands/ffzemotes.go create mode 100644 pkg/commands/fill.go create mode 100644 pkg/commands/firstline.go create mode 100644 pkg/commands/followage.go create mode 100644 pkg/commands/game.go diff --git a/cmd/main.go b/cmd/main.go index 47cabbc..4839b99 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -36,6 +36,7 @@ func main() { handlers.PrivateMessage(message, nb) }) - nb.TwitchClient.Join("nourybot") + nb.TwitchClient.Join("nouryqt", "nourybot") + nb.Send("nourybot", "HeyGuys") nb.TwitchClient.Connect() } diff --git a/pkg/api/ivr/firstline.go b/pkg/api/ivr/firstline.go new file mode 100644 index 0000000..3f2ae15 --- /dev/null +++ b/pkg/api/ivr/firstline.go @@ -0,0 +1,47 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type firstLineApiResponse struct { + User string `json:"user"` + Message string `json:"message"` + Time string `json:"time"` + Error string `json:"error"` +} + +var ( + firstLineBaseUrl = "https://api.ivr.fi/logs/firstmessage" +) + +func FirstLine(streamer string, username string) (string, error) { + resp, err := http.Get(fmt.Sprintf("%s/%s/%s", firstLineBaseUrl, streamer, username)) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan", err + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + } + + var responseObject firstLineApiResponse + json.Unmarshal(body, &responseObject) + + // User or channel was not found + if responseObject.Error != "" { + return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil + } else { + return fmt.Sprintf(username + ": " + responseObject.Message + " (" + responseObject.Time + " ago)."), nil + } + +} diff --git a/pkg/api/ivr/followage.go b/pkg/api/ivr/followage.go new file mode 100644 index 0000000..2ab1ea9 --- /dev/null +++ b/pkg/api/ivr/followage.go @@ -0,0 +1,47 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +// https://api.ivr.fi +type followageApiResponse struct { + User string `json:"user"` + UserID string `json:"userid"` + Channel string `json:"channel"` + ChannelId string `json:"channelid"` + FollowedAt string `json:"followedAt"` + Error string `json:"error"` +} + +func Followage(streamer string, username string) (string, error) { + resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/subage/%s/%s", username, streamer)) + if err != nil { + log.Error(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + } + + var responseObject followageApiResponse + json.Unmarshal(body, &responseObject) + + // User or channel was not found + if responseObject.Error != "" { + return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil + } else if responseObject.FollowedAt == "" { + return fmt.Sprintf(username + " is not following " + streamer), nil + } else { + d := responseObject.FollowedAt[:10] + return fmt.Sprintf(username + " has been following " + streamer + " since " + d + "."), nil + } +} diff --git a/pkg/commands/botstatus.go b/pkg/commands/botstatus.go new file mode 100644 index 0000000..2660eec --- /dev/null +++ b/pkg/commands/botstatus.go @@ -0,0 +1,19 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func BotStatus(channel string, name string, nb *bot.Bot) { + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/botStatus/%s?includeLimits=1", name)) + if err != nil { + nb.Send(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + + nb.Send(channel, resp) +} diff --git a/pkg/commands/bttvemotes.go b/pkg/commands/bttvemotes.go new file mode 100644 index 0000000..94b1d93 --- /dev/null +++ b/pkg/commands/bttvemotes.go @@ -0,0 +1,19 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func BttvEmotes(channel string, nb *bot.Bot) { + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/bttv", channel)) + if err != nil { + log.Error(err) + nb.Send(channel, "Something went wrong FeelsBadMan") + } + + nb.Send(channel, string(resp)) +} diff --git a/pkg/commands/coinflip.go b/pkg/commands/coinflip.go new file mode 100644 index 0000000..63c8aca --- /dev/null +++ b/pkg/commands/coinflip.go @@ -0,0 +1,16 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/utils" +) + +func Coinflip(channel string, nb *bot.Bot) { + result := utils.GenerateRandomNumber(2) + + if result == 1 { + nb.Send(channel, "Heads") + } else { + nb.Send(channel, "Tails") + } +} diff --git a/pkg/commands/color.go b/pkg/commands/color.go new file mode 100644 index 0000000..155acd6 --- /dev/null +++ b/pkg/commands/color.go @@ -0,0 +1,15 @@ +package commands + +import ( + "fmt" + + "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/cmd/bot" +) + +func Color(message twitch.PrivateMessage, nb *bot.Bot) { + reply := fmt.Sprintf("@%v, your color is %v", message.User.DisplayName, message.User.Color) + + nb.Send(message.Channel, reply) + +} diff --git a/pkg/commands/echo.go b/pkg/commands/echo.go new file mode 100644 index 0000000..ddd9917 --- /dev/null +++ b/pkg/commands/echo.go @@ -0,0 +1,7 @@ +package commands + +import "github.com/lyx0/nourybot/cmd/bot" + +func Echo(channel string, message string, nb *bot.Bot) { + nb.Send(channel, message) +} diff --git a/pkg/commands/eightball.go b/pkg/commands/eightball.go new file mode 100644 index 0000000..751d979 --- /dev/null +++ b/pkg/commands/eightball.go @@ -0,0 +1,17 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func EightBall(channel string, nb *bot.Bot) { + resp, err := aiden.ApiCall("api/v1/misc/8ball") + if err != nil { + log.Error(err) + nb.Send(channel, "Something went wrong FeelsBadMan") + } + + nb.Send(channel, string(resp)) +} diff --git a/pkg/commands/ffzemotes.go b/pkg/commands/ffzemotes.go new file mode 100644 index 0000000..14f1e7d --- /dev/null +++ b/pkg/commands/ffzemotes.go @@ -0,0 +1,20 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func FfzEmotes(channel string, nb *bot.Bot) { + + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/ffz", channel)) + if err != nil { + log.Error(err) + nb.Send(channel, "Something went wrong FeelsBadMan") + } + + nb.Send(channel, string(resp)) +} diff --git a/pkg/commands/fill.go b/pkg/commands/fill.go new file mode 100644 index 0000000..36b2663 --- /dev/null +++ b/pkg/commands/fill.go @@ -0,0 +1,25 @@ +package commands + +import ( + "fmt" + "strings" + + "github.com/lyx0/nourybot/cmd/bot" +) + +func Fill(channel string, emote string, nb *bot.Bot) { + if emote[0] == '.' || emote[0] == '/' { + nb.Send(channel, ":tf:") + return + } + + // Get the length of the emote + emoteLength := (len(emote) + 1) + + // Check how often the emote fits into a single message + repeatCount := (499 / emoteLength) + + reply := strings.Repeat(fmt.Sprintf(emote+" "), repeatCount) + nb.Send(channel, reply) + +} diff --git a/pkg/commands/firstline.go b/pkg/commands/firstline.go new file mode 100644 index 0000000..eed2fe7 --- /dev/null +++ b/pkg/commands/firstline.go @@ -0,0 +1,17 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/ivr" +) + +func Firstline(channel string, streamer string, username string, nb *bot.Bot) { + ivrResponse, err := ivr.FirstLine(streamer, username) + if err != nil { + nb.Send(channel, fmt.Sprint(err)) + return + } + nb.Send(channel, ivrResponse) +} diff --git a/pkg/commands/followage.go b/pkg/commands/followage.go new file mode 100644 index 0000000..b7eb00b --- /dev/null +++ b/pkg/commands/followage.go @@ -0,0 +1,16 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/ivr" +) + +func Followage(channel string, streamer string, username string, nb *bot.Bot) { + ivrResponse, err := ivr.Followage(streamer, username) + if err != nil { + nb.Send(channel, fmt.Sprint(err)) + } + nb.Send(channel, ivrResponse) +} diff --git a/pkg/commands/game.go b/pkg/commands/game.go new file mode 100644 index 0000000..cfbd60d --- /dev/null +++ b/pkg/commands/game.go @@ -0,0 +1,20 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func Game(channel string, name string, nb *bot.Bot) { + + game, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/game", name)) + if err != nil { + nb.Send(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + reply := fmt.Sprintf("@%s was last seen playing: %s", name, game) + nb.Send(channel, reply) +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index c7c39a6..fcb2ab4 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -26,33 +26,113 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { // Useful for checking if enough cmdParams are given. msgLen := len(strings.SplitN(message.Message, " ", -2)) + // target channel + target := message.Channel + switch commandName { case "": if msgLen == 1 { - nb.Send(message.Channel, "xd") + nb.Send(target, "xd") } - case "echo": - if msgLen != 1 { - nb.Send(message.Channel, cmdParams[1]) + case "botstatus": + if msgLen == 1 { + nb.Send(target, "Usage: ()botstatus [username]") + return + } else { + commands.BotStatus(target, cmdParams[1], nb) return } + case "bttvemotes": + commands.BttvEmotes(target, nb) + return + case "cf": + commands.Coinflip(target, nb) + return + case "coin": + commands.Coinflip(target, nb) + return + case "coinflip": + commands.Coinflip(target, nb) + return + case "color": + commands.Color(message, nb) + return + case "mycolor": + commands.Color(message, nb) + return + case "echo": + commands.Echo(target, message.Message[7:len(message.Message)], nb) + return + case "8ball": + commands.EightBall(target, nb) + return + case "ffzemotes": + commands.FfzEmotes(target, nb) + return + + case "fill": + if msgLen == 1 { + nb.Send(target, "Usage: ()fill [emote]") + return + } else { + commands.Fill(target, message.Message[7:len(message.Message)], nb) + return + } + case "firstline": + if msgLen == 1 { + nb.Send(target, "Usage: ()firstline [channel] [user]") + return + } else if msgLen == 2 { + commands.Firstline(target, message.Channel, cmdParams[1], nb) + return + } else { + commands.Firstline(target, cmdParams[1], cmdParams[2], nb) + return + } + case "fl": + if msgLen == 1 { + nb.Send(target, "Usage: ()firstline [channel] [user]") + return + } else if msgLen == 2 { + commands.Firstline(target, message.Channel, cmdParams[1], nb) + return + } else { + commands.Firstline(target, cmdParams[1], cmdParams[2], nb) + return + } + case "followage": + if msgLen <= 2 { + nb.Send(target, "Usage: ()followage [channel] [user]") + return + } else { + commands.Followage(target, cmdParams[1], cmdParams[2], nb) + return + } + case "game": + if msgLen == 1 { + nb.Send(target, "Usage: ()game [channel]") + return + } else { + commands.Game(target, cmdParams[1], nb) + } + case "randomxkcd": - commands.RandomXkcd(message.Channel, nb) + commands.RandomXkcd(target, nb) return case "ping": - commands.Ping(message.Channel, nb) + commands.Ping(target, nb) return case "weather": if msgLen == 1 { - nb.Send(message.Channel, "Usage: ()weather [location]") + nb.Send(target, "Usage: ()weather [location]") return } else { - commands.Weather(message.Channel, message.Message[9:len(message.Message)], nb) + commands.Weather(target, message.Message[9:len(message.Message)], nb) return } case "xkcd": - commands.Xkcd(message.Channel, nb) + commands.Xkcd(target, nb) return } From 4e6451462d87202aa24bf6c5cc32c79af7f0acd7 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Tue, 19 Oct 2021 23:53:41 +0200 Subject: [PATCH 10/10] add commands --- pkg/api/ivr/profilepicture.go | 44 ++++++++++ pkg/api/ivr/subage.go | 70 ++++++++++++++++ pkg/api/ivr/userid.go | 40 ++++++++++ pkg/api/numbersapi.go | 34 ++++++++ pkg/api/randomcat.go | 30 +++++++ pkg/api/randomdog.go | 30 +++++++ pkg/api/randomfox.go | 31 ++++++++ pkg/commands/godocs.go | 13 +++ pkg/commands/number.go | 16 ++++ pkg/commands/pingme.go | 13 +++ pkg/commands/profilepicture.go | 18 +++++ pkg/commands/pyramid.go | 49 ++++++++++++ pkg/commands/randomcat.go | 12 +++ pkg/commands/randomdog.go | 12 +++ pkg/commands/randomfox.go | 12 +++ pkg/commands/subage.go | 18 +++++ pkg/commands/thumbnail.go | 16 ++++ pkg/commands/title.go | 19 +++++ pkg/commands/uptime.go | 21 +++++ pkg/commands/userid.go | 11 +++ pkg/commands/xd.go | 7 ++ pkg/handlers/command.go | 141 +++++++++++++++++++++++++++++++-- 22 files changed, 651 insertions(+), 6 deletions(-) create mode 100644 pkg/api/ivr/profilepicture.go create mode 100644 pkg/api/ivr/subage.go create mode 100644 pkg/api/ivr/userid.go create mode 100644 pkg/api/numbersapi.go create mode 100644 pkg/api/randomcat.go create mode 100644 pkg/api/randomdog.go create mode 100644 pkg/api/randomfox.go create mode 100644 pkg/commands/godocs.go create mode 100644 pkg/commands/number.go create mode 100644 pkg/commands/pingme.go create mode 100644 pkg/commands/profilepicture.go create mode 100644 pkg/commands/pyramid.go create mode 100644 pkg/commands/randomcat.go create mode 100644 pkg/commands/randomdog.go create mode 100644 pkg/commands/randomfox.go create mode 100644 pkg/commands/subage.go create mode 100644 pkg/commands/thumbnail.go create mode 100644 pkg/commands/title.go create mode 100644 pkg/commands/uptime.go create mode 100644 pkg/commands/userid.go create mode 100644 pkg/commands/xd.go diff --git a/pkg/api/ivr/profilepicture.go b/pkg/api/ivr/profilepicture.go new file mode 100644 index 0000000..5494996 --- /dev/null +++ b/pkg/api/ivr/profilepicture.go @@ -0,0 +1,44 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +// https://api.ivr.fi +type pfpApiResponse struct { + Logo string `json:"logo"` + Error string `json:"error"` +} + +var ( + baseUrl = "https://api.ivr.fi/twitch/resolve" +) + +func ProfilePicture(username string) (string, error) { + resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, username)) + if err != nil { + log.Error(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + } + + var responseObject pfpApiResponse + json.Unmarshal(body, &responseObject) + + // User not found + if responseObject.Error != "" { + return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil + } else { + return fmt.Sprintf(responseObject.Logo), nil + } +} diff --git a/pkg/api/ivr/subage.go b/pkg/api/ivr/subage.go new file mode 100644 index 0000000..1c03781 --- /dev/null +++ b/pkg/api/ivr/subage.go @@ -0,0 +1,70 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type subageApiResponse struct { + User string `json:"user"` + UserID string `json:"userId"` + Channel string `json:"channel"` + ChannelId string `json:"channelid"` + SubageHidden bool `json:"hidden"` + Subscribed bool `json:"subscribed"` + FollowedAt string `json:"followedAt"` + Cumulative cumulative `json:"cumulative"` + Streak subStreak `json:"streak"` + Error string `json:"error"` +} + +type cumulative struct { + Months int `json:"months"` +} + +type subStreak struct { + Months int `json:"months"` +} + +var ( + subageBaseUrl = "https://api.ivr.fi/twitch/subage" +) + +func Subage(username string, streamer string) (string, error) { + resp, err := http.Get(fmt.Sprintf("%s/%s/%s", subageBaseUrl, username, streamer)) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan", err + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + } + + var responseObject subageApiResponse + json.Unmarshal(body, &responseObject) + + // User or channel was not found + if responseObject.Error != "" { + reply := fmt.Sprintf(responseObject.Error + " FeelsBadMan") + // client.Say(channel, fmt.Sprintf(responseObject.Error+" FeelsBadMan")) + return reply, nil + } + + if responseObject.SubageHidden { + + reply := fmt.Sprintf(username + " has their subscription status hidden. FeelsBadMan") + return reply, nil + } else { + months := fmt.Sprint(responseObject.Cumulative.Months) + reply := fmt.Sprintf(username + " has been subscribed to " + streamer + " for " + months + " months.") + return reply, nil + } +} diff --git a/pkg/api/ivr/userid.go b/pkg/api/ivr/userid.go new file mode 100644 index 0000000..80c8e7c --- /dev/null +++ b/pkg/api/ivr/userid.go @@ -0,0 +1,40 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +// https://api.ivr.fi +type uidApiResponse struct { + Id string `json:"id"` + Error string `json:"error"` +} + +func Userid(username string) string { + resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/resolve/%s", username)) + if err != nil { + log.Error(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + } + + var responseObject uidApiResponse + json.Unmarshal(body, &responseObject) + + // User not found + if responseObject.Error != "" { + return fmt.Sprintf(responseObject.Error + " FeelsBadMan") + } else { + return fmt.Sprintf(responseObject.Id) + } +} diff --git a/pkg/api/numbersapi.go b/pkg/api/numbersapi.go new file mode 100644 index 0000000..e1d4799 --- /dev/null +++ b/pkg/api/numbersapi.go @@ -0,0 +1,34 @@ +package api + +import ( + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +func RandomNumber() string { + response, err := http.Get("http://numbersapi.com/random/trivia") + if err != nil { + log.Error(err) + } + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + + return string(responseData) +} + +func Number(number string) string { + response, err := http.Get(fmt.Sprint("http://numbersapi.com/" + string(number))) + if err != nil { + log.Error(err) + } + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + return string(responseData) +} diff --git a/pkg/api/randomcat.go b/pkg/api/randomcat.go new file mode 100644 index 0000000..efede29 --- /dev/null +++ b/pkg/api/randomcat.go @@ -0,0 +1,30 @@ +package api + +import ( + "encoding/json" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type randomCatResponse struct { + File string `json:"file"` +} + +func RandomCat() string { + response, err := http.Get("https://aws.random.cat/meow") + if err != nil { + log.Error(err) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + + var responseObject randomCatResponse + json.Unmarshal(responseData, &responseObject) + + return string(responseObject.File) +} diff --git a/pkg/api/randomdog.go b/pkg/api/randomdog.go new file mode 100644 index 0000000..7b17af5 --- /dev/null +++ b/pkg/api/randomdog.go @@ -0,0 +1,30 @@ +package api + +import ( + "encoding/json" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type randomDogResponse struct { + Url string `json:"url"` +} + +func RandomDog() string { + response, err := http.Get("https://random.dog/woof.json") + if err != nil { + log.Error(err) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + + var responseObject randomDogResponse + json.Unmarshal(responseData, &responseObject) + + return string(responseObject.Url) +} diff --git a/pkg/api/randomfox.go b/pkg/api/randomfox.go new file mode 100644 index 0000000..6a4bfc5 --- /dev/null +++ b/pkg/api/randomfox.go @@ -0,0 +1,31 @@ +package api + +import ( + "encoding/json" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type randomFoxResponse struct { + Image string `json:"image"` + Link string `json:"link"` +} + +func RandomFox() string { + response, err := http.Get("https://randomfox.ca/floof/") + if err != nil { + log.Error(err) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + + var responseObject randomFoxResponse + json.Unmarshal(responseData, &responseObject) + + return string(responseObject.Image) +} diff --git a/pkg/commands/godocs.go b/pkg/commands/godocs.go new file mode 100644 index 0000000..9a92097 --- /dev/null +++ b/pkg/commands/godocs.go @@ -0,0 +1,13 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" +) + +func Godocs(channel string, searchTerm string, nb *bot.Bot) { + resp := fmt.Sprintf("https://godocs.io/?q=%s", searchTerm) + + nb.Send(channel, resp) +} diff --git a/pkg/commands/number.go b/pkg/commands/number.go new file mode 100644 index 0000000..bd3c0cf --- /dev/null +++ b/pkg/commands/number.go @@ -0,0 +1,16 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomNumber(channel string, nb *bot.Bot) { + reply := api.RandomNumber() + nb.Send(channel, string(reply)) +} + +func Number(channel string, number string, nb *bot.Bot) { + reply := api.Number(number) + nb.Send(channel, string(reply)) +} diff --git a/pkg/commands/pingme.go b/pkg/commands/pingme.go new file mode 100644 index 0000000..d118c93 --- /dev/null +++ b/pkg/commands/pingme.go @@ -0,0 +1,13 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" +) + +func Pingme(channel string, user string, nb *bot.Bot) { + response := fmt.Sprintf("@%s", user) + + nb.Send(channel, response) +} diff --git a/pkg/commands/profilepicture.go b/pkg/commands/profilepicture.go new file mode 100644 index 0000000..8146b7c --- /dev/null +++ b/pkg/commands/profilepicture.go @@ -0,0 +1,18 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/ivr" +) + +func ProfilePicture(channel string, target string, nb *bot.Bot) { + reply, err := ivr.ProfilePicture(target) + if err != nil { + nb.Send(channel, fmt.Sprint(err)) + return + } + + nb.Send(channel, reply) +} diff --git a/pkg/commands/pyramid.go b/pkg/commands/pyramid.go new file mode 100644 index 0000000..3291f13 --- /dev/null +++ b/pkg/commands/pyramid.go @@ -0,0 +1,49 @@ +package commands + +import ( + "fmt" + "strconv" + "strings" + + "github.com/lyx0/nourybot/cmd/bot" +) + +func Pyramid(channel string, size string, emote string, nb *bot.Bot) { + if size[0] == '.' || size[0] == '/' { + nb.Send(channel, ":tf:") + return + } + + if emote[0] == '.' || emote[0] == '/' { + nb.Send(channel, ":tf:") + return + } + + pyramidSize, err := strconv.Atoi(size) + pyramidEmote := fmt.Sprint(emote + " ") + + if err != nil { + nb.Send(channel, "Something went wrong") + } + + if pyramidSize == 1 { + nb.Send(channel, fmt.Sprint(pyramidEmote+"...")) + return + } + + if pyramidSize > 20 { + nb.Send(channel, "Max pyramid size is 20") + return + } + + for i := 0; i <= pyramidSize; i++ { + pyramidMessageAsc := strings.Repeat(pyramidEmote, i) + // fmt.Println(pyramidMessageAsc) + nb.Send(channel, pyramidMessageAsc) + } + for j := pyramidSize - 1; j >= 0; j-- { + pyramidMessageDesc := strings.Repeat(pyramidEmote, j) + // fmt.Println(pyramidMessageDesc) + nb.Send(channel, pyramidMessageDesc) + } +} diff --git a/pkg/commands/randomcat.go b/pkg/commands/randomcat.go new file mode 100644 index 0000000..34dae05 --- /dev/null +++ b/pkg/commands/randomcat.go @@ -0,0 +1,12 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomCat(channel string, nb *bot.Bot) { + reply := api.RandomCat() + + nb.Send(channel, reply) +} diff --git a/pkg/commands/randomdog.go b/pkg/commands/randomdog.go new file mode 100644 index 0000000..5555dba --- /dev/null +++ b/pkg/commands/randomdog.go @@ -0,0 +1,12 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomDog(channel string, nb *bot.Bot) { + reply := api.RandomDog() + + nb.Send(channel, reply) +} diff --git a/pkg/commands/randomfox.go b/pkg/commands/randomfox.go new file mode 100644 index 0000000..d9b3744 --- /dev/null +++ b/pkg/commands/randomfox.go @@ -0,0 +1,12 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomFox(channel string, nb *bot.Bot) { + reply := api.RandomFox() + + nb.Send(channel, reply) +} diff --git a/pkg/commands/subage.go b/pkg/commands/subage.go new file mode 100644 index 0000000..70a0988 --- /dev/null +++ b/pkg/commands/subage.go @@ -0,0 +1,18 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/ivr" +) + +func Subage(channel string, username string, streamer string, nb *bot.Bot) { + + ivrResponse, err := ivr.Subage(username, streamer) + if err != nil { + nb.Send(channel, fmt.Sprint(err)) + return + } + nb.Send(channel, ivrResponse) +} diff --git a/pkg/commands/thumbnail.go b/pkg/commands/thumbnail.go new file mode 100644 index 0000000..ab19f95 --- /dev/null +++ b/pkg/commands/thumbnail.go @@ -0,0 +1,16 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/utils" +) + +func Thumbnail(channel string, target string, nb *bot.Bot) { + imageHeight := utils.GenerateRandomNumberRange(1040, 1080) + imageWidth := utils.GenerateRandomNumberRange(1890, 1920) + response := fmt.Sprintf("https://static-cdn.jtvnw.net/previews-ttv/live_user_%v-%vx%v.jpg", target, imageWidth, imageHeight) + + nb.Send(channel, response) +} diff --git a/pkg/commands/title.go b/pkg/commands/title.go new file mode 100644 index 0000000..076629b --- /dev/null +++ b/pkg/commands/title.go @@ -0,0 +1,19 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func Title(channel string, target string, nb *bot.Bot) { + title, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/title", target)) + if err != nil { + nb.Send(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + reply := fmt.Sprintf("%s title is: %s", target, title) + nb.Send(channel, reply) +} diff --git a/pkg/commands/uptime.go b/pkg/commands/uptime.go new file mode 100644 index 0000000..af97c0c --- /dev/null +++ b/pkg/commands/uptime.go @@ -0,0 +1,21 @@ +package commands + +import ( + "fmt" + + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/aiden" + log "github.com/sirupsen/logrus" +) + +func Uptime(channel string, name string, nb *bot.Bot) { + + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/uptime", name)) + if err != nil { + nb.Send(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + + nb.Send(channel, resp) + +} diff --git a/pkg/commands/userid.go b/pkg/commands/userid.go new file mode 100644 index 0000000..bdc9897 --- /dev/null +++ b/pkg/commands/userid.go @@ -0,0 +1,11 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api/ivr" +) + +func Userid(channel string, target string, nb *bot.Bot) { + reply := ivr.Userid(target) + nb.Send(channel, reply) +} diff --git a/pkg/commands/xd.go b/pkg/commands/xd.go new file mode 100644 index 0000000..d5c7c49 --- /dev/null +++ b/pkg/commands/xd.go @@ -0,0 +1,7 @@ +package commands + +import "github.com/lyx0/nourybot/cmd/bot" + +func Xd(channel string, nb *bot.Bot) { + nb.Send(channel, "xd") +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index fcb2ab4..7b9754a 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -6,6 +6,7 @@ import ( "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" "github.com/lyx0/nourybot/pkg/commands" + "github.com/lyx0/nourybot/pkg/utils" "github.com/sirupsen/logrus" ) @@ -83,7 +84,7 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { nb.Send(target, "Usage: ()firstline [channel] [user]") return } else if msgLen == 2 { - commands.Firstline(target, message.Channel, cmdParams[1], nb) + commands.Firstline(target, target, cmdParams[1], nb) return } else { commands.Firstline(target, cmdParams[1], cmdParams[2], nb) @@ -94,7 +95,7 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { nb.Send(target, "Usage: ()firstline [channel] [user]") return } else if msgLen == 2 { - commands.Firstline(target, message.Channel, cmdParams[1], nb) + commands.Firstline(target, target, cmdParams[1], nb) return } else { commands.Firstline(target, cmdParams[1], cmdParams[2], nb) @@ -115,13 +116,139 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { } else { commands.Game(target, cmdParams[1], nb) } - - case "randomxkcd": - commands.RandomXkcd(target, nb) - return + case "godoc": + if msgLen == 1 { + nb.Send(target, "Usage: ()godoc [term]") + return + } else { + commands.Godocs(target, message.Message[8:len(message.Message)], nb) + return + } + case "godocs": + if msgLen == 1 { + nb.Send(target, "Usage: ()godoc [term]") + return + } else { + commands.Godocs(target, message.Message[9:len(message.Message)], nb) + return + } + case "num": + if msgLen == 1 { + commands.RandomNumber(target, nb) + } else { + commands.Number(target, cmdParams[1], nb) + } + case "number": + if msgLen == 1 { + commands.RandomNumber(target, nb) + } else { + commands.Number(target, cmdParams[1], nb) + } case "ping": commands.Ping(target, nb) return + case "pingme": + commands.Pingme(target, message.User.DisplayName, nb) + return + case "preview": + if msgLen == 1 { + nb.Send(target, "Usage: ()preview [channel]") + return + } else { + commands.Thumbnail(target, cmdParams[1], nb) + return + } + case "profilepicture": + if msgLen == 1 { + nb.Send(target, "Usage: ()profilepicture [user]") + return + } + commands.ProfilePicture(target, cmdParams[1], nb) + return + case "pfp": + if msgLen == 1 { + nb.Send(target, "Usage: ()pfp [user]") + return + } + commands.ProfilePicture(target, cmdParams[1], nb) + return + + case "pyramid": + if msgLen != 3 { + nb.Send(target, "Usage: ()pyramid [size] [emote]") + } else if utils.ElevatedPrivsMessage(message) { + commands.Pyramid(target, cmdParams[1], cmdParams[2], nb) + } else { + nb.Send(target, "Pleb's can't pyramid FeelsBadMan") + } + case "randomcat": + commands.RandomCat(target, nb) + return + case "randomdog": + commands.RandomDog(target, nb) + return + case "randomfox": + commands.RandomFox(target, nb) + return + case "randomxkcd": + commands.RandomXkcd(target, nb) + return + case "subage": + if msgLen < 3 { + nb.Send(target, "Usage: ()subage [user] [streamer]") + return + } else { + commands.Subage(target, cmdParams[1], cmdParams[2], nb) + return + } + case "thumb": + if msgLen == 1 { + nb.Send(target, "Usage: ()thumbnail [channel]") + return + } else { + commands.Thumbnail(target, cmdParams[1], nb) + return + } + case "thumbnail": + if msgLen == 1 { + nb.Send(target, "Usage: ()thumbnail [channel]") + return + } else { + commands.Thumbnail(target, cmdParams[1], nb) + return + } + case "title": + if msgLen == 1 { + commands.Title(target, target, nb) + return + } else { + commands.Title(target, cmdParams[1], nb) + return + } + case "uptime": + if msgLen == 1 { + commands.Uptime(target, target, nb) + return + } else { + commands.Uptime(target, cmdParams[1], nb) + return + } + case "uid": + if msgLen == 1 { + nb.Send(target, "Usage: ()uid [username]") + return + } else { + commands.Userid(target, cmdParams[1], nb) + return + } + case "userid": + if msgLen == 1 { + nb.Send(target, "Usage: ()userid [username]") + return + } else { + commands.Userid(target, cmdParams[1], nb) + return + } case "weather": if msgLen == 1 { @@ -131,6 +258,8 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { commands.Weather(target, message.Message[9:len(message.Message)], nb) return } + case "xd": + commands.Xd(target, nb) case "xkcd": commands.Xkcd(target, nb) return