From b6898b63efea86d670844a28f29a7a8860787e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 6 Oct 2022 13:16:32 +0200 Subject: [PATCH] static_commands: Add commands list Preconfigured commands are still missing from this list. --- static_commands.go | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/static_commands.go b/static_commands.go index 5f45433..ff67f65 100644 --- a/static_commands.go +++ b/static_commands.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "errors" + "fmt" "log" "strings" @@ -12,15 +13,49 @@ import ( var errTooShort = errors.New("input too short") func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error { - if !b.isAuthorized(&msg.User, msg.Channel) { - return errNotAuthorized - } - if len(parsed) == 1 || parsed[1] == "list" { - // TODO: List all + var commands []string + // TODO: Add preconfigured commands like elo + query := ` + SELECT name + FROM static_commands + WHERE channel = $1` + + rows, err := b.db.DB.Query(query, msg.Channel) + if err != nil { + return err + } + defer rows.Close() + + for rows.Next() { + var command string + if err := rows.Scan(&command); err != nil { + return err + } + + commands = append(commands, command) + } + + if err = rows.Err(); err != nil { + return err + } + + var text string + for i, command := range commands { + text += fmt.Sprintf("!%s", command) + if i < len(commands)-1 { + text += ", " + } + } + + b.say(msg, text) return nil } + if !b.isAuthorized(&msg.User, msg.Channel) { + return errNotAuthorized + } + editCommands := [4]string{"edit", "update", "create", "add"} for _, cmd := range editCommands { if parsed[1] == cmd { -- 2.44.0