From 4a4e34a929db3bcef5c692d8c28e0467fdd91353 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Thu, 11 Aug 2022 01:29:17 +0200 Subject: [PATCH] add comments explaining funky logic --- cmd/bot/commands.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/bot/commands.go b/cmd/bot/commands.go index cc8030e..5dc52e1 100644 --- a/cmd/bot/commands.go +++ b/cmd/bot/commands.go @@ -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)