Migrate poll command

This commit is contained in:
Ethan Lane 2021-11-29 15:34:57 +00:00
parent 0d3134bf45
commit e7169d960a
Signed by: Vylpes
GPG key ID: EED233CC06D12504
3 changed files with 56 additions and 210 deletions

56
src/commands/poll.ts Normal file
View file

@ -0,0 +1,56 @@
import { Command, ICommandContext } from "vylbot-core";
import ErrorEmbed from "../helpers/ErrorEmbed";
import PublicEmbed from "../helpers/PublicEmbed";
export default class Poll extends Command {
constructor() {
super();
super._category = "General";
}
public override async execute(context: ICommandContext) {
const argsJoined = context.args.join(" ");
const argsSplit = argsJoined.split(";");
if (argsSplit.length < 3 || argsSplit.length > 10) {
const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options");
errorEmbed.SendToCurrentChannel();
return;
}
const title = argsSplit[0];
const arrayOfNumbers = [
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:'
];
const reactionEmojis = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
const description = arrayOfNumbers.splice(0, argsSplit.length - 1);
description.forEach((value, index) => {
description[index] = `${value} ${argsSplit[index + 1]}`;
});
const embed = new PublicEmbed(context, title, description.join("\n"));
const message = await context.message.channel.send(embed);
description.forEach(async (value, index) => {
await message.react(reactionEmojis[index]);
});
if (context.message.deletable) {
await context.message.delete({ reason: "Poll command" });
}
}
}