From cda0544c0afe5732872595ad482fe0e4631bd0dd Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Fri, 24 Dec 2021 03:43:48 -0700 Subject: [PATCH] Add a reset vote command --- src/commands/reset.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/commands/reset.ts diff --git a/src/commands/reset.ts b/src/commands/reset.ts new file mode 100644 index 0000000..bc2e93a --- /dev/null +++ b/src/commands/reset.ts @@ -0,0 +1,26 @@ +import { user_answers, commands, question_index, questions } from "../main"; + + +function reset_command(args: string[]) { + + if (question_index < 0) { + return `Cannot reset a user's answer for a question when the quiz hasn't begun`; + }; + + if (questions[question_index].can_change) { + return `${args[0]} can change their own answer by answering again.`; + }; + + if (args.length == 0) { + return `Missing argument: User`; + }; + + let user = args[0].startsWith("@") ? args[0].slice(1) : args[0]; + + delete user_answers[user]; + + return `The answer for @${user} has been removed`; +}; + + +commands["!reset"] = reset_command; \ No newline at end of file