diff --git a/src/commands/fun/8ball.ts b/src/commands/fun/8ball.ts index f79a2c0..66d2aa6 100644 --- a/src/commands/fun/8ball.ts +++ b/src/commands/fun/8ball.ts @@ -1,4 +1,4 @@ -import {Command, NamedCommand} from "../../core"; +import {NamedCommand, RestCommand} from "../../core"; import {random} from "../../lib"; const responses = [ @@ -28,11 +28,10 @@ export default new NamedCommand({ description: "Answers your question in an 8-ball manner.", usage: "", run: "Please provide a question.", - any: new Command({ + any: new RestCommand({ description: "Question to ask the 8-ball.", - async run({send, message}) { - const sender = message.author; - send(`${random(responses)} <@${sender.id}>`); + async run({send, author}) { + send(`${random(responses)} ${author}`); } }) }); diff --git a/src/commands/fun/cookie.ts b/src/commands/fun/cookie.ts index 71d9c20..3ca68b9 100644 --- a/src/commands/fun/cookie.ts +++ b/src/commands/fun/cookie.ts @@ -40,13 +40,12 @@ export default new NamedCommand({ user: new Command({ description: "User to give cookie to.", async run({send, author, args}) { - const sender = author; const mention: User = args[0]; - if (mention.id == sender.id) return send("You can't give yourself cookies!"); + if (mention.id == author.id) return send("You can't give yourself cookies!"); return send( - `:cookie: <@${sender.id}> ${parseVars(random(cookies), { + `:cookie: ${author} ${parseVars(random(cookies), { target: mention.toString() })}` ); diff --git a/src/commands/fun/poll.ts b/src/commands/fun/poll.ts index 3909968..5e48a60 100644 --- a/src/commands/fun/poll.ts +++ b/src/commands/fun/poll.ts @@ -1,27 +1,58 @@ -import {MessageEmbed} from "discord.js"; -import {NamedCommand, RestCommand} from "../../core"; +import {MessageEmbed, Message, User} from "discord.js"; +import {NamedCommand, RestCommand, poll, CHANNEL_TYPE, SendFunction, Command} from "../../core"; +import {pluralise} from "../../lib"; export default new NamedCommand({ description: "Create a poll.", - usage: "", + usage: "() ", run: "Please provide a question.", + 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}) { + execPoll(send, message, author, combined, args[0]); + } + }) + }), any: new RestCommand({ description: "Question for the poll.", - async run({send, message, combined}) { - const embed = new MessageEmbed() - .setAuthor( - `Poll created by ${message.author.username}`, - message.guild?.iconURL({dynamic: true}) ?? undefined - ) - .setColor(0xffffff) - .setFooter("React to vote.") - .setDescription(combined); - const msg = await send(embed); - await msg.react("✅"); - await msg.react("⛔"); - message.delete({ - timeout: 1000 - }); + async run({send, message, author, combined}) { + execPoll(send, message, author, combined); } }) }); + +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; + const msg = await send( + new MessageEmbed() + .setAuthor(`Poll created by ${message.author.username}`, icon) + .setColor(0xffffff) + .setFooter("React to vote.") + .setDescription(question) + ); + const results = await poll(msg, [AGREE, DISAGREE], duration); + send( + 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")}` + ) + ); + msg.delete(); +} diff --git a/src/commands/utility/invite.ts b/src/commands/utility/invite.ts index 58b38d8..d0eb559 100644 --- a/src/commands/utility/invite.ts +++ b/src/commands/utility/invite.ts @@ -1,12 +1,17 @@ -import {NamedCommand} from "../../core"; +import {Command, NamedCommand} from "../../core"; export default new NamedCommand({ description: "Gives you the invite link.", - async run({send, client, args}) { - send( - `https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${ - args[0] || 8 - }&scope=bot` - ); - } + async run({send, client}) { + send(`https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=8&scope=bot`); + }, + number: new Command({ + async run({send, client, args}) { + send( + `https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${ + args[0] + }&scope=bot` + ); + } + }) });