mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add followage and first line commands
This commit is contained in:
parent
82927a97dd
commit
8e8342998f
|
@ -94,6 +94,7 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
commands.Echo(target, message.Message[7:len(message.Message)], tc)
|
||||
return
|
||||
}
|
||||
|
||||
case "ffz":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()ffz <emote name>", tc)
|
||||
|
@ -109,6 +110,44 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
// Followage
|
||||
// ()followage channel username
|
||||
case "followage":
|
||||
if msgLen == 1 { // ()followage
|
||||
commands.Followage(target, target, message.User.Name, tc)
|
||||
return
|
||||
} else if msgLen == 2 { // ()followage forsen
|
||||
commands.Followage(target, target, cmdParams[1], tc)
|
||||
return
|
||||
} else { // ()followage forsen pajlada
|
||||
commands.Followage(target, cmdParams[1], cmdParams[2], tc)
|
||||
return
|
||||
}
|
||||
// First Line
|
||||
case "firstline":
|
||||
if msgLen == 1 {
|
||||
common.Send(target, "Usage: ()firstline <channel> <user>", tc)
|
||||
return
|
||||
} else if msgLen == 2 {
|
||||
commands.FirstLine(target, target, cmdParams[1], tc)
|
||||
return
|
||||
} else {
|
||||
commands.FirstLine(target, cmdParams[1], cmdParams[2], tc)
|
||||
return
|
||||
}
|
||||
case "fl":
|
||||
if msgLen == 1 {
|
||||
common.Send(target, "Usage: ()firstline <channel> <user>", tc)
|
||||
return
|
||||
} else if msgLen == 2 {
|
||||
commands.FirstLine(target, target, cmdParams[1], tc)
|
||||
return
|
||||
} else {
|
||||
commands.FirstLine(target, cmdParams[1], cmdParams[2], tc)
|
||||
return
|
||||
}
|
||||
|
||||
case "ping":
|
||||
commands.Ping(target, tc)
|
||||
return
|
||||
|
@ -120,6 +159,17 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
commands.Preview(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
|
||||
case "thumbnail":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", tc)
|
||||
return
|
||||
} else {
|
||||
commands.Preview(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
|
||||
// SevenTV
|
||||
case "seventv":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()seventv <emote name>", tc)
|
||||
|
@ -136,14 +186,6 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
commands.Seventv(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
case "thumbnail":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", tc)
|
||||
return
|
||||
} else {
|
||||
commands.Preview(target, cmdParams[1], tc)
|
||||
return
|
||||
}
|
||||
case "tweet":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()tweet <username>", tc)
|
||||
|
|
46
pkg/commands/decapi/followage.go
Normal file
46
pkg/commands/decapi/followage.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package decapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Followage(channel, username string) (string, error) {
|
||||
var basePath = "https://decapi.me/twitch/followage/"
|
||||
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
// ?precision is how precise the timestamp should be.
|
||||
// precision 4 means: 1 2 3 4
|
||||
// pajlada has been following forsen for 7 years, 4 months, 4 weeks, 1 day
|
||||
resp, err := http.Get(fmt.Sprint(basePath + channel + "/" + username + "?precision=4"))
|
||||
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
|
||||
}
|
||||
|
||||
// User tries to look up how long he follows himself.
|
||||
if string(body) == followageUserCannotFollowOwn {
|
||||
return "You cannot follow yourself.", nil
|
||||
|
||||
// Username is not following the requested channel.
|
||||
} else if string(body) == fmt.Sprintf("%s does not follow %s", username, channel) {
|
||||
return string(body), nil
|
||||
} else {
|
||||
reply := fmt.Sprintf("%s has been following %s for %s", username, channel, string(body))
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
}
|
20
pkg/commands/firstline.go
Normal file
20
pkg/commands/firstline.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v3"
|
||||
"github.com/lyx0/nourybot/pkg/commands/ivr"
|
||||
"github.com/lyx0/nourybot/pkg/common"
|
||||
)
|
||||
|
||||
func FirstLine(target, channel, username string, tc *twitch.Client) {
|
||||
ivrResponse, err := ivr.FirstLine(channel, username)
|
||||
|
||||
if err != nil {
|
||||
common.Send(channel, fmt.Sprint(err), tc)
|
||||
return
|
||||
}
|
||||
|
||||
common.Send(target, ivrResponse, tc)
|
||||
}
|
21
pkg/commands/followage.go
Normal file
21
pkg/commands/followage.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/gempir/go-twitch-irc/v3"
|
||||
"github.com/lyx0/nourybot/pkg/commands/decapi"
|
||||
"github.com/lyx0/nourybot/pkg/common"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// ()currency 10 USD to EUR
|
||||
func Followage(target, channel, username string, tc *twitch.Client) {
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
resp, err := decapi.Followage(channel, username)
|
||||
if err != nil {
|
||||
sugar.Error(err)
|
||||
}
|
||||
|
||||
common.Send(target, resp, tc)
|
||||
}
|
50
pkg/commands/ivr/firstline.go
Normal file
50
pkg/commands/ivr/firstline.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package ivr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
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) {
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
baseUrl := "https://api.ivr.fi/logs/firstmessage"
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, channel, 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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue