mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
start rewrite
This commit is contained in:
parent
6542c30989
commit
078f9451a7
|
@ -1,78 +0,0 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// banphraseResponse is the data we receive back from
|
||||
// the banphrase API
|
||||
type banphraseResponse struct {
|
||||
Banned bool `json:"banned"`
|
||||
InputMessage string `json:"input_message"`
|
||||
BanphraseData banphraseData `json:"banphrase_data"`
|
||||
}
|
||||
|
||||
// banphraseData contains details about why a message
|
||||
// was banphrased.
|
||||
type banphraseData struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Phrase string `json:"phrase"`
|
||||
Length int `json:"length"`
|
||||
Permanent bool `json:"permanent"`
|
||||
}
|
||||
|
||||
var (
|
||||
banPhraseUrl = "https://pajlada.pajbot.com/api/v1/banphrases/test"
|
||||
)
|
||||
|
||||
// CheckMessage checks a message against a banphrase api..
|
||||
// returns false, "okay" if a message was allowed
|
||||
// returns true, "[banphrased] monkaS" and the reason if not.
|
||||
// More information:
|
||||
// https://gist.github.com/pajlada/57464e519ba8d195a97ddcd0755f9715
|
||||
func CheckMessage(text string) (bool, string) {
|
||||
// log.Info("fn CheckMessage")
|
||||
|
||||
// {"message": "AHAHAHAHA LUL"}
|
||||
reqBody, err := json.Marshal(map[string]string{
|
||||
"message": text,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
resp, err := http.Post(banPhraseUrl, "application/json", bytes.NewBuffer(reqBody))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var responseObject banphraseResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
// Bad Message
|
||||
//
|
||||
// {"phrase": "No gyazo allowed"}
|
||||
// reason := responseObject.BanphraseData.Name
|
||||
if responseObject.Banned {
|
||||
return true, "[Banphrased]"
|
||||
} else if !responseObject.Banned {
|
||||
// Good message
|
||||
return false, "okay"
|
||||
}
|
||||
|
||||
// Couldn't contact api so assume it was a bad message
|
||||
return true, "Banphrase API couldn't be reached monkaS"
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package bot
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBanphrase(t *testing.T) {
|
||||
t.Run("tests the banphrase api", func(t *testing.T) {
|
||||
// Banned message
|
||||
request, _ := CheckMessage("https://gyazo.com/asda")
|
||||
response := true
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
|
||||
// Okay message
|
||||
request, _ = CheckMessage("LUL")
|
||||
response = false
|
||||
|
||||
got = request
|
||||
want = response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
twitch "github.com/gempir/go-twitch-irc/v2"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
type Bot struct {
|
||||
TwitchClient *twitch.Client
|
||||
MongoClient *mongo.Client
|
||||
Uptime time.Time
|
||||
}
|
||||
|
||||
// Send checks the message against a banphrase api
|
||||
// and also splits the message into two if the message
|
||||
// is too long for a single twitch chat message.
|
||||
func (b *Bot) Send(target, text string) {
|
||||
if len(text) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if text[0] == '.' || text[0] == '/' || text[0] == '!' {
|
||||
text = ":tf: " + text
|
||||
}
|
||||
|
||||
// If a message is too long for a single twitch
|
||||
// message, split it into two messages.
|
||||
if len(text) > 500 {
|
||||
firstMessage := text[0:499]
|
||||
secondMessage := text[499:]
|
||||
|
||||
b.TwitchClient.Say(target, firstMessage)
|
||||
b.TwitchClient.Say(target, secondMessage)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// check the message for bad words before we say it
|
||||
messageBanned, banReason := CheckMessage(text)
|
||||
if messageBanned {
|
||||
// Bad message, replace message with a small
|
||||
// notice on why it's banned.
|
||||
b.TwitchClient.Say(target, banReason)
|
||||
return
|
||||
} else {
|
||||
// Message was okay.
|
||||
b.TwitchClient.Say(target, text)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// SkipChecking sends the message without banphrase check
|
||||
func (b *Bot) SkipChecking(target, text string) {
|
||||
b.TwitchClient.Say(target, text)
|
||||
}
|
|
@ -2,21 +2,16 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"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/db"
|
||||
"github.com/lyx0/nourybot/pkg/handlers"
|
||||
"github.com/go-delve/delve/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var nb *bot.Bot
|
||||
|
||||
func main() {
|
||||
|
||||
// runMode is either dev or production so that we don't join every channel
|
||||
// everytime we do a small test.
|
||||
runMode := flag.String("mode", "production", "Mode in which to run. (dev/production")
|
||||
|
@ -26,27 +21,10 @@ func main() {
|
|||
|
||||
nb = &bot.Bot{
|
||||
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
|
||||
MongoClient: db.Connect(conf),
|
||||
Uptime: time.Now(),
|
||||
// MongoClient: db.Connect(conf),
|
||||
Uptime: time.Now(),
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Don't act on bots own messages.
|
||||
if message.Tags["user-id"] == conf.BotUserId {
|
||||
return
|
||||
}
|
||||
|
||||
// Forward the message for further processing.
|
||||
handlers.PrivateMessage(message, nb)
|
||||
})
|
||||
|
||||
// Depending on the mode we run in, join different channel.
|
||||
if *runMode == "production" {
|
||||
log.Info("[PRODUCTION]: Joining every channel.")
|
||||
|
@ -62,5 +40,4 @@ func main() {
|
|||
nb.Send("nourybot", "[DEV] Badabing Badaboom Pepepains")
|
||||
}
|
||||
|
||||
nb.TwitchClient.Connect()
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
t.Run("main package test placeholder", func(t *testing.T) {
|
||||
request := 1
|
||||
response := 1
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package aiden
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
basePath = "https://customapi.aidenwallis.co.uk/"
|
||||
)
|
||||
|
||||
// ApiCall calls https://customapi.aidenwallis.co.uk/ with
|
||||
// a given uri and returns the result and an error.
|
||||
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,21 +0,0 @@
|
|||
package aiden
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestAidenBotRatelimits calls aidens bot ratelimits api and checks
|
||||
// the results against each other with my bot and another verified bot.
|
||||
func TestAidenBotRatelimits(t *testing.T) {
|
||||
t.Run("returns a twitch accounts ratelimits", func(t *testing.T) {
|
||||
requestPajbot, _ := ApiCall("api/v1/twitch/botStatus/pajbot?includeLimits=1")
|
||||
requestNourybot, _ := ApiCall("api/v1/twitch/botStatus/nourybot?includeLimits=1")
|
||||
|
||||
got := requestPajbot
|
||||
want := requestNourybot
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package api
|
||||
|
||||
import "testing"
|
||||
|
||||
// Idk how to test this really since almost everything in here is random
|
||||
func TestApi(t *testing.T) {
|
||||
t.Run("api package test placeholder", func(t *testing.T) {
|
||||
request := 1
|
||||
response := 1
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type currencyResponse struct {
|
||||
Amount int `json:"amount"`
|
||||
Base string `json:"base"`
|
||||
Rates map[string]float32 `json:"rates"`
|
||||
}
|
||||
|
||||
// Currency returns the exchange rate for a given given amount to another.
|
||||
func Currency(currAmount, currFrom, currTo string) (string, error) {
|
||||
baseUrl := "https://api.frankfurter.app"
|
||||
currFromUpper := strings.ToUpper(currFrom)
|
||||
currToUpper := strings.ToUpper(currTo)
|
||||
|
||||
// https://api.frankfurter.app/latest?amount=10&from=gbp&to=usd
|
||||
response, err := http.Get(fmt.Sprintf("%s/latest?amount=%s&from=%s&to=%s", baseUrl, currAmount, currFromUpper, currToUpper))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
responseData, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var responseObject currencyResponse
|
||||
json.Unmarshal(responseData, &responseObject)
|
||||
|
||||
// log.Info(responseObject.Amount)
|
||||
// log.Info(responseObject.Base)
|
||||
// log.Info(responseObject.Rates[strings.ToUpper(currTo)])
|
||||
|
||||
if responseObject.Rates[currToUpper] != 0 {
|
||||
return fmt.Sprintf("%s %s = %.2f %s", currAmount, currFromUpper, responseObject.Rates[currToUpper], currToUpper), nil
|
||||
}
|
||||
|
||||
return "Something went wrong FeelsBadMan", nil
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEmoteLookup(t *testing.T) {
|
||||
t.Run("returns the channel a twitch emote is from and its tier", func(t *testing.T) {
|
||||
// Tier 1
|
||||
request, _ := EmoteLookup("forsenE")
|
||||
response := "forsenE is a Tier 1 emote to channel forsen."
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
// Tier 2
|
||||
request, _ = EmoteLookup("nanZ")
|
||||
response = "nanZ is a Tier 2 emote to channel nani."
|
||||
|
||||
got = request
|
||||
want = response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
// Tier 3
|
||||
request, _ = EmoteLookup("pajaCORAL")
|
||||
response = "pajaCORAL is a Tier 3 emote to channel pajlada."
|
||||
|
||||
got = request
|
||||
want = response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type emoteLookupResponse struct {
|
||||
Channel string `json:"channel"`
|
||||
EmoteCode string `json:"emotecode"`
|
||||
Tier string `json:"tier"`
|
||||
Emote string `json:"emote"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// ProfilePicture returns a link to a given users profilepicture.
|
||||
func EmoteLookup(emote string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/twitch/emotes"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, emote))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var responseObject emoteLookupResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
// log.Info(responseObject.Tier)
|
||||
|
||||
// Emote not found
|
||||
if responseObject.Error != "" {
|
||||
return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil
|
||||
} else {
|
||||
return fmt.Sprintf("%s is a Tier %v emote to channel %s.", responseObject.EmoteCode, responseObject.Tier, responseObject.Channel), 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"`
|
||||
}
|
||||
|
||||
// FirstLine returns the first line a given user has sent in a
|
||||
// given channel.
|
||||
func FirstLine(channel, username string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/logs/firstmessage"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, channel, 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,16 +0,0 @@
|
|||
package ivr
|
||||
|
||||
// func TestFirstLine(t *testing.T) {
|
||||
// t.Run("returns a users first message in a channel", func(t *testing.T) {
|
||||
// request, _ := FirstLine("forsen", "forsen")
|
||||
// response := "forsen: EZ or Ezy (3y, 9mo, 16d ago)."
|
||||
|
||||
// got := request
|
||||
// want := response
|
||||
|
||||
// if got != want {
|
||||
// t.Errorf("got %q, want %q", got, want)
|
||||
// }
|
||||
|
||||
// })
|
||||
// }
|
|
@ -1,50 +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"`
|
||||
}
|
||||
|
||||
// Followage returns the time since a given user followed a given streamer
|
||||
func Followage(streamer, username string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/twitch/subage"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, 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,18 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFollowage(t *testing.T) {
|
||||
t.Run("returns a users date they followed a channel", func(t *testing.T) {
|
||||
request, _ := Followage("forsen", "pajlada")
|
||||
response := "pajlada has been following forsen since 2015-03-09."
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,43 +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"`
|
||||
}
|
||||
|
||||
// ProfilePicture returns a link to a given users profilepicture.
|
||||
func ProfilePicture(username string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/twitch/resolve"
|
||||
|
||||
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,18 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestProfilePicture(t *testing.T) {
|
||||
t.Run("returns a link to a users profile picture", func(t *testing.T) {
|
||||
request, _ := ProfilePicture("forsen")
|
||||
response := "https://static-cdn.jtvnw.net/jtv_user_pictures/forsen-profile_image-48b43e1e4f54b5c8-600x600.png"
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type randomQuoteApiResponse struct {
|
||||
User string `json:"user"`
|
||||
Message string `json:"message"`
|
||||
Time string `json:"time"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// FirstLine returns the first line a given user has sent in a
|
||||
// given channel.
|
||||
func RandomQuote(channel, username string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/logs/rq"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, channel, 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 randomQuoteApiResponse
|
||||
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,69 +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"`
|
||||
}
|
||||
|
||||
// Subage returns the length a given user has been subscribed to a given channel.
|
||||
func Subage(username, channel string) (string, error) {
|
||||
baseUrl := "https://api.ivr.fi/twitch/subage"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, username, channel))
|
||||
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 " + channel + " for " + months + " months.")
|
||||
return reply, nil
|
||||
}
|
||||
}
|
|
@ -1,43 +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"`
|
||||
}
|
||||
|
||||
// Userid returns the userID of a given user
|
||||
func Userid(username string) string {
|
||||
baseUrl := "https://api.ivr.fi/twitch/resolve"
|
||||
|
||||
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 uidApiResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
// User not found
|
||||
if responseObject.Error != "" {
|
||||
return fmt.Sprintf(responseObject.Error + " FeelsBadMan")
|
||||
} else {
|
||||
return fmt.Sprintf(responseObject.Id)
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestUserid(t *testing.T) {
|
||||
t.Run("returns a link to a users profile picture", func(t *testing.T) {
|
||||
request := Userid("nouryxd")
|
||||
response := "31437432"
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// https://api.ivr.fi
|
||||
type whoisApiResponse struct {
|
||||
Id string `json:"id"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Login string `json:"login"`
|
||||
Bio string `json:"bio"`
|
||||
ChatColor string `json:"chatColor"`
|
||||
Partner bool `json:"partner"`
|
||||
// Affiliate bool `json:"affiliate"`
|
||||
Bot bool `json:"bot"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
Roles roles
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type roles struct {
|
||||
IsAffiliate bool `json:"isAffiliate"`
|
||||
IsPartner bool `json:"isPartner"`
|
||||
IsSiteAdmin bool `json:"isSiteAdmin"`
|
||||
IsStaff bool `json:"isStaff"`
|
||||
}
|
||||
|
||||
// Userid returns the userID of a given user
|
||||
func Whois(username string) string {
|
||||
baseUrl := "https://api.ivr.fi/twitch/resolve"
|
||||
|
||||
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 whoisApiResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
// time string format 2011-05-19T00:28:28.310449Z
|
||||
// discard everything after T
|
||||
created := strings.Split(responseObject.CreatedAt, "T")
|
||||
|
||||
reply := fmt.Sprintf("User: %s, ID: %s, Created on: %s, Color: %s, Affiliate: %v, Partner: %v, Staff: %v, Admin: %v, Bot: %v, Bio: %v",
|
||||
responseObject.DisplayName,
|
||||
responseObject.Id,
|
||||
created[0],
|
||||
responseObject.ChatColor,
|
||||
responseObject.Roles.IsAffiliate,
|
||||
responseObject.Roles.IsPartner,
|
||||
responseObject.Roles.IsStaff,
|
||||
responseObject.Roles.IsSiteAdmin,
|
||||
responseObject.Bot,
|
||||
responseObject.Bio,
|
||||
)
|
||||
|
||||
// User not found
|
||||
if responseObject.Error != "" {
|
||||
return fmt.Sprintf(responseObject.Error + " FeelsBadMan")
|
||||
} else {
|
||||
return reply
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package ivr
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWhois(t *testing.T) {
|
||||
t.Run("returns a link to a users profile picture", func(t *testing.T) {
|
||||
request := Whois("forsen")
|
||||
got := request
|
||||
want := Whois("forsen")
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RandomNumber returns a string containg fun facts about a random number.
|
||||
// API used: http://numbersapi.com
|
||||
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)
|
||||
}
|
||||
|
||||
// Number returns a string containing fun facts about a given number.
|
||||
// API used: http://numbersapi.com
|
||||
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,32 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type randomCatResponse struct {
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
// RandomCat returns a link to a random cat picture.
|
||||
// API used: https://aws.random.cat/meow
|
||||
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,32 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type randomDogResponse struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// RandomDog returns a link to a random dog picture.
|
||||
// API used: https://random.dog/woof.json
|
||||
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,32 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type randomDuckResponse struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// RandomDuck returns a link to a random duck picture.
|
||||
// API used: https://random-d.uk/api/random
|
||||
func RandomDuck() string {
|
||||
response, err := http.Get("https://random-d.uk/api/random")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
responseData, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var responseObject randomDuckResponse
|
||||
json.Unmarshal(responseData, &responseObject)
|
||||
|
||||
return string(responseObject.Url)
|
||||
}
|
|
@ -1,33 +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"`
|
||||
}
|
||||
|
||||
// RandomFox returns a link to a random fox picture.
|
||||
// API used: https://randomfox.ca/floof/
|
||||
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,36 +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"`
|
||||
}
|
||||
|
||||
// RandomXkcd returns a link to a random Xkcd comic.
|
||||
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,29 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Xkcd returns a link to the latest Xkcd comic.
|
||||
// API used: https://xkcd.com/info.0.json
|
||||
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,22 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Botstatus responds with if a given bot is verified/known and its ratelimits.
|
||||
func BotStatus(channel, 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)
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, resp)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Bttv responds with a search for a given bttv emote.
|
||||
func Bttv(target, emote string, nb *bot.Bot) {
|
||||
reply := fmt.Sprintf("https://betterttv.com/emotes/shared/search?query=%s", emote)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
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))
|
||||
// }
|
|
@ -1,11 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/db"
|
||||
)
|
||||
|
||||
func ChannelList(target string, nb *bot.Bot) {
|
||||
db.ListChannel(nb)
|
||||
nb.Send(target, "Whispered you the list of channel.")
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
// Coinflip responds with Heads or Tails.
|
||||
func Coinflip(channel string, nb *bot.Bot) {
|
||||
result := utils.GenerateRandomNumber(2)
|
||||
|
||||
if result == 1 {
|
||||
nb.Send(channel, "Heads")
|
||||
} else {
|
||||
nb.Send(channel, "Tails")
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// https://api.ivr.fi
|
||||
type colorApiResponse struct {
|
||||
Id string `json:"id"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ChatColor string `json:"chatColor"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// Userid returns the userID of a given user
|
||||
func Color(username, target string, nb *bot.Bot) {
|
||||
baseUrl := "https://api.ivr.fi/twitch/resolve"
|
||||
|
||||
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 colorApiResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
// time string format 2011-05-19T00:28:28.310449Z
|
||||
// discard everything after T
|
||||
|
||||
reply := fmt.Sprintf("%s color is %s",
|
||||
responseObject.DisplayName,
|
||||
responseObject.ChatColor,
|
||||
)
|
||||
|
||||
// User not found
|
||||
if responseObject.Error != "" {
|
||||
nb.Send(target, "Something went wrong... FeelsBadMan")
|
||||
}
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package commands
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
t.Run("commands package test placeholder", func(t *testing.T) {
|
||||
request := 1
|
||||
response := 1
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package commands
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Commandslist responds with a link to the list of commands.
|
||||
func CommandsList(target string, nb *bot.Bot) {
|
||||
reply := "https://gist.github.com/lyx0/6e326451ed9602157fcf6b5e40fb1dfd"
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Currency responds with the conversion rate for two given currencies.
|
||||
// Example: ()currency 10 usd to eur
|
||||
func Currency(target, currAmount, currFrom, currTo string, nb *bot.Bot) {
|
||||
reply, err := api.Currency(currAmount, currFrom, currTo)
|
||||
if err != nil {
|
||||
logrus.Info(err)
|
||||
}
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package commands
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Echo responds with the given message.
|
||||
func Echo(channel, message string, nb *bot.Bot) {
|
||||
|
||||
nb.Send(channel, message)
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Eightball asks the magic 8ball for guidance.
|
||||
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))
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// EmoteLookup looks up a given emote and responds with the channel it is
|
||||
// associated with and its tier.
|
||||
func EmoteLookup(channel, emote string, nb *bot.Bot) {
|
||||
reply, err := ivr.EmoteLookup(emote)
|
||||
|
||||
if err != nil {
|
||||
nb.Send(channel, fmt.Sprint(err))
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Ffz responds with a search link for a given ffz emote.
|
||||
func Ffz(target, emote string, nb *bot.Bot) {
|
||||
reply := fmt.Sprintf("https://www.frankerfacez.com/emoticons/?q=%s", emote)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
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))
|
||||
// }
|
|
@ -1,27 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Fill repeats a given emote until the whole twitch message
|
||||
// is filled up with the emote and then sends it.
|
||||
func Fill(channel, 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)
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// Firstline responds a given users first message in a given channel.
|
||||
func Firstline(channel, streamer, 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)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// Followage responds with a given users time since he followed a streamer.
|
||||
func Followage(channel, streamer, username string, nb *bot.Bot) {
|
||||
ivrResponse, err := ivr.Followage(streamer, username)
|
||||
|
||||
if err != nil {
|
||||
nb.Send(channel, fmt.Sprint(err))
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, ivrResponse)
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Game responds with the current game category a given stream is set to.
|
||||
func Game(channel, 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)
|
||||
return
|
||||
}
|
||||
|
||||
reply := fmt.Sprintf("@%s was last seen playing: %s", name, game)
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Godocs responds with a search for a given term on godocs.io
|
||||
func Godocs(channel, searchTerm string, nb *bot.Bot) {
|
||||
resp := fmt.Sprintf("https://godocs.io/?q=%s", searchTerm)
|
||||
|
||||
nb.Send(channel, resp)
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package commands
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Help responds with basic information about the bot.
|
||||
func Help(target string, nb *bot.Bot) {
|
||||
reply := "Bot made in Go by @Nouryqt, Prefix: (), Commands: https://gist.github.com/lyx0/6e326451ed9602157fcf6b5e40fb1dfd"
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomNumber calls the numbers api with a random number.
|
||||
func RandomNumber(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomNumber()
|
||||
|
||||
nb.Send(channel, string(reply))
|
||||
}
|
||||
|
||||
// Number calls the numbers api with a given number.
|
||||
func Number(channel, number string, nb *bot.Bot) {
|
||||
reply := api.Number(number)
|
||||
|
||||
nb.Send(channel, string(reply))
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Osrs responds with a link to a given osrs wiki search.
|
||||
func Osrs(target, term string, nb *bot.Bot) {
|
||||
reply := fmt.Sprint("https://oldschool.runescape.wiki/?search=" + url.QueryEscape(term))
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Arch responds with a meme about Arch linux
|
||||
func Arch(target string, nb *bot.Bot) {
|
||||
reply := "Your friend isn't wrong. Being on the actual latest up to date software, having a single unified community repository for out of repo software (AUR) instead of a bunch of scattered broken PPAs for extra software, not having so many hard dependencies that removing GNOME removes basic system utilities, broader customization support and other things is indeed, pretty nice."
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
||||
|
||||
// ArchTwo responds with a meme about Arch linux
|
||||
func ArchTwo(target string, nb *bot.Bot) {
|
||||
reply := "One time I was ordering coffee and suddenly realised the barista didn't know I use Arch. Needless to say, I stopped mid-order to inform her that I do indeed use Arch. I must have spoken louder than I intended because the whole café instantly erupted into a prolonged applause. I walked outside with my head held high. I never did finish my order that day, but just knowing that everyone around me was aware that I use Arch was more energising than a simple cup of coffee could ever be."
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Farm responds with osrs wiki farming guide
|
||||
func Farm(target string, nb *bot.Bot) {
|
||||
nb.Send(target, "Trees: https://oldschool.runescape.wiki/w/Crop_running#Example_tree_run_sequence")
|
||||
nb.Send(target, "Herbs: https://oldschool.runescape.wiki/w/Crop_running#Example_allotment,_flower_and_herb_run_sequence")
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Justinfan responds with the Jusinfan user chatterino has used before.
|
||||
func Justinfan(target string, nb *bot.Bot) {
|
||||
reply := "64537"
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
t.Run("personal package test placeholder", func(t *testing.T) {
|
||||
request := 1
|
||||
response := 1
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Rave returns youtube music playlists.
|
||||
func Rave(target string, nb *bot.Bot) {
|
||||
reply := `https://www.youtube.com/playlist?list=PLY9LTYa8xnQKrug3VvgkPWqmpmXSKAYPe`
|
||||
reply2 := `https://www.youtube.com/playlist?list=PLWwCeXamjNuZ2ZNJiNwvdmVT9TtULsHc6`
|
||||
|
||||
nb.Send(target, reply)
|
||||
nb.Send(target, reply2)
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Streamlink returns the streamlink config.
|
||||
func Streamlink(target string, nb *bot.Bot) {
|
||||
reply := `https://haste.zneix.eu/udajirixep put this in ~/.config/streamlink/config on Linux (or %appdata%\streamlink\streamlinkrc on Windows)`
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Xset returns the keyboard repeat rate command.
|
||||
func Xset(target string, nb *bot.Bot) {
|
||||
reply := "xset r rate 175 50"
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package personal
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Zneix returns a meme about Zneix leaking stuff.
|
||||
func Zneix(target string, nb *bot.Bot) {
|
||||
reply := "ᵃᵈ⁴³ oh frick ⁵²⁴ᵈ ⁸⁹ᵈˢ ⁷⁵⁴⁹ ᶠᵈ³⁴ ᶦᵒ⁶⁸ frick sorry guys ᶠ⁷⁸ᶠ ᵈ⁹⁸⁹ ᵍ⁸²³ ᵍ⁹⁰ˣ ⁹ᵍᶠᵖ sorry im dropping ⁸⁹⁸⁴ ⁰⁹⁰ᶠ my api keys all over the ⁵³²ᵈ place ⁸⁷ᶠᵈ ⁹⁸⁴ᶠ ⁰⁹¹ᵃ sorry zneixApu zneixLeak"
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/humanize"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
// Ping responds with Pong and basic information about the bot.
|
||||
func Ping(target string, nb *bot.Bot) {
|
||||
commandCount := fmt.Sprint(utils.GetCommandsUsed())
|
||||
botUptime := humanize.Time(nb.Uptime)
|
||||
|
||||
reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v", commandCount, botUptime)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Pingme pings a user.
|
||||
func Pingme(channel, user string, nb *bot.Bot) {
|
||||
response := fmt.Sprintf("🔔 @%s 🔔", user)
|
||||
|
||||
nb.Send(channel, response)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// ProfilePicture responds with a link to a given users Twitch Profilepicture.
|
||||
func ProfilePicture(channel, target string, nb *bot.Bot) {
|
||||
reply, err := ivr.ProfilePicture(target)
|
||||
|
||||
if err != nil {
|
||||
nb.Send(channel, fmt.Sprint(err))
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package commands
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "strconv"
|
||||
// "strings"
|
||||
|
||||
// "github.com/lyx0/nourybot/cmd/bot"
|
||||
// )
|
||||
|
||||
// func Pyramid(channel, size, 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 > 3 {
|
||||
// nb.Send(channel, "Max pyramid size is 3")
|
||||
// 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)
|
||||
// }
|
||||
// }
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomCat calls the RandomCat api and responds with a link for a
|
||||
// random cat image.
|
||||
func RandomCat(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomCat()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomDog calls the RandomDog api and responds with a link for a
|
||||
// random dog image.
|
||||
func RandomDog(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomDog()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomDuck calls the RandomDuck api and responds with a link for a
|
||||
// random duck image.
|
||||
func RandomDuck(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomDuck()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomFox calls the RandomFox api and responds with a link for a
|
||||
// random fox image.
|
||||
func RandomFox(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomFox()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// RandomQuote calls the RandomQuote api and responds with a link for a
|
||||
// random quote image.
|
||||
func RandomQuote(channel, target, username string, nb *bot.Bot) {
|
||||
ivrResponse, err := ivr.RandomQuote(target, username)
|
||||
|
||||
if err != nil {
|
||||
nb.Send(channel, fmt.Sprint(err))
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, ivrResponse)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// RandomXkcd calls the RandomXkcd api and responds with a link to a
|
||||
// random xkcd comic.
|
||||
func RandomXkcd(channel string, nb *bot.Bot) {
|
||||
reply := api.RandomXkcd()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// Robohash takes the message ID from the message and responds
|
||||
// with the robohash image link for the message id.
|
||||
func RoboHash(target string, message twitch.PrivateMessage, nb *bot.Bot) {
|
||||
reply := fmt.Sprintf("https://robohash.org/%s", message.ID)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
)
|
||||
|
||||
// SevenTV responds with a link to the 7tv search for a given emote.
|
||||
func SevenTV(target, emote string, nb *bot.Bot) {
|
||||
reply := fmt.Sprintf("https://7tv.app/emotes?query=%s", emote)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// Subage responds with the time a given user has been subscribed
|
||||
// to a given channel.
|
||||
func Subage(channel, username, 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)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
// Thumbnail responds with the current preview image for a given channel.
|
||||
func Thumbnail(channel, 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)
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Title responds with the stream title for a given channel.
|
||||
func Title(channel, 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)
|
||||
return
|
||||
}
|
||||
|
||||
reply := fmt.Sprintf("%s title is: %s", target, title)
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Uptime responds with the time a given channel has been live.
|
||||
func Uptime(channel, 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)
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, resp)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// Userid responds with the userid for a given user.
|
||||
func Userid(channel, target string, nb *bot.Bot) {
|
||||
reply := ivr.Userid(target)
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/aiden"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Weather calls the weather api for a given location and responds
|
||||
// with the current weather data.
|
||||
func Weather(channel, location string, nb *bot.Bot) {
|
||||
reply, err := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location))
|
||||
|
||||
if err != nil {
|
||||
nb.Send(channel, "Something went wrong FeelsBadMan")
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
nb.Send(channel, reply)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||
)
|
||||
|
||||
// Whois responds with information about a given users Twitch account.
|
||||
func Whois(target, user string, nb *bot.Bot) {
|
||||
reply := ivr.Whois(user)
|
||||
|
||||
nb.Send(target, reply)
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package commands
|
||||
|
||||
import "github.com/lyx0/nourybot/cmd/bot"
|
||||
|
||||
// Xd responds with a xd
|
||||
func Xd(channel string, nb *bot.Bot) {
|
||||
nb.Send(channel, "xd")
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/api"
|
||||
)
|
||||
|
||||
// Xkcd responds with a link to the current xkcd comic and information about i.
|
||||
func Xkcd(channel string, nb *bot.Bot) {
|
||||
reply := api.Xkcd()
|
||||
|
||||
nb.Send(channel, reply)
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Username string
|
||||
Oauth string
|
||||
BotUserId string
|
||||
MongoURI string
|
||||
}
|
||||
|
||||
func LoadConfig() *Config {
|
||||
err := godotenv.Load()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env")
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Username: os.Getenv("TWITCH_USER"),
|
||||
Oauth: os.Getenv("TWITCH_PASS"),
|
||||
BotUserId: os.Getenv("BOT_USER_ID"),
|
||||
MongoURI: os.Getenv("MONGO_URI"),
|
||||
}
|
||||
|
||||
log.Info("Config loaded succesfully")
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
// Only for tests
|
||||
func LoadConfigTest() {
|
||||
os.Setenv("TEST_VALUE", "xDLUL420")
|
||||
// defer os.Unsetenv("TEST_VALUE")
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
t.Run("loads a testing value from the .env file", func(t *testing.T) {
|
||||
LoadConfigTest()
|
||||
|
||||
got := os.Getenv("TEST_VALUE")
|
||||
want := "xDLUL420"
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,568 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/commands"
|
||||
"github.com/lyx0/nourybot/pkg/commands/personal"
|
||||
"github.com/lyx0/nourybot/pkg/db"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
// Command contains all the logic for routing mesasges containing commands
|
||||
// and will forward the messages to the specific command handlers.
|
||||
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||
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 antonion
|
||||
// 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))
|
||||
|
||||
// target channel
|
||||
target := message.Channel
|
||||
|
||||
// Logs the message to the database since it invoked a command.
|
||||
db.InsertCommand(nb, commandName, message.User.Name, message.Channel, message.User.ID, message.Message)
|
||||
|
||||
switch commandName {
|
||||
case "":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "xd")
|
||||
return
|
||||
}
|
||||
|
||||
case "7tv":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()7tv [emote]")
|
||||
return
|
||||
}
|
||||
commands.SevenTV(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
case "8ball":
|
||||
commands.EightBall(target, nb)
|
||||
return
|
||||
|
||||
case "bot":
|
||||
commands.Help(target, nb)
|
||||
return
|
||||
|
||||
case "botinfo":
|
||||
commands.Help(target, nb)
|
||||
return
|
||||
|
||||
case "botstatus":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()botstatus [username]")
|
||||
return
|
||||
} else {
|
||||
commands.BotStatus(target, cmdParams[1], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "bttv":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()bttv [emote]")
|
||||
return
|
||||
}
|
||||
commands.Bttv(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
case "channellist":
|
||||
if message.User.ID != "31437432" {
|
||||
nb.Send(target, "You are not allowed to do this")
|
||||
return
|
||||
}
|
||||
commands.ChannelList(target, nb)
|
||||
return
|
||||
|
||||
// case "bttvemotes":
|
||||
// commands.BttvEmotes(target, nb)
|
||||
// return
|
||||
|
||||
case "cat":
|
||||
commands.RandomCat(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(cmdParams[1], target, nb)
|
||||
return
|
||||
|
||||
case "commands":
|
||||
commands.CommandsList(target, nb)
|
||||
return
|
||||
|
||||
case "dog":
|
||||
commands.RandomDog(target, nb)
|
||||
return
|
||||
|
||||
case "duck":
|
||||
commands.RandomDuck(target, nb)
|
||||
return
|
||||
|
||||
case "currency":
|
||||
if msgLen <= 4 {
|
||||
nb.Send(target, "Usage: ()currency 10 usd to eur, only 3 letter codes work.")
|
||||
return
|
||||
}
|
||||
commands.Currency(target, cmdParams[1], cmdParams[2], cmdParams[4], nb)
|
||||
return
|
||||
|
||||
case "echo":
|
||||
if message.User.ID != "31437432" {
|
||||
// nb.Send(target, "You're not authorized to do this.")
|
||||
return
|
||||
} else {
|
||||
commands.Echo(target, message.Message[7:len(message.Message)], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "emote":
|
||||
commands.EmoteLookup(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
case "emotelookup":
|
||||
commands.EmoteLookup(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
case "ffz":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()ffz [emote]")
|
||||
return
|
||||
}
|
||||
commands.Ffz(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
// case "ffzemotes":
|
||||
// commands.FfzEmotes(target, nb)
|
||||
// return
|
||||
|
||||
case "fill":
|
||||
if message.User.ID != "31437432" {
|
||||
nb.Send(target, "You're not authorized to do this.")
|
||||
return
|
||||
} else 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, target, 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, target, 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 "fox":
|
||||
commands.RandomFox(target, nb)
|
||||
return
|
||||
|
||||
case "game":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()game [channel]")
|
||||
return
|
||||
} else {
|
||||
commands.Game(target, cmdParams[1], nb)
|
||||
}
|
||||
|
||||
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 "help":
|
||||
commands.Help(target, nb)
|
||||
return
|
||||
|
||||
case "join":
|
||||
if msgLen == 1 || message.User.ID != "31437432" {
|
||||
nb.Send(target, "You are not allowed to do this")
|
||||
return
|
||||
}
|
||||
db.AddChannel(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
//. case "mycolor":
|
||||
//. commands.Color(message, nb)
|
||||
//. return
|
||||
|
||||
case "nourybot":
|
||||
commands.Help(target, nb)
|
||||
return
|
||||
|
||||
case "num":
|
||||
if msgLen == 1 {
|
||||
commands.RandomNumber(target, nb)
|
||||
return
|
||||
} else {
|
||||
commands.Number(target, cmdParams[1], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "number":
|
||||
if msgLen == 1 {
|
||||
commands.RandomNumber(target, nb)
|
||||
return
|
||||
} else {
|
||||
commands.Number(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
}
|
||||
case "osrs":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()osrs [term]")
|
||||
return
|
||||
} else {
|
||||
commands.Osrs(target, message.Message[7:len(message.Message)], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "part":
|
||||
if msgLen == 1 || message.User.ID != "31437432" {
|
||||
nb.Send(target, "You are not allowed to do this")
|
||||
return
|
||||
}
|
||||
db.PartChannel(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
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 "randomduck":
|
||||
commands.RandomDuck(target, nb)
|
||||
return
|
||||
|
||||
case "randomfox":
|
||||
commands.RandomFox(target, nb)
|
||||
return
|
||||
|
||||
case "rq":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()rq [channel] [user]")
|
||||
return
|
||||
} else if msgLen == 2 {
|
||||
commands.RandomQuote(target, target, cmdParams[1], nb)
|
||||
return
|
||||
} else {
|
||||
commands.RandomQuote(target, cmdParams[1], cmdParams[2], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "randomquote":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()randomquote [channel] [user]")
|
||||
return
|
||||
} else if msgLen == 2 {
|
||||
commands.RandomQuote(target, target, cmdParams[1], nb)
|
||||
return
|
||||
} else {
|
||||
commands.RandomQuote(target, cmdParams[1], cmdParams[2], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "randomxkcd":
|
||||
commands.RandomXkcd(target, nb)
|
||||
return
|
||||
|
||||
case "robo":
|
||||
commands.RoboHash(target, message, nb)
|
||||
return
|
||||
|
||||
case "robohash":
|
||||
commands.RoboHash(target, message, nb)
|
||||
return
|
||||
|
||||
case "subage":
|
||||
if msgLen < 3 {
|
||||
nb.Send(target, "Usage: ()subage [streamer] [user]")
|
||||
return
|
||||
} else {
|
||||
commands.Subage(target, cmdParams[2], cmdParams[1], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "thumb":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()thumb [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 {
|
||||
nb.Send(target, "Usage: ()weather [location]")
|
||||
return
|
||||
} else {
|
||||
commands.Weather(target, message.Message[9:len(message.Message)], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "whois":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()whois [user]")
|
||||
return
|
||||
} else {
|
||||
commands.Whois(target, cmdParams[1], nb)
|
||||
return
|
||||
}
|
||||
|
||||
case "xd":
|
||||
commands.Xd(target, nb)
|
||||
return
|
||||
|
||||
case "xkcd":
|
||||
commands.Xkcd(target, nb)
|
||||
return
|
||||
|
||||
// Basically just personal commands for my own channel from here on.
|
||||
|
||||
case "arch":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Arch(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "arch2":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.ArchTwo(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "farm":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Farm(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "justinfan":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Justinfan(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "farming":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Farm(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "rave":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Rave(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "repeat":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Xset(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "streamlink":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Streamlink(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "streamlinkconfig":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Streamlink(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "xset":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Xset(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
case "zneix":
|
||||
if target == "nouryxd" || target == "nourybot" {
|
||||
personal.Zneix(target, nb)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import "testing"
|
||||
|
||||
// Idk how to test this really we don't return anything
|
||||
func TestHandlers(t *testing.T) {
|
||||
t.Run("handlers package test placeholder", func(t *testing.T) {
|
||||
request := 1
|
||||
response := 1
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// PrivateMessage checks messages for correctness and forwards
|
||||
// commands to the command handler.
|
||||
func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||
// log.Info("fn PrivateMessage")
|
||||
// log.Info(message.Raw)
|
||||
|
||||
// roomId is the Twitch UserID of the channel the message
|
||||
// was sent in.
|
||||
roomId := message.Tags["room-id"]
|
||||
|
||||
// The message has no room-id so something went wrong.
|
||||
if roomId == "" {
|
||||
log.Error("Missing room-id in message tag", roomId)
|
||||
return
|
||||
}
|
||||
|
||||
// General message logging. Not in use currently.
|
||||
// db.InsertMessage(nb, message.User.Name, message.Channel, message.User.ID, message.Message)
|
||||
|
||||
// Thing for #pajlada
|
||||
if message.Channel == "pajlada" && message.Message == "pajaS 🚨 ALERT" && message.User.Name == "pajbot" && message.Action {
|
||||
// log.Info(message.Message)
|
||||
nb.SkipChecking("pajlada", "/me PAJAS 🚨 pajaAAAAAAAAAAA")
|
||||
return
|
||||
}
|
||||
|
||||
// Since our command prefix is () ignore every message
|
||||
// that is less than 2
|
||||
if len(message.Message) >= 2 {
|
||||
// Message starts with (), pass it on to
|
||||
// the command handler.
|
||||
if message.Message[:2] == "()" {
|
||||
Command(message, nb)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Message was no command
|
||||
log.Infof("[#%s]:%s: %s", message.Channel, message.User.DisplayName, message.Message)
|
||||
|
||||
}
|
|
@ -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,30 +0,0 @@
|
|||
package humanize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
t.Run("tests the humanized time", func(t *testing.T) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
fmt.Println("now:", now)
|
||||
|
||||
count := 10
|
||||
// then is the current time - 10 minutes.
|
||||
then := now.Add(time.Duration(-count) * time.Minute)
|
||||
|
||||
request := Time(then)
|
||||
response := "10 minutes ago"
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// I don't know how to test the other ones since they are random
|
||||
func TestCommandsUsed(t *testing.T) {
|
||||
t.Run("tests the commands used counter", func(t *testing.T) {
|
||||
|
||||
request := mockCommandsUsed(127)
|
||||
response := 127
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
|
||||
// 127 + 53
|
||||
// request = mockCommandsUsed(53)
|
||||
// response = 180
|
||||
|
||||
// got = request
|
||||
// want = response
|
||||
|
||||
// if got != want {
|
||||
// t.Errorf("got %v, want %v", got, want)
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
func mockCommandsUsed(n int) int {
|
||||
for i := 0; i < n; i++ {
|
||||
CommandUsed()
|
||||
}
|
||||
return tempCommands
|
||||
}
|
Loading…
Reference in a new issue