mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Small fixes and rework of poll
This commit is contained in:
parent
8142709581
commit
6ea052ae6f
4 changed files with 68 additions and 34 deletions
|
@ -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: "<question>",
|
||||
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}`);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
@ -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()
|
||||
})}`
|
||||
);
|
||||
|
|
|
@ -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: "<question>",
|
||||
usage: "(<seconds>) <question>",
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue