From e9c911832140013a796bfd439e1f813343142ec1 Mon Sep 17 00:00:00 2001 From: nouryxd <66651385+nouryxd@users.noreply.github.com> Date: Thu, 16 May 2024 15:52:02 +0200 Subject: [PATCH] fix out of bounds crash for meme and conv command --- cmd/nourybot/commands.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index fe82428..69896ff 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -227,16 +227,6 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { return } - case "conv": - if userLevel >= 100 { - app.ConvertToMP4(cmdParams[1], message) - } - - case "meme": - if userLevel >= 100 { - app.ConvertAndSave(cmdParams[1], cmdParams[2], message) - } - case "set": switch cmdParams[1] { case "lastfm": @@ -380,6 +370,24 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { // 1000 User Level // Admin //------------------------------------ + case "conv": + if userLevel >= 1000 { + if msgLen > 1 { + reply = "Not enough arguments provided" + } else if msgLen == 2 { + app.ConvertToMP4(cmdParams[1], message) + } + } + + case "meme": + if userLevel < 1000 { // Unauthorized + return + } else if userLevel >= 1000 && msgLen <= 2 { // Authorized but not enough args. + reply = "Not enough arguments provided." + } else if userLevel >= 1000 && msgLen >= 3 { + app.ConvertAndSave(cmdParams[1], cmdParams[2], message) + } + case "say": if userLevel >= 1000 { reply = message.Message[6:len(message.Message)]