Add a reset vote command

This commit is contained in:
Oliver-Akins 2021-12-24 03:43:48 -07:00
parent f95063274f
commit cda0544c0a

26
src/commands/reset.ts Normal file
View file

@ -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;