mirror of
https://github.com/lyx0/ollama-twitch-bot.git
synced 2024-11-06 18:52:03 +01:00
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gempir/go-twitch-irc/v4"
|
|
)
|
|
|
|
// 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) {
|
|
var reply string
|
|
|
|
// 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))
|
|
|
|
// commandName is the actual name of the command without the prefix.
|
|
// e.g. `()gpt` is `gpt`.
|
|
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
|
|
switch commandName {
|
|
case "gpt":
|
|
if msgLen < 2 {
|
|
reply = "Not enough arguments provided. Usage: ()gpt <query>"
|
|
} else {
|
|
switch app.OllamaContext {
|
|
case "none":
|
|
app.generateNoContext(message.Channel, message.Message[6:len(message.Message)])
|
|
return
|
|
|
|
case "general":
|
|
app.chatGeneralContext(message.Channel, message.Message[6:len(message.Message)])
|
|
return
|
|
|
|
case "user":
|
|
app.chatUserContext(message.Channel, message.User.Name, message.Message[6:len(message.Message)])
|
|
return
|
|
}
|
|
}
|
|
if reply != "" {
|
|
go app.Send(message.Channel, reply)
|
|
return
|
|
}
|
|
}
|
|
}
|