Migrate poll command
This commit is contained in:
parent
0d3134bf45
commit
e7169d960a
3 changed files with 56 additions and 210 deletions
56
src/commands/poll.ts
Normal file
56
src/commands/poll.ts
Normal 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" });
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue