add comments explaining funky logic

This commit is contained in:
lyx0 2022-08-11 01:29:17 +02:00
parent 841025cac0
commit 4a4e34a929

View file

@ -8,14 +8,21 @@ import (
)
func (app *Application) AddCommand(name string, message twitch.PrivateMessage) {
// text1 := strings.Split(message.Message, name)
// prefixLength is the length of `()addcommand` plus +2 (for the space and zero based)
prefixLength := 14
text := message.Message[14+len(name) : len(message.Message)]
app.Logger.Infow("Message splits",
"Command Name:", name,
"Command Text:", text)
// Split the twitch message at the length of the prefix + the length of the name of the command.
// prefixLength |name| text
// 0123456789012|4567|
// e.g. ()addcommand dank FeelsDankMan
// | snip ^ |
text := message.Message[prefixLength+len(name) : len(message.Message)]
err := app.Models.Commands.Insert(name, text)
// app.Logger.Infow("Message splits",
// "Command Name:", name,
// "Command Text:", text)
if err != nil {
reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err)
common.Send(message.Channel, reply, app.TwitchClient)