Merge pull request #1 from lyx0/rewrite

Rewrite
This commit is contained in:
lyx0 2021-10-19 23:55:03 +02:00 committed by GitHub
commit 1b7828032b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 239 additions and 270 deletions

View file

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

View file

@ -1,17 +1,42 @@
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)
})
nb.TwitchClient.Join("nouryqt", "nourybot")
nb.Send("nourybot", "HeyGuys")
nb.TwitchClient.Connect()
}

View file

@ -3,18 +3,17 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func BotStatus(channel string, name string, client *twitch.Client) {
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 {
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
client.Say(channel, resp)
nb.Send(channel, resp)
}

View file

@ -3,17 +3,17 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func BttvEmotes(channel string, client *twitch.Client) {
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)
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
}
client.Say(channel, string(resp))
nb.Send(channel, string(resp))
}

View file

@ -1,16 +1,16 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/utils"
)
func Coinflip(channel string, client *twitch.Client) {
func Coinflip(channel string, nb *bot.Bot) {
result := utils.GenerateRandomNumber(2)
if result == 1 {
client.Say(channel, "Heads")
nb.Send(channel, "Heads")
} else {
client.Say(channel, "Tails")
nb.Send(channel, "Tails")
}
}

View file

@ -4,11 +4,12 @@ import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
)
func Color(message twitch.PrivateMessage, client *twitch.Client) {
func Color(message twitch.PrivateMessage, nb *bot.Bot) {
reply := fmt.Sprintf("@%v, your color is %v", message.User.DisplayName, message.User.Color)
client.Say(message.Channel, reply)
nb.Send(message.Channel, reply)
}

View file

@ -1,7 +1,7 @@
package commands
import "github.com/gempir/go-twitch-irc/v2"
import "github.com/lyx0/nourybot/cmd/bot"
func Echo(channel string, message string, client *twitch.Client) {
client.Say(channel, message)
func Echo(channel string, message string, nb *bot.Bot) {
nb.Send(channel, message)
}

View file

@ -1,17 +1,17 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func EightBall(channel string, client *twitch.Client) {
func EightBall(channel string, nb *bot.Bot) {
resp, err := aiden.ApiCall("api/v1/misc/8ball")
if err != nil {
log.Error(err)
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
}
client.Say(channel, string(resp))
nb.Send(channel, string(resp))
}

View file

@ -3,18 +3,18 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func FfzEmotes(channel string, client *twitch.Client) {
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)
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
}
client.Say(channel, string(resp))
nb.Send(channel, string(resp))
}

View file

@ -4,12 +4,12 @@ import (
"fmt"
"strings"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
)
func Fill(channel string, emote string, client *twitch.Client) {
func Fill(channel string, emote string, nb *bot.Bot) {
if emote[0] == '.' || emote[0] == '/' {
client.Say(channel, ":tf:")
nb.Send(channel, ":tf:")
return
}
@ -20,6 +20,6 @@ func Fill(channel string, emote string, client *twitch.Client) {
repeatCount := (499 / emoteLength)
reply := strings.Repeat(fmt.Sprintf(emote+" "), repeatCount)
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -3,15 +3,15 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func Firstline(channel string, streamer string, username string, client *twitch.Client) {
func Firstline(channel string, streamer string, username string, nb *bot.Bot) {
ivrResponse, err := ivr.FirstLine(streamer, username)
if err != nil {
client.Say(channel, fmt.Sprint(err))
nb.Send(channel, fmt.Sprint(err))
return
}
client.Say(channel, ivrResponse)
nb.Send(channel, ivrResponse)
}

View file

@ -3,14 +3,14 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func Followage(channel string, streamer string, username string, client *twitch.Client) {
func Followage(channel string, streamer string, username string, nb *bot.Bot) {
ivrResponse, err := ivr.Followage(streamer, username)
if err != nil {
client.Say(channel, fmt.Sprint(err))
nb.Send(channel, fmt.Sprint(err))
}
client.Say(channel, ivrResponse)
nb.Send(channel, ivrResponse)
}

View file

@ -3,18 +3,18 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func Game(channel string, name string, client *twitch.Client) {
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 {
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
reply := fmt.Sprintf("@%s was last seen playing: %s", name, game)
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -3,11 +3,11 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
)
func Godocs(channel string, searchTerm string, client *twitch.Client) {
func Godocs(channel string, searchTerm string, nb *bot.Bot) {
resp := fmt.Sprintf("https://godocs.io/?q=%s", searchTerm)
client.Say(channel, resp)
nb.Send(channel, resp)
}

View file

@ -1,16 +1,16 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomNumber(channel string, client *twitch.Client) {
func RandomNumber(channel string, nb *bot.Bot) {
reply := api.RandomNumber()
client.Say(channel, string(reply))
nb.Send(channel, string(reply))
}
func Number(channel string, number string, client *twitch.Client) {
func Number(channel string, number string, nb *bot.Bot) {
reply := api.Number(number)
client.Say(channel, string(reply))
nb.Send(channel, string(reply))
}

View file

@ -2,17 +2,17 @@ package commands
import (
"fmt"
"time"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/humanize"
"github.com/lyx0/nourybot/pkg/utils"
)
func Ping(channel string, client *twitch.Client, uptime time.Time) {
func Ping(target string, nb *bot.Bot) {
commandCount := fmt.Sprint(utils.GetCommandsUsed())
botUptime := humanize.Time(uptime)
botUptime := humanize.Time(nb.Uptime)
reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v", commandCount, botUptime)
client.Say(channel, reply)
reply := fmt.Sprintf("Pong! :) Commands Used: %v, Last restart: %v", commandCount, botUptime)
nb.Send(target, reply)
}

View file

@ -3,12 +3,11 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
)
func Pingme(channel string, user string, client *twitch.Client) {
func Pingme(channel string, user string, nb *bot.Bot) {
response := fmt.Sprintf("@%s", user)
client.Say(channel, response)
nb.Send(channel, response)
}

View file

@ -3,16 +3,16 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func ProfilePicture(channel string, target string, client *twitch.Client) {
func ProfilePicture(channel string, target string, nb *bot.Bot) {
reply, err := ivr.ProfilePicture(target)
if err != nil {
client.Say(channel, fmt.Sprint(err))
nb.Send(channel, fmt.Sprint(err))
return
}
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -5,17 +5,17 @@ import (
"strconv"
"strings"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
)
func Pyramid(channel string, size string, emote string, client *twitch.Client) {
func Pyramid(channel string, size string, emote string, nb *bot.Bot) {
if size[0] == '.' || size[0] == '/' {
client.Say(channel, ":tf:")
nb.Send(channel, ":tf:")
return
}
if emote[0] == '.' || emote[0] == '/' {
client.Say(channel, ":tf:")
nb.Send(channel, ":tf:")
return
}
@ -23,27 +23,27 @@ func Pyramid(channel string, size string, emote string, client *twitch.Client) {
pyramidEmote := fmt.Sprint(emote + " ")
if err != nil {
client.Say(channel, "Something went wrong")
nb.Send(channel, "Something went wrong")
}
if pyramidSize == 1 {
client.Say(channel, fmt.Sprint(pyramidEmote+"..."))
nb.Send(channel, fmt.Sprint(pyramidEmote+"..."))
return
}
if pyramidSize > 20 {
client.Say(channel, "Max pyramid size is 20")
nb.Send(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)
nb.Send(channel, pyramidMessageAsc)
}
for j := pyramidSize - 1; j >= 0; j-- {
pyramidMessageDesc := strings.Repeat(pyramidEmote, j)
// fmt.Println(pyramidMessageDesc)
client.Say(channel, pyramidMessageDesc)
nb.Send(channel, pyramidMessageDesc)
}
}

View file

@ -1,12 +1,12 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomCat(channel string, client *twitch.Client) {
func RandomCat(channel string, nb *bot.Bot) {
reply := api.RandomCat()
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -1,12 +1,12 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomDog(channel string, client *twitch.Client) {
func RandomDog(channel string, nb *bot.Bot) {
reply := api.RandomDog()
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -1,12 +1,12 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomFox(channel string, client *twitch.Client) {
func RandomFox(channel string, nb *bot.Bot) {
reply := api.RandomFox()
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -1,11 +1,11 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomXkcd(channel string, client *twitch.Client) {
func RandomXkcd(channel string, nb *bot.Bot) {
reply := api.RandomXkcd()
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -3,16 +3,16 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func Subage(channel string, username string, streamer string, client *twitch.Client) {
func Subage(channel string, username string, streamer string, nb *bot.Bot) {
ivrResponse, err := ivr.Subage(username, streamer)
if err != nil {
client.Say(channel, fmt.Sprint(err))
nb.Send(channel, fmt.Sprint(err))
return
}
client.Say(channel, ivrResponse)
nb.Send(channel, ivrResponse)
}

View file

@ -3,14 +3,14 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/utils"
)
func Thumbnail(channel string, target string, client *twitch.Client) {
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)
client.Say(channel, response)
nb.Send(channel, response)
}

View file

@ -3,17 +3,17 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func Title(channel string, target string, client *twitch.Client) {
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 {
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
reply := fmt.Sprintf("%s title is: %s", target, title)
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -3,19 +3,19 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func Uptime(channel string, name string, client *twitch.Client) {
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 {
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
client.Say(channel, resp)
nb.Send(channel, resp)
}

View file

@ -1,11 +1,11 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func Userid(channel string, target string, client *twitch.Client) {
func Userid(channel string, target string, nb *bot.Bot) {
reply := ivr.Userid(target)
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -3,18 +3,18 @@ package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
)
func Weather(channel string, location string, client *twitch.Client) {
func Weather(channel string, location string, nb *bot.Bot) {
reply, err := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location))
if err != nil {
client.Say(channel, "Something went wrong FeelsBadMan")
nb.Send(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -1,7 +1,7 @@
package commands
import "github.com/gempir/go-twitch-irc/v2"
import "github.com/lyx0/nourybot/cmd/bot"
func Xd(channel string, client *twitch.Client) {
client.Say(channel, "xd")
func Xd(channel string, nb *bot.Bot) {
nb.Send(channel, "xd")
}

View file

@ -1,12 +1,13 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api"
)
func Xkcd(channel string, client *twitch.Client) {
func Xkcd(channel string, nb *bot.Bot) {
reply := api.Xkcd()
client.Say(channel, reply)
nb.Send(channel, reply)
}

View file

@ -2,23 +2,16 @@ package handlers
import (
"strings"
"time"
"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"
log "github.com/sirupsen/logrus"
"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")
// Counter that increments on every command call.
utils.CommandUsed()
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
logrus.Info("fn Command")
// commandName is the actual command name without the prefix.
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
@ -34,238 +27,242 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
// 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 {
twitchClient.Say(message.Channel, "Why yes, that's my prefix :)")
return
nb.Send(target, "xd")
}
case "botstatus":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()botstatus [username]")
nb.Send(target, "Usage: ()botstatus [username]")
return
} else {
commands.BotStatus(message.Channel, cmdParams[1], twitchClient)
commands.BotStatus(target, cmdParams[1], nb)
return
}
case "bttvemotes":
commands.BttvEmotes(message.Channel, twitchClient)
commands.BttvEmotes(target, nb)
return
case "cf":
commands.Coinflip(message.Channel, twitchClient)
commands.Coinflip(target, nb)
return
case "coin":
commands.Coinflip(message.Channel, twitchClient)
commands.Coinflip(target, nb)
return
case "coinflip":
commands.Coinflip(message.Channel, twitchClient)
commands.Coinflip(target, nb)
return
case "color":
commands.Color(message, twitchClient)
commands.Color(message, nb)
return
case "mycolor":
commands.Color(message, twitchClient)
commands.Color(message, nb)
return
case "echo":
commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient)
commands.Echo(target, message.Message[7:len(message.Message)], nb)
return
case "8ball":
commands.EightBall(message.Channel, twitchClient)
commands.EightBall(target, nb)
return
case "ffzemotes":
commands.FfzEmotes(message.Channel, twitchClient)
commands.FfzEmotes(target, nb)
return
case "fill":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()fill [emote]")
nb.Send(target, "Usage: ()fill [emote]")
return
} else {
commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient)
commands.Fill(target, message.Message[7:len(message.Message)], nb)
return
}
case "firstline":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()firstline [channel] [user]")
nb.Send(target, "Usage: ()firstline [channel] [user]")
return
} else if msgLen == 2 {
commands.Firstline(message.Channel, message.Channel, cmdParams[1], twitchClient)
commands.Firstline(target, target, cmdParams[1], nb)
return
} else {
commands.Firstline(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
return
}
case "fl":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()firstline [channel] [user]")
nb.Send(target, "Usage: ()firstline [channel] [user]")
return
} else if msgLen == 2 {
commands.Firstline(message.Channel, message.Channel, cmdParams[1], twitchClient)
commands.Firstline(target, target, cmdParams[1], nb)
return
} else {
commands.Firstline(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
return
}
case "followage":
if msgLen <= 2 {
twitchClient.Say(message.Channel, "Usage: ()followage [channel] [user]")
nb.Send(target, "Usage: ()followage [channel] [user]")
return
} else {
commands.Followage(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
commands.Followage(target, cmdParams[1], cmdParams[2], nb)
return
}
case "game":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()game [channel]")
nb.Send(target, "Usage: ()game [channel]")
return
} else {
commands.Game(message.Channel, cmdParams[1], twitchClient)
commands.Game(target, cmdParams[1], nb)
}
case "godoc":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
nb.Send(target, "Usage: ()godoc [term]")
return
} else {
commands.Godocs(message.Channel, message.Message[8:len(message.Message)], twitchClient)
commands.Godocs(target, message.Message[8:len(message.Message)], nb)
return
}
case "godocs":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
nb.Send(target, "Usage: ()godoc [term]")
return
} else {
commands.Godocs(message.Channel, message.Message[9:len(message.Message)], twitchClient)
commands.Godocs(target, message.Message[9:len(message.Message)], nb)
return
}
case "num":
if msgLen == 1 {
commands.RandomNumber(message.Channel, twitchClient)
commands.RandomNumber(target, nb)
} else {
commands.Number(message.Channel, cmdParams[1], twitchClient)
commands.Number(target, cmdParams[1], nb)
}
case "number":
if msgLen == 1 {
commands.RandomNumber(message.Channel, twitchClient)
commands.RandomNumber(target, nb)
} else {
commands.Number(message.Channel, cmdParams[1], twitchClient)
commands.Number(target, cmdParams[1], nb)
}
case "ping":
commands.Ping(message.Channel, twitchClient, uptime)
commands.Ping(target, nb)
return
case "pingme":
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
commands.Pingme(target, message.User.DisplayName, nb)
return
case "preview":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()preview [channel]")
nb.Send(target, "Usage: ()preview [channel]")
return
} else {
commands.Thumbnail(message.Channel, cmdParams[1], twitchClient)
commands.Thumbnail(target, cmdParams[1], nb)
return
}
case "profilepicture":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()profilepicture [user]")
nb.Send(target, "Usage: ()profilepicture [user]")
return
}
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
commands.ProfilePicture(target, cmdParams[1], nb)
return
case "pfp":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()pfp [user]")
nb.Send(target, "Usage: ()pfp [user]")
return
}
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
commands.ProfilePicture(target, cmdParams[1], nb)
return
case "pyramid":
if msgLen != 3 {
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")
nb.Send(target, "Usage: ()pyramid [size] [emote]")
} else if utils.ElevatedPrivsMessage(message) {
commands.Pyramid(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
commands.Pyramid(target, cmdParams[1], cmdParams[2], nb)
} else {
twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan")
nb.Send(target, "Pleb's can't pyramid FeelsBadMan")
}
case "randomcat":
commands.RandomCat(message.Channel, twitchClient)
commands.RandomCat(target, nb)
return
case "randomdog":
commands.RandomDog(message.Channel, twitchClient)
commands.RandomDog(target, nb)
return
case "randomfox":
commands.RandomFox(message.Channel, twitchClient)
commands.RandomFox(target, nb)
return
case "randomxkcd":
commands.RandomXkcd(message.Channel, twitchClient)
commands.RandomXkcd(target, nb)
return
case "subage":
if msgLen < 3 {
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")
nb.Send(target, "Usage: ()subage [user] [streamer]")
return
} else {
commands.Subage(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
commands.Subage(target, cmdParams[1], cmdParams[2], nb)
return
}
case "thumb":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]")
nb.Send(target, "Usage: ()thumbnail [channel]")
return
} else {
commands.Thumbnail(message.Channel, cmdParams[1], twitchClient)
commands.Thumbnail(target, cmdParams[1], nb)
return
}
case "thumbnail":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]")
nb.Send(target, "Usage: ()thumbnail [channel]")
return
} else {
commands.Thumbnail(message.Channel, cmdParams[1], twitchClient)
commands.Thumbnail(target, cmdParams[1], nb)
return
}
case "title":
if msgLen == 1 {
commands.Title(message.Channel, message.Channel, twitchClient)
commands.Title(target, target, nb)
return
} else {
commands.Title(message.Channel, cmdParams[1], twitchClient)
commands.Title(target, cmdParams[1], nb)
return
}
case "uptime":
if msgLen == 1 {
commands.Uptime(message.Channel, message.Channel, twitchClient)
commands.Uptime(target, target, nb)
return
} else {
commands.Uptime(message.Channel, cmdParams[1], twitchClient)
commands.Uptime(target, cmdParams[1], nb)
return
}
case "uid":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()uid [username]")
nb.Send(target, "Usage: ()uid [username]")
return
} else {
commands.Userid(message.Channel, cmdParams[1], twitchClient)
commands.Userid(target, cmdParams[1], nb)
return
}
case "userid":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()userid [username]")
nb.Send(target, "Usage: ()userid [username]")
return
} else {
commands.Userid(message.Channel, cmdParams[1], twitchClient)
commands.Userid(target, cmdParams[1], nb)
return
}
case "weather":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()weather [location]")
nb.Send(target, "Usage: ()weather [location]")
return
} else {
commands.Weather(message.Channel, message.Message[9:len(message.Message)], twitchClient)
commands.Weather(target, message.Message[9:len(message.Message)], nb)
return
}
case "xd":
commands.Xd(message.Channel, twitchClient)
return
commands.Xd(target, nb)
case "xkcd":
commands.Xkcd(message.Channel, twitchClient)
commands.Xkcd(target, nb)
return
}
}

View file

@ -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,8 +10,8 @@ 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) {
log.Info("fn HandlePrivateMessage")
func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
log.Info("fn PrivateMessage")
// log.Info(message)
// roomId is the Twitch UserID of the channel the message
@ -26,13 +24,6 @@ func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client,
return
}
// 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
if len(message.Message) >= 2 {
@ -40,7 +31,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
}
}

View file

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