mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
start with rewrite
This commit is contained in:
parent
07eb4090c5
commit
833eee0c99
48 changed files with 50 additions and 1383 deletions
|
@ -4,63 +4,33 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
twitch "github.com/gempir/go-twitch-irc/v2"
|
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 {
|
type Bot struct {
|
||||||
twitchClient *twitch.Client
|
TwitchClient *twitch.Client
|
||||||
cfg *cfg.Config
|
|
||||||
Uptime time.Time
|
Uptime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBot(cfg *cfg.Config) *Bot {
|
type Channel struct {
|
||||||
|
Name string
|
||||||
log.Info("fn Newbot")
|
|
||||||
twitchClient := twitch.NewClient(cfg.Username, cfg.Oauth)
|
|
||||||
|
|
||||||
return &Bot{
|
|
||||||
cfg: cfg,
|
|
||||||
twitchClient: twitchClient,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) Connect() error {
|
func (b *Bot) Send(target, text string) {
|
||||||
log.Info("fn Connect")
|
if len(text) == 0 {
|
||||||
|
return
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
// if message[0] == '.' || message[0] == '/' {
|
||||||
}
|
// message = ". " + message
|
||||||
|
// }
|
||||||
|
|
||||||
func (b *Bot) Disconnect() error {
|
if len(text) > 500 {
|
||||||
err := b.twitchClient.Disconnect()
|
firstMessage := text[0:499]
|
||||||
if err != nil {
|
secondMessage := text[499:]
|
||||||
log.Error("Error Disconnecting from Twitch: ", err)
|
b.TwitchClient.Say(target, firstMessage)
|
||||||
|
b.TwitchClient.Say(target, secondMessage)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
b.TwitchClient.Say(target, text)
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
31
cmd/main.go
31
cmd/main.go
|
@ -1,17 +1,38 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
"github.com/lyx0/nourybot/cmd/bot"
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
"github.com/lyx0/nourybot/pkg/config"
|
"github.com/lyx0/nourybot/pkg/config"
|
||||||
|
"github.com/lyx0/nourybot/pkg/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var nb *bot.Bot
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg := config.LoadConfig()
|
conf := config.LoadConfig()
|
||||||
nb := bot.NewBot(cfg)
|
|
||||||
|
|
||||||
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
|
@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -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")
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,271 +1,14 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v2"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
"github.com/lyx0/nourybot/pkg/commands"
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
"github.com/lyx0/nourybot/pkg/utils"
|
"github.com/sirupsen/logrus"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleCommand receives a twitch.PrivateMessage from
|
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||||
// HandlePrivateMessage where it found a command in it.
|
logrus.Info("fn Command")
|
||||||
// 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.
|
nb.Send("nourybot", "xd")
|
||||||
utils.CommandUsed()
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v2"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
"github.com/lyx0/nourybot/pkg/config"
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +10,7 @@ import (
|
||||||
// *twitch.Client and *config.Config and has the logic to decide if the provided
|
// *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.
|
// PrivateMessage is a command or not and passes it on accordingly.
|
||||||
// Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua
|
// 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("fn HandlePrivateMessage")
|
||||||
// log.Info(message)
|
// 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
|
// Message was sent from the Bot. Don't act on it
|
||||||
// so that we don't repeat ourself.
|
// 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
|
// Since our command prefix is () ignore every message
|
||||||
// that is less than 2
|
// that is less than 2
|
||||||
|
@ -40,7 +34,7 @@ func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client,
|
||||||
// Message starts with (), pass it on to
|
// Message starts with (), pass it on to
|
||||||
// the command handler.
|
// the command handler.
|
||||||
if message.Message[:2] == "()" {
|
if message.Message[:2] == "()" {
|
||||||
HandleCommand(message, client, uptime)
|
Command(message, nb)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue