From e444225b2cd2a37569b5a3f68ef302bbd8a2a55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 6 Oct 2022 13:41:22 +0200 Subject: [PATCH] static_commands: Protect built-in commands --- functions.go | 11 +++++++++++ static_commands.go | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 functions.go diff --git a/functions.go b/functions.go new file mode 100644 index 0000000..8395f8e --- /dev/null +++ b/functions.go @@ -0,0 +1,11 @@ +package main + +func sliceContains(s []string, e string) bool { + for _, v := range s { + if e == v { + return true + } + } + + return false +} diff --git a/static_commands.go b/static_commands.go index 51bd2f3..b8ff07a 100644 --- a/static_commands.go +++ b/static_commands.go @@ -66,6 +66,12 @@ func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error name := strings.TrimLeft(parsed[2], "!") resp := strings.Join(parsed[3:], " ") + // check if built-in commands use this name + if sliceContains(faceitCommands(), name) { + b.say(msg, "Cannot override built-in command.") + return nil + } + query := ` INSERT INTO static_commands (channel, name, response) VALUES ($1, $2, $3) @@ -83,6 +89,12 @@ func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error if parsed[1] == "delete" { name := strings.TrimLeft(parsed[2], "!") + // check if built-in commands use this name + if sliceContains(faceitCommands(), name) { + b.say(msg, "Cannot delete built-in command.") + return nil + } + query := ` DELETE FROM static_commands WHERE channel = $1 AND name = $2` -- 2.44.0