add ffz and bttv command

This commit is contained in:
lyx0 2022-08-07 18:10:40 +02:00
parent 6fed6fc265
commit cfb320b017
6 changed files with 125 additions and 0 deletions

View file

@ -53,6 +53,13 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
common.Send(target, "xd", tc)
return
}
case "bttv": // Pretty spammy command so it's limited to my own channel until elevated messages are implemented.
if target == "nourylul" || target == "nourybot" {
commands.Bttv(target, tc)
return
} else {
return
}
case "currency":
if msgLen < 4 {
common.Send(target, "Not enough arguments provided. Usage: ()currency 10 USD to EUR", tc)
@ -67,6 +74,13 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
commands.Echo(target, message.Message[7:len(message.Message)], tc)
return
}
case "ffz": // Pretty spammy command so it's limited to my own channel until elevated messages are implemented.
if target == "nourylul" || target == "nourybot" {
commands.Ffz(target, tc)
return
} else {
return
}
case "tweet":
if msgLen < 2 {
common.Send(target, "Not enough arguments provided. Usage: ()tweet forsen", tc)

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

@ -0,0 +1,20 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/pkg/common"
"github.com/lyx0/nourybot/pkg/decapi"
"go.uber.org/zap"
)
func Bttv(target string, tc *twitch.Client) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
resp, err := decapi.Bttv(target)
if err != nil {
sugar.Error(err)
}
common.Send(target, resp, tc)
}

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

@ -0,0 +1,20 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/pkg/common"
"github.com/lyx0/nourybot/pkg/decapi"
"go.uber.org/zap"
)
func Ffz(target string, tc *twitch.Client) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
resp, err := decapi.Ffz(target)
if err != nil {
sugar.Error(err)
}
common.Send(target, resp, tc)
}

View file

@ -118,6 +118,7 @@ func Send(target, message string, tc *twitch.Client) {
// Twitch has a maximum length for messages of 510 characters so to be safe
// we split and check at 500 characters.
// https://discuss.dev.twitch.tv/t/missing-client-side-message-length-check/21316
// TODO: Make it so it splits at a space instead and not in the middle of a word.
if len(message) > 500 {
firstMessage := message[0:499]
secondMessage := message[499:]

35
pkg/decapi/bttv.go Normal file
View file

@ -0,0 +1,35 @@
package decapi
import (
"fmt"
"io"
"net/http"
"go.uber.org/zap"
)
func Bttv(username string) (string, error) {
var basePath = "https://decapi.me/bttv/emotes/"
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
// https://decapi.me/twitter/latest/forsen?url&no_rts
// ?url adds the url at the end and &no_rts ignores retweets.
resp, err := http.Get(fmt.Sprint(basePath + username))
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
reply := string(body)
return reply, nil
}

35
pkg/decapi/ffz.go Normal file
View file

@ -0,0 +1,35 @@
package decapi
import (
"fmt"
"io"
"net/http"
"go.uber.org/zap"
)
func Ffz(username string) (string, error) {
var basePath = "https://decapi.me/ffz/emotes/"
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
// https://decapi.me/twitter/latest/forsen?url&no_rts
// ?url adds the url at the end and &no_rts ignores retweets.
resp, err := http.Get(fmt.Sprint(basePath + username))
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
reply := string(body)
return reply, nil
}