add more commands

This commit is contained in:
lyx0 2021-10-19 23:27:55 +02:00
parent 88aa450b47
commit 7bc69ff5e0
15 changed files with 376 additions and 10 deletions

View file

@ -36,6 +36,7 @@ func main() {
handlers.PrivateMessage(message, nb) handlers.PrivateMessage(message, nb)
}) })
nb.TwitchClient.Join("nourybot") nb.TwitchClient.Join("nouryqt", "nourybot")
nb.Send("nourybot", "HeyGuys")
nb.TwitchClient.Connect() nb.TwitchClient.Connect()
} }

47
pkg/api/ivr/firstline.go Normal file
View file

@ -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
}
}

47
pkg/api/ivr/followage.go Normal file
View file

@ -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
}
}

19
pkg/commands/botstatus.go Normal file
View file

@ -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)
}

View file

@ -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))
}

16
pkg/commands/coinflip.go Normal file
View file

@ -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")
}
}

15
pkg/commands/color.go Normal file
View file

@ -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)
}

7
pkg/commands/echo.go Normal file
View file

@ -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)
}

17
pkg/commands/eightball.go Normal file
View file

@ -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))
}

20
pkg/commands/ffzemotes.go Normal file
View file

@ -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))
}

25
pkg/commands/fill.go Normal file
View file

@ -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)
}

17
pkg/commands/firstline.go Normal file
View file

@ -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)
}

16
pkg/commands/followage.go Normal file
View file

@ -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)
}

20
pkg/commands/game.go Normal file
View file

@ -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)
}

View file

@ -26,33 +26,113 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
// Useful for checking if enough cmdParams are given. // Useful for checking if enough cmdParams are given.
msgLen := len(strings.SplitN(message.Message, " ", -2)) msgLen := len(strings.SplitN(message.Message, " ", -2))
// target channel
target := message.Channel
switch commandName { switch commandName {
case "": case "":
if msgLen == 1 { if msgLen == 1 {
nb.Send(message.Channel, "xd") nb.Send(target, "xd")
} }
case "echo": case "botstatus":
if msgLen != 1 { if msgLen == 1 {
nb.Send(message.Channel, cmdParams[1]) nb.Send(target, "Usage: ()botstatus [username]")
return
} else {
commands.BotStatus(target, cmdParams[1], nb)
return 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": case "randomxkcd":
commands.RandomXkcd(message.Channel, nb) commands.RandomXkcd(target, nb)
return return
case "ping": case "ping":
commands.Ping(message.Channel, nb) commands.Ping(target, nb)
return return
case "weather": case "weather":
if msgLen == 1 { if msgLen == 1 {
nb.Send(message.Channel, "Usage: ()weather [location]") nb.Send(target, "Usage: ()weather [location]")
return return
} else { } else {
commands.Weather(message.Channel, message.Message[9:len(message.Message)], nb) commands.Weather(target, message.Message[9:len(message.Message)], nb)
return return
} }
case "xkcd": case "xkcd":
commands.Xkcd(message.Channel, nb) commands.Xkcd(target, nb)
return return
} }