mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add commands
This commit is contained in:
parent
833eee0c99
commit
cf4e4b64e4
3 changed files with 31 additions and 5 deletions
|
@ -35,4 +35,7 @@ func main() {
|
|||
|
||||
handlers.PrivateMessage(message, nb)
|
||||
})
|
||||
|
||||
nb.TwitchClient.Join("nourybot")
|
||||
nb.TwitchClient.Connect()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -9,6 +11,30 @@ import (
|
|||
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||
logrus.Info("fn Command")
|
||||
|
||||
nb.Send("nourybot", "xd")
|
||||
// commandName is the actual command name without the prefix.
|
||||
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
|
||||
|
||||
// cmdParams are additional command inputs.
|
||||
// example:
|
||||
// weather san antonio
|
||||
// is
|
||||
// commandName cmdParams[0] cmdParams[1]
|
||||
cmdParams := strings.SplitN(message.Message, " ", 500)
|
||||
|
||||
// msgLen is the amount of words in the message without the prefix.
|
||||
// Useful for checking if enough cmdParams are given.
|
||||
msgLen := len(strings.SplitN(message.Message, " ", -2))
|
||||
|
||||
switch commandName {
|
||||
case "":
|
||||
if msgLen == 1 {
|
||||
nb.Send(message.Channel, "xd")
|
||||
}
|
||||
case "echo":
|
||||
if msgLen != 1 {
|
||||
nb.Send(message.Channel, cmdParams[1])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
// PrivateMessage is a command or not and passes it on accordingly.
|
||||
// Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua
|
||||
func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||
log.Info("fn HandlePrivateMessage")
|
||||
log.Info("fn PrivateMessage")
|
||||
// log.Info(message)
|
||||
|
||||
// roomId is the Twitch UserID of the channel the message
|
||||
|
@ -24,9 +24,6 @@ func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
|
|||
return
|
||||
}
|
||||
|
||||
// Message was sent from the Bot. Don't act on it
|
||||
// so that we don't repeat ourself.
|
||||
|
||||
// Since our command prefix is () ignore every message
|
||||
// that is less than 2
|
||||
if len(message.Message) >= 2 {
|
||||
|
|
Loading…
Reference in a new issue