2021-04-12 09:07:04 +00:00
|
|
|
|
import {MessageEmbed, Message, User} from "discord.js";
|
2021-04-13 12:38:52 +00:00
|
|
|
|
import {NamedCommand, RestCommand, poll, CHANNEL_TYPE, SendFunction, Command} from "onion-lasers";
|
2021-04-12 09:07:04 +00:00
|
|
|
|
import {pluralise} from "../../lib";
|
2020-08-17 17:38:15 +00:00
|
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
|
export default new NamedCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
|
description: "Create a poll.",
|
2021-04-12 09:07:04 +00:00
|
|
|
|
usage: "(<seconds>) <question>",
|
2020-12-15 01:44:28 +00:00
|
|
|
|
run: "Please provide a question.",
|
2021-04-12 09:07:04 +00:00
|
|
|
|
channelType: CHANNEL_TYPE.GUILD,
|
|
|
|
|
number: new Command({
|
|
|
|
|
run: "Please provide a question in addition to the provided duration.",
|
|
|
|
|
any: new RestCommand({
|
|
|
|
|
description: "Question for the poll.",
|
|
|
|
|
async run({send, message, author, args, combined}) {
|
2021-05-06 13:30:51 +00:00
|
|
|
|
execPoll(send, message, author, combined, args[0] * 1000);
|
2021-04-12 09:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}),
|
2021-04-10 17:07:55 +00:00
|
|
|
|
any: new RestCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
|
description: "Question for the poll.",
|
2021-04-12 09:07:04 +00:00
|
|
|
|
async run({send, message, author, combined}) {
|
|
|
|
|
execPoll(send, message, author, combined);
|
2020-12-15 01:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
2020-10-15 09:23:24 +00:00
|
|
|
|
});
|
2021-04-12 09:07:04 +00:00
|
|
|
|
|
|
|
|
|
const AGREE = "✅";
|
|
|
|
|
const DISAGREE = "⛔";
|
|
|
|
|
|
|
|
|
|
async function execPoll(send: SendFunction, message: Message, user: User, question: string, duration = 60000) {
|
|
|
|
|
const icon =
|
|
|
|
|
user.avatarURL({
|
|
|
|
|
dynamic: true,
|
|
|
|
|
size: 2048
|
|
|
|
|
}) || user.defaultAvatarURL;
|
2021-10-29 12:52:46 +00:00
|
|
|
|
const msg = await send({
|
|
|
|
|
embeds: [
|
|
|
|
|
new MessageEmbed()
|
|
|
|
|
.setAuthor(`Poll created by ${message.author.username}`, icon)
|
|
|
|
|
.setColor(0xffffff)
|
|
|
|
|
.setFooter("React to vote.")
|
|
|
|
|
.setDescription(question)
|
|
|
|
|
]
|
|
|
|
|
});
|
2021-04-12 09:07:04 +00:00
|
|
|
|
const results = await poll(msg, [AGREE, DISAGREE], duration);
|
2021-10-29 12:52:46 +00:00
|
|
|
|
send({
|
|
|
|
|
embeds: [
|
|
|
|
|
new MessageEmbed()
|
|
|
|
|
.setAuthor(`The results of ${message.author.username}'s poll:`, icon)
|
|
|
|
|
.setTitle(question)
|
|
|
|
|
.setDescription(
|
|
|
|
|
`${AGREE} - ${pluralise(
|
|
|
|
|
results[AGREE],
|
|
|
|
|
"",
|
|
|
|
|
"people who agree",
|
|
|
|
|
"person who agrees"
|
|
|
|
|
)}\n${DISAGREE} - ${pluralise(
|
|
|
|
|
results[DISAGREE],
|
|
|
|
|
"",
|
|
|
|
|
"people who disagree",
|
|
|
|
|
"person who disagrees"
|
|
|
|
|
)}`
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
});
|
2021-04-12 09:07:04 +00:00
|
|
|
|
msg.delete();
|
|
|
|
|
}
|