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