2023-08-08 02:37:37 +02:00
package main
import (
2023-12-17 21:01:14 +01:00
"fmt"
"sort"
2023-08-08 02:37:37 +02:00
"strings"
"github.com/gempir/go-twitch-irc/v4"
2024-02-20 22:36:33 +01:00
"github.com/lyx0/nourybot/pkg/commands"
"github.com/lyx0/nourybot/pkg/common"
2023-10-11 18:52:46 +02:00
"github.com/lyx0/nourybot/pkg/ivr"
"github.com/lyx0/nourybot/pkg/lastfm"
"github.com/lyx0/nourybot/pkg/owm"
2023-08-08 02:37:37 +02:00
)
// handleCommand takes in a twitch.PrivateMessage and then routes the message to
// the function that is responsible for each command and knows how to deal with it accordingly.
func ( app * application ) handleCommand ( message twitch . PrivateMessage ) {
2023-09-07 20:12:09 +02:00
var reply string
2023-08-08 02:37:37 +02:00
2023-12-03 16:35:34 +01:00
if message . Channel == "forsen" {
return
}
2023-08-08 02:37:37 +02:00
// Increments the counter how many commands have been used, called in the ping command.
2023-10-10 12:49:06 +02:00
go common . CommandUsed ( )
go app . InitUser ( message . User . Name , message . User . ID )
2023-08-08 02:37:37 +02:00
// commandName is the actual name of the command without the prefix.
// e.g. `()ping` would be `ping`.
commandName := strings . ToLower ( strings . SplitN ( message . Message , " " , 3 ) [ 0 ] [ 2 : ] )
// cmdParams are additional command parameters.
// e.g. `()weather san antonio`
// cmdParam[0] is `san` and cmdParam[1] = `antonio`.
//
// Since Twitch messages are at most 500 characters I use a
// maximum count of 500+10 just to be safe.
// https://discuss.dev.twitch.tv/t/missing-client-side-message-length-check/21316
cmdParams := strings . SplitN ( message . Message , " " , 500 )
// msgLen is the amount of words in a message without the prefix.
// Useful to check if enough cmdParams are provided.
msgLen := len ( strings . SplitN ( message . Message , " " , - 2 ) )
2023-10-11 20:46:02 +02:00
userLevel := app . GetUserLevel ( message )
2023-10-11 18:01:32 +02:00
2023-08-08 02:37:37 +02:00
// target is the channelname the message originated from and
// where the TwitchClient should send the response
target := message . Channel
app . Log . Infow ( "Command received" ,
// "message", message, // Pretty taxing
"message.Message" , message . Message ,
"message.Channel" , target ,
"commandName" , commandName ,
"cmdParams" , cmdParams ,
"msgLen" , msgLen ,
2023-09-19 14:04:58 +02:00
"userLevel" , userLevel ,
2023-08-08 02:37:37 +02:00
)
2023-10-10 16:07:35 +02:00
go app . LogCommand ( message , commandName , userLevel )
2023-08-08 02:37:37 +02:00
// A `commandName` is every message starting with `()`.
// Hardcoded commands have a priority over database commands.
// Switch over the commandName and see if there is a hardcoded case for it.
// If there was no switch case satisfied, query the database if there is
// a data.CommandModel.Name equal to the `commandName`
// If there is return the data.CommandModel.Text entry.
// Otherwise we ignore the message.
switch commandName {
case "" :
if msgLen == 1 {
2023-09-07 20:12:09 +02:00
reply = "xd"
2023-08-08 02:37:37 +02:00
}
2023-10-11 18:01:32 +02:00
// --------------------------------
// pleb commands
// --------------------------------
2023-09-07 20:43:16 +02:00
case "bttv" :
if msgLen < 2 {
reply = "Not enough arguments provided. Usage: ()bttv <emote name>"
} else {
reply = commands . Bttv ( cmdParams [ 1 ] )
}
2023-12-17 22:46:18 +01:00
case "betterttv" :
if msgLen < 2 {
reply = "Not enough arguments provided. Usage: ()bttv <emote name>"
} else {
reply = commands . Bttv ( cmdParams [ 1 ] )
}
2023-09-07 20:43:16 +02:00
// Coinflip
case "coin" :
reply = commands . Coinflip ( )
2023-12-17 22:46:18 +01:00
2023-09-07 20:43:16 +02:00
case "coinflip" :
reply = commands . Coinflip ( )
2023-12-17 22:46:18 +01:00
2023-09-07 20:43:16 +02:00
case "cf" :
reply = commands . Coinflip ( )
2023-09-07 21:09:33 +02:00
case "currency" :
if msgLen < 4 {
reply = "Not enough arguments provided. Usage: ()currency 10 USD to EUR"
} else {
2024-02-20 22:36:33 +01:00
// ()currency <amount> <input currency> to <output currency>
2023-09-07 21:09:33 +02:00
reply , _ = commands . Currency ( cmdParams [ 1 ] , cmdParams [ 2 ] , cmdParams [ 4 ] )
}
2023-10-10 14:28:43 +02:00
case "osrs" :
reply = commands . OSRS ( message . Message [ 7 : len ( message . Message ) ] )
case "preview" :
reply = commands . Preview ( cmdParams [ 1 ] )
case "thumbnail" :
reply = commands . Preview ( cmdParams [ 1 ] )
case "ffz" :
reply = commands . Ffz ( cmdParams [ 1 ] )
2023-12-17 22:46:18 +01:00
case "frankerfacez" :
reply = commands . Ffz ( cmdParams [ 1 ] )
2024-02-13 19:13:44 +01:00
case "notify" :
switch cmdParams [ 1 ] {
case "live" :
if userLevel >= 100 {
reply = app . createLiveSubscription ( target , cmdParams [ 2 ] )
}
case "offline" :
if userLevel >= 100 {
2024-02-14 23:01:54 +01:00
reply = app . createOfflineSubscription ( target , cmdParams [ 2 ] )
2024-02-13 19:13:44 +01:00
}
}
2024-02-15 21:58:57 +01:00
2024-02-14 22:13:07 +01:00
case "unnotify" :
switch cmdParams [ 1 ] {
case "live" :
if userLevel >= 100 {
reply = app . deleteLiveSubscription ( target , cmdParams [ 2 ] )
}
2024-02-14 23:01:54 +01:00
case "offline" :
if userLevel >= 100 {
reply = app . deleteOfflineSubscription ( target , cmdParams [ 2 ] )
}
2024-02-14 22:13:07 +01:00
}
2024-02-13 19:13:44 +01:00
2023-10-10 14:28:43 +02:00
case "ddg" :
reply = commands . DuckDuckGo ( message . Message [ 6 : len ( message . Message ) ] )
case "youtube" :
reply = commands . Youtube ( message . Message [ 10 : len ( message . Message ) ] )
case "godocs" :
reply = commands . Godocs ( message . Message [ 9 : len ( message . Message ) ] )
case "google" :
reply = commands . Google ( message . Message [ 9 : len ( message . Message ) ] )
case "duckduckgo" :
reply = commands . DuckDuckGo ( message . Message [ 13 : len ( message . Message ) ] )
case "seventv" :
reply = commands . SevenTV ( cmdParams [ 1 ] )
case "7tv" :
reply = commands . SevenTV ( cmdParams [ 1 ] )
2023-09-08 01:36:41 +02:00
case "lastfm" :
if msgLen == 1 {
reply = app . UserCheckLastFM ( message )
} else {
// Default to first argument supplied being the name
// of the user to look up recently played.
2023-10-11 18:52:46 +02:00
reply = lastfm . LastFmUserRecent ( target , cmdParams [ 1 ] )
2023-09-08 01:36:41 +02:00
}
2023-10-10 13:16:30 +02:00
case "help" :
if msgLen > 1 {
2023-10-10 17:51:12 +02:00
app . commandHelp ( target , cmdParams [ 1 ] , message . User . Name , message )
2023-10-10 13:16:30 +02:00
}
2023-08-08 02:37:37 +02:00
case "nourybot" :
2023-10-23 13:48:27 +02:00
reply = "Lidl Twitch bot made by @nouryxd. Prefix: ()"
2023-08-08 02:37:37 +02:00
2023-09-07 21:09:33 +02:00
case "phonetic" :
if msgLen == 1 {
reply = "Not enough arguments provided. Usage: ()phonetic <text to translate>"
} else {
reply , _ = commands . Phonetic ( message . Message [ 11 : len ( message . Message ) ] )
}
2023-08-08 02:37:37 +02:00
case "ping" :
2024-02-10 20:40:27 +01:00
reply = commands . Ping ( app . Environment )
2023-08-08 02:37:37 +02:00
// ()bttv <emote name>
2023-09-07 20:43:16 +02:00
// ()weather <location>
case "weather" :
if msgLen == 1 {
2023-09-08 01:36:41 +02:00
app . UserCheckWeather ( message )
2023-09-07 20:43:16 +02:00
} else if msgLen < 2 {
reply = "Not enough arguments provided."
} else {
2023-10-11 18:52:46 +02:00
reply , _ = owm . Weather ( message . Message [ 10 : len ( message . Message ) ] )
2023-09-07 20:43:16 +02:00
}
2023-09-07 21:09:33 +02:00
case "rxkcd" :
reply , _ = commands . RandomXkcd ( )
2023-12-17 22:46:18 +01:00
2023-09-07 21:09:33 +02:00
case "randomxkcd" :
reply , _ = commands . RandomXkcd ( )
2023-12-17 22:46:18 +01:00
2023-09-07 21:09:33 +02:00
case "xkcd" :
reply , _ = commands . Xkcd ( )
2023-10-11 18:01:32 +02:00
case "uid" :
2023-12-20 02:18:57 +01:00
reply = ivr . IDByUsernameReply ( cmdParams [ 1 ] )
2023-10-11 18:01:32 +02:00
2023-12-17 22:46:18 +01:00
case "userid" :
2023-12-20 02:18:57 +01:00
reply = ivr . IDByUsernameReply ( cmdParams [ 1 ] )
2023-12-17 22:46:18 +01:00
2023-12-17 18:48:46 +01:00
case "commands" :
reply = app . ListChannelCommands ( message . Channel )
2023-12-17 20:11:02 +01:00
case "timers" :
2024-01-08 16:25:54 +01:00
reply = fmt . Sprintf ( "https://bot.noury.li/timer/%s" , message . Channel )
2023-12-17 20:11:02 +01:00
2023-12-19 22:30:22 +01:00
case "conv" :
if userLevel >= 100 {
app . ConvertToMP4 ( cmdParams [ 1 ] , message )
}
2023-12-19 22:53:42 +01:00
case "meme" :
if userLevel >= 100 {
app . ConvertAndSave ( cmdParams [ 1 ] , cmdParams [ 2 ] , message )
}
2023-10-11 18:01:32 +02:00
case "set" :
2023-09-07 22:34:53 +02:00
switch cmdParams [ 1 ] {
2023-10-11 18:01:32 +02:00
case "lastfm" :
app . SetUserLastFM ( cmdParams [ 2 ] , message )
case "location" :
app . SetUserLocation ( message )
2023-09-07 22:34:53 +02:00
}
2023-10-11 18:01:32 +02:00
// --------------------------------
2023-10-11 21:35:47 +02:00
// 100 user level
// trusted
// vip
2023-10-11 18:01:32 +02:00
// --------------------------------
2023-12-17 17:23:42 +01:00
case "wa" :
if userLevel >= 100 {
reply = commands . WolframAlphaQuery ( message . Message [ 5 : len ( message . Message ) ] , app . Config . wolframAlphaAppID )
}
2023-12-17 22:46:18 +01:00
case "query" :
if userLevel >= 100 {
reply = commands . WolframAlphaQuery ( message . Message [ 8 : len ( message . Message ) ] , app . Config . wolframAlphaAppID )
}
2023-09-08 03:03:57 +02:00
case "debug" :
switch cmdParams [ 1 ] {
case "user" :
2023-10-11 21:35:47 +02:00
if userLevel >= 100 {
2023-09-19 14:04:58 +02:00
app . DebugUser ( cmdParams [ 2 ] , message )
}
2023-09-14 17:40:35 +02:00
case "command" :
2023-10-11 21:35:47 +02:00
if userLevel >= 100 {
2023-09-19 14:04:58 +02:00
app . DebugCommand ( cmdParams [ 2 ] , message )
}
2023-12-08 19:23:31 +01:00
case "env" :
if userLevel >= 100 {
reply = app . Environment
}
2023-12-17 23:15:21 +01:00
case "timers" :
if userLevel >= 100 {
app . DebugChannelTimers ( message . Channel )
}
2023-09-08 03:03:57 +02:00
}
2023-10-11 21:35:47 +02:00
// --------------------------------
// 250 user level
// twitch mod/broadcaster
// --------------------------------
// empty for now
// --------------------------------
// 420 user level
// dank
// --------------------------------
case "catbox" :
if userLevel >= 420 {
go app . NewDownload ( "catbox" , target , cmdParams [ 1 ] , message )
}
case "kappa" :
if userLevel >= 420 {
go app . NewDownload ( "kappa" , target , cmdParams [ 1 ] , message )
}
case "yaf" :
if userLevel >= 420 {
go app . NewDownload ( "yaf" , target , cmdParams [ 1 ] , message )
}
case "gofile" :
if userLevel >= 420 {
go app . NewDownload ( "gofile" , target , cmdParams [ 1 ] , message )
}
//----------------------------------
// 500 User Level
// trusted
//---------------------------------
2023-10-11 18:01:32 +02:00
case "timer" :
switch cmdParams [ 1 ] {
case "add" :
2023-10-11 21:35:47 +02:00
if userLevel >= 500 {
2023-10-11 18:01:32 +02:00
app . AddTimer ( cmdParams [ 2 ] , cmdParams [ 3 ] , message )
}
case "delete" :
2023-10-11 21:35:47 +02:00
if userLevel >= 500 {
2023-10-11 18:01:32 +02:00
app . DeleteTimer ( cmdParams [ 2 ] , message )
}
2023-12-17 23:15:21 +01:00
case "edit" :
if userLevel >= 500 {
app . EditTimer ( cmdParams [ 2 ] , cmdParams [ 3 ] , message )
2023-10-11 18:01:32 +02:00
}
}
2023-09-08 00:18:09 +02:00
case "command" :
switch cmdParams [ 1 ] {
case "add" :
2023-10-11 21:35:47 +02:00
if userLevel >= 500 {
2023-10-11 18:01:32 +02:00
app . AddCommand ( cmdParams [ 2 ] , message )
}
2023-09-08 00:18:09 +02:00
case "delete" :
2023-10-11 21:35:47 +02:00
if userLevel >= 500 {
2023-10-11 18:01:32 +02:00
app . DeleteCommand ( cmdParams [ 2 ] , message )
}
2023-12-03 17:24:42 +01:00
case "list" :
if userLevel >= 500 {
reply = app . ListCommands ( )
}
2023-09-08 00:18:09 +02:00
case "edit" :
switch cmdParams [ 2 ] {
case "level" :
2023-10-11 21:35:47 +02:00
if userLevel >= 500 {
2023-10-11 18:01:32 +02:00
app . EditCommandLevel ( cmdParams [ 3 ] , cmdParams [ 4 ] , message )
}
2023-09-08 00:18:09 +02:00
}
}
2023-10-11 18:01:32 +02:00
//------------------------------------
// 1000 User Level
2023-10-11 21:35:47 +02:00
// Admin
2023-10-11 18:01:32 +02:00
//------------------------------------
case "join" :
if userLevel >= 1000 {
go app . AddChannel ( cmdParams [ 1 ] , message )
}
case "part" :
if userLevel >= 1000 {
go app . DeleteChannel ( cmdParams [ 1 ] , message )
2023-09-08 01:36:41 +02:00
}
case "user" :
switch cmdParams [ 1 ] {
case "edit" :
switch cmdParams [ 2 ] {
case "level" :
2023-10-11 18:01:32 +02:00
if userLevel >= 1000 {
app . EditUserLevel ( cmdParams [ 3 ] , cmdParams [ 4 ] , message )
}
}
case "set" :
switch cmdParams [ 2 ] {
case "level" :
if userLevel >= 1000 {
app . EditUserLevel ( cmdParams [ 3 ] , cmdParams [ 4 ] , message )
}
2023-09-08 01:36:41 +02:00
}
}
2023-10-10 11:58:42 +02:00
default :
r , err := app . GetCommand ( target , commandName , userLevel )
if err != nil {
return
}
2023-12-19 19:37:26 +01:00
go app . SendNoBanphrase ( target , r )
return
2023-08-08 02:37:37 +02:00
}
2023-09-07 20:12:09 +02:00
if reply != "" {
2023-10-10 17:51:12 +02:00
go app . Send ( target , reply , message )
2023-09-07 20:12:09 +02:00
return
}
2023-08-08 02:37:37 +02:00
}
2023-10-10 13:16:30 +02:00
2023-12-17 22:46:18 +01:00
type command struct {
2023-12-20 02:06:05 +01:00
Name string
2023-12-17 22:46:18 +01:00
Alias [ ] string
Description string
Level string
Usage string
}
// Optional is []
// Required is < >
var helpText = map [ string ] command {
"bttv" : {
2023-12-20 02:06:05 +01:00
Name : "bttv" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "bttv" , "betterttv" } ,
Description : "Returns the search URL for a given BTTV emote." ,
Level : "0" ,
Usage : "()bttv <emote name>" ,
} ,
"catbox" : {
2023-12-20 02:06:05 +01:00
Name : "catbox" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Downloads the video of a given link with yt-dlp and then uploads the video to catbox.moe." ,
Level : "420" ,
Usage : "()catbox <link>" ,
} ,
"coin" : {
2023-12-20 02:06:05 +01:00
Name : "coin" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "coin" , "coinflip" , "cf" } ,
Description : "Flip a coin." ,
Level : "0" ,
Usage : "()coin" ,
} ,
2023-12-17 23:15:21 +01:00
"command add" : {
2023-12-20 02:06:05 +01:00
Name : "command add" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Adds a channel command to the database." ,
Level : "250" ,
Usage : "()add command <command name> <command text>" ,
} ,
"command edit level" : {
2023-12-20 02:06:05 +01:00
Name : "command edit level" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Edits the required level of a channel command with the given name." ,
Level : "250" ,
Usage : "()command edit level <command name> <new command level>" ,
} ,
"command delete" : {
2023-12-20 02:06:05 +01:00
Name : "command delete" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Deletes the channel command with the given name." ,
Level : "250" ,
Usage : "()command delete <command name>" ,
} ,
2023-12-17 22:46:18 +01:00
"commands" : {
2023-12-20 02:06:05 +01:00
Name : "commands" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns a link to the commands in the channel." ,
Level : "0" ,
Usage : "()commands" ,
} ,
"currency" : {
2023-12-20 02:06:05 +01:00
Name : "currency" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "currency" , "money" } ,
Description : "Returns the exchange rate for two currencies. Only three letter abbreviations are supported ( List of supported currencies: https://decapi.me/misc/currency?list )." ,
Level : "0" ,
Usage : "()currency <curr> to <curr>" ,
} ,
2023-12-17 23:15:21 +01:00
"debug env" : {
2023-12-20 02:06:05 +01:00
Name : "debug env" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Returns the environment currently running in." ,
Level : "100" ,
Usage : "()debug env" ,
} ,
"debug user" : {
2023-12-20 02:06:05 +01:00
Name : "debug user" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Returns additional information about a user." ,
Level : "100" ,
Usage : "()debug user <username>" ,
} ,
"debug command" : {
2023-12-20 02:06:05 +01:00
Name : "debug command" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Returns additional informations about a command." ,
Level : "100" ,
Usage : "()debug command <command name>" ,
} ,
"debug timers" : {
2023-12-20 02:06:05 +01:00
Name : "debug timers" ,
2023-12-17 23:15:21 +01:00
Alias : nil ,
Description : "Returns a list of timers currently running in the channel with additional informations." ,
Level : "100" ,
Usage : "()debug timers" ,
} ,
2023-12-17 22:46:18 +01:00
"duckduckgo" : {
2023-12-20 02:06:05 +01:00
Name : "duckduckgo" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "duckduckgo" , "ddg" } ,
Description : "Returns the duckduckgo search URL for a given query." ,
Level : "0" ,
Usage : "()duckduckgo <query>" ,
} ,
"ffz" : {
2023-12-20 02:06:05 +01:00
Name : "ffz" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "ffz" , "frankerfacez" } ,
Description : "Returns the search URL for a given FFZ emote." ,
Level : "0" ,
Usage : "()ffz <emote name>" ,
} ,
"firstline" : {
2023-12-20 02:06:05 +01:00
Name : "firstline" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "firstline" , "fl" } ,
Description : "Returns the first message a user has sent in a channel" ,
Level : "0" ,
Usage : "()firstline <channel> <username>" ,
} ,
"followage" : {
2023-12-20 02:06:05 +01:00
Name : "followage" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "followage" , "fa" } ,
Description : "Returns how long a user has been following a channel." ,
Level : "0" ,
Usage : "()followage <channel> <username>" ,
} ,
"godocs" : {
2023-12-20 02:06:05 +01:00
Name : "godocs" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns the godocs.io search URL for a given query." ,
Level : "0" ,
Usage : "()godoc <query>" ,
} ,
"gofile" : {
2023-12-20 02:06:05 +01:00
Name : "gofile" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Downloads the video of a given link with yt-dlp and then uploads the video to gofile.io." ,
Level : "420" ,
Usage : "()gofile <link>" ,
} ,
"google" : {
2023-12-20 02:06:05 +01:00
Name : "google" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns the google search URL for a given query." ,
Level : "0" ,
Usage : "()google <query>" ,
} ,
"help" : {
2023-12-20 02:06:05 +01:00
Name : "help" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns more information about a command 4Head." ,
Level : "0" ,
Usage : "()help <command name>" ,
} ,
"join" : {
2023-12-20 02:06:05 +01:00
Name : "join" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Adds the bot to a given channel." ,
Level : "1000" ,
Usage : "()join <channel name>" ,
} ,
"kappa" : {
2023-12-20 02:06:05 +01:00
Name : "kappa" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Downloads the video of a given link with yt-dlp and then uploads the video to kappa.lol." ,
Level : "420" ,
Usage : "()kappa <link>" ,
} ,
"lastfm" : {
2023-12-20 02:06:05 +01:00
Name : "lastfm" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : ` Look up the last played title for a user on last.fm. If you "$set lastfm" a last.fm username the command will use that username if no other username is specified. ` ,
Level : "0" ,
Usage : "()lastfm [username]" ,
} ,
"osrs" : {
2023-12-20 02:06:05 +01:00
Name : "osrs" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns the oldschool runescape wiki search URL for a given query." ,
Level : "0" ,
Usage : "()osrs <query>" ,
} ,
"part" : {
2023-12-20 02:06:05 +01:00
Name : "part" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Removes the bot from a given channel." ,
Level : "1000" ,
Usage : "()part <channel name>" ,
} ,
"phonetic" : {
2023-12-20 02:06:05 +01:00
Name : "phonetic" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "phonetic" , "ph" } ,
Description : "Translates the input to the character equivalent on a phonetic russian keyboard layout. Layout and general functionality is the same as on https://russian.typeit.org/" ,
Level : "0" ,
Usage : "()phonetic <input>" ,
} ,
"ping" : {
2023-12-20 02:06:05 +01:00
Name : "ping" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Hopefully returns a pong monkaS." ,
Level : "0" ,
Usage : "()ping" ,
} ,
"preview" : {
2023-12-20 02:06:05 +01:00
Name : "preview" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "preview" , "thumbnail" } ,
Description : "Returns a link to an (almost) live screenshot of a live channel." ,
Level : "0" ,
Usage : "()thumbnail <channel>" ,
} ,
"randomxkcd" : {
2023-12-20 02:06:05 +01:00
Name : "randomxkcd" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "randomxkcd" , "rxkcd" } ,
Description : "Returns a link to a random xkcd comic." ,
Level : "0" ,
Usage : "()randomxkcd" ,
} ,
"seventv" : {
2023-12-20 02:06:05 +01:00
Name : "seventv" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "seventv" , "7tv" } ,
Description : "Returns the search URL for a given SevenTV emote." ,
Level : "0" ,
Usage : "()seventv <emote name>" ,
} ,
"set lastfm" : {
2023-12-20 02:06:05 +01:00
Name : "set lastfm" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Allows you to set a last.fm username that will be used for $lastfm lookups if no other username is specified." ,
Level : "0" ,
Usage : "()set lastfm <username>" ,
} ,
"set location" : {
2023-12-20 02:06:05 +01:00
Name : "set location" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Allows you to set a location that will be used for $weather lookups if no other location is specified." ,
Level : "0" ,
Usage : "()set location <location>" ,
} ,
"timer add" : {
2023-12-20 02:06:05 +01:00
Name : "timer add" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Adds a new timer to the channel." ,
Level : "500" ,
Usage : "()timer add <name> <repeat> <text>" ,
} ,
"timer delete" : {
2023-12-20 02:06:05 +01:00
Name : "timer delete" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Deletes a timer from the channel." ,
Level : "500" ,
Usage : "()timer delete <name>" ,
} ,
2023-12-17 23:15:21 +01:00
"timer edit" : {
2023-12-20 02:06:05 +01:00
Name : "timer edit" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
2023-12-17 23:15:21 +01:00
Description : "Edits a timer from the channel." ,
Level : "500" ,
Usage : "()timer edit <name> <repeat> <text>" ,
2023-12-17 22:46:18 +01:00
} ,
"timers" : {
2023-12-20 02:06:05 +01:00
Name : "timers" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns a link to the currently active timers in the channel." ,
Level : "0" ,
Usage : "()timers" ,
} ,
"user edit level" : {
2023-12-20 02:06:05 +01:00
Name : "user edit level" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "user set level" } ,
Description : "Edits the user level for a given username." ,
Level : "1000" ,
Usage : "()user edit level <username> <level>" ,
} ,
"uid" : {
2023-12-20 02:06:05 +01:00
Name : "uid" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "uid" , "userid" } ,
Description : "Returns the Twitch user ID for a given username." ,
Level : "0" ,
Usage : "()uid <username>" ,
} ,
"wa" : {
2023-12-20 02:06:05 +01:00
Name : "wa" ,
2023-12-17 22:46:18 +01:00
Alias : [ ] string { "wa" , "query" } ,
Description : "Queries the Wolfram|Alpha API about the input." ,
Level : "100" ,
Usage : "()wa <input>" ,
} ,
"weather" : {
2023-12-20 02:06:05 +01:00
Name : "weather" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : ` Returns the weather for a given location. If you "$set location" your location, the command will use that location if no other location is specified. ` ,
Level : "0" ,
Usage : "()weather [location]" ,
} ,
"xkcd" : {
2023-12-20 02:06:05 +01:00
Name : "xkcd" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Returns the link to the latest xkcd comic." ,
Level : "0" ,
Usage : "()xkcd" ,
} ,
"yaf" : {
2023-12-20 02:06:05 +01:00
Name : "yaf" ,
2023-12-17 22:46:18 +01:00
Alias : nil ,
Description : "Downloads the video of a given link with yt-dlp and then uploads the video to yaf.li." ,
Level : "420" ,
Usage : "()yaf <link>" ,
} ,
2023-10-10 13:16:30 +02:00
}
// Help checks if a help text for a given command exists and replies with it.
2023-10-10 17:51:12 +02:00
func ( app * application ) commandHelp ( target , name , username string , message twitch . PrivateMessage ) {
2023-10-10 13:16:30 +02:00
// Check if the `helpText` map has an entry for `name`. If it does return it's value entry
// and send that as a reply.
i , ok := helpText [ name ]
if ! ok {
// If it doesn't check the database for a command with that `name`. If there is one
// reply with that commands `help` entry.
2023-12-18 00:04:27 +01:00
c , err := app . GetCommandDescription ( name , target , username )
2023-10-10 13:16:30 +02:00
if err != nil {
app . Log . Infow ( "commandHelp: no such command found" ,
"err" , err )
return
}
2023-10-10 17:51:12 +02:00
app . Send ( target , c , message )
2023-10-10 13:16:30 +02:00
return
}
2023-12-17 22:46:18 +01:00
app . Send ( target , i . Description , message )
2023-10-10 13:16:30 +02:00
}
2023-12-17 21:01:14 +01:00
// Help checks if a help text for a given command exists and replies with it.
func ( app * application ) GetAllHelpText ( ) string {
// The slice of timers is only used to log them at
// the start so it looks a bit nicer.
var cs [ ] string
// Iterate over all timers and then add them onto the scheduler.
for i , v := range helpText {
// idk why this works but it does so no touchy touchy.
// https://github.com/robfig/cron/issues/420#issuecomment-940949195
i , v := i , v
_ = i
var c string
2023-12-17 22:46:18 +01:00
if v . Alias == nil {
2023-12-18 00:04:27 +01:00
c = fmt . Sprintf ( "Name: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n" , i , v . Description , v . Level , v . Usage )
2023-12-17 22:46:18 +01:00
} else {
2023-12-18 00:04:27 +01:00
c = fmt . Sprintf ( "Name: %s\nAliases: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n" , i , v . Alias , v . Description , v . Level , v . Usage )
2023-12-17 22:46:18 +01:00
}
2023-12-17 21:01:14 +01:00
// Add new value to the slice
cs = append ( cs , c )
}
sort . Strings ( cs )
return strings . Join ( cs , "" )
}