From c560490cc1457f7f2cebece7c2aa5f3bd83a36dc Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 13 Mar 2022 13:56:32 -0600 Subject: added editcommand --- twitch-bot/bot.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/twitch-bot/bot.js b/twitch-bot/bot.js index 0399a1b..9d383e3 100644 --- a/twitch-bot/bot.js +++ b/twitch-bot/bot.js @@ -170,10 +170,11 @@ function createCommand(target) { var command_reply = ""; for (int i = 2; i < fullMessage.length; i++) { command_reply = command_reply + fullMessage[i] + " "; + } chat_commands.push(['command': fullMessage[1], 'reply': command_reply]); try { const data = JSON.stringify(chat_commands, null, 4); - fs.writeFileSync('user.json', data); + fs.writeFileSync('commands.json', data); console.log('* Added command ' + settings.command_char + fullMessage[1]); client.say(target, `Successfully added command: ${settings.command_char}${fullMessage[1]}`); } catch (err) { @@ -183,7 +184,26 @@ function createCommand(target) { } function editCommand(target) { - + chat_commands.forEach(command => { + if (fullMessage[1].search(command.command) !== -1) { + var command_reply = ""; + for (int i = 2; i < fullMessage.length; i++) { + command_reply = command_reply + fullMessage[i] + " "; + } + chat_commands[fullMessage[1]] = command_reply; + try { + const data = JSON.stringify(chat_commands, null, 4); + fs.writeFileSync('commands.json', data); + console.log('* Edited command ' + settings.command_char + fullMessage[1]); + client.say(target, `Successfully edited existing command: ${settings.command_char}${fullMessage[1]}`); + } catch (err) { + console.error('An error occured trying to run !editcommand: ' + err); + client.say(target, `Something went wrong editing this command, please try again later.`); + } + return true; + } + }); + return false; } function reactions (target, message, user) { -- cgit v1.2.3