JaBa/commands/Moderation/poll.js

109 lines
2.8 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Discord = require("discord.js");
class Poll extends Command {
constructor(client) {
super(client, {
name: "poll",
dirname: __dirname,
enabled: true,
guildOnly: true,
2022-01-05 22:04:46 +05:00
aliases: ["po"],
2022-01-04 02:18:28 +05:00
memberPermissions: ["MANAGE_MESSAGES"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
const question = args.join(" ");
if (!question) return message.error("moderation/poll:MISSING_QUESTION");
let mention = null;
2022-02-25 00:56:32 +05:00
const msg = await message.sendT("moderation/announcement:MENTION_PROMPT");
const filter = m => m.author.id === message.author.id;
const collector = new Discord.MessageCollector(message.channel, {
filter,
2022-01-04 02:18:28 +05:00
time: 240000
});
collector.on("collect", async (tmsg) => {
if (tmsg.content.toLowerCase() === message.translate("common:NO").toLowerCase()) {
tmsg.delete();
msg.delete();
collector.stop(true);
2022-02-15 01:34:39 +05:00
message.delete();
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
if (tmsg.content.toLowerCase() === message.translate("common:YES").toLowerCase()) {
tmsg.delete();
msg.delete();
2022-02-15 01:40:18 +05:00
const tmsg1 = await message.channel.send(message.translate("moderation/announcement:MENTION_TYPE_PROMPT"));
const filter = m => m.author.id === message.author.id;
const c = new Discord.MessageCollector(message.channel, {
filter,
2022-01-04 02:18:28 +05:00
time: 60000
});
c.on("collect", (m) => {
if (m.content.toLowerCase() === "here") {
mention = "@here";
tmsg1.delete();
m.delete();
collector.stop(true);
c.stop(true);
2022-02-15 01:26:29 +05:00
} else if (m.content.toLowerCase() === "everyone") {
2022-01-04 02:18:28 +05:00
mention = "@everyone";
tmsg1.delete();
m.delete();
collector.stop(true);
c.stop(true);
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
});
2022-02-15 01:34:39 +05:00
2022-01-04 02:18:28 +05:00
c.on("end", (collected, reason) => {
2022-02-15 01:34:39 +05:00
if (reason === "time") return message.error("misc:TIMES_UP");
2022-01-04 02:18:28 +05:00
});
2022-02-15 01:34:39 +05:00
message.delete();
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
});
collector.on("end", (collected, reason) => {
if (reason === "time") return message.error("misc:TIMES_UP");
const success = this.client.customEmojis.success.split(":")[1];
const error = this.client.customEmojis.error.split(":")[1];
const emojis = [
this.client.emojis.cache.find(e => e.name === success),
this.client.emojis.cache.find(e => e.name === error)
2022-01-04 02:18:28 +05:00
];
const embed = new Discord.MessageEmbed()
.setAuthor({
name: message.translate("moderation/poll:TITLE")
})
2022-01-04 02:18:28 +05:00
.setColor(data.config.embed.color)
.addField(question, message.translate("moderation/poll:REACT", {
success: emojis[0].toString(),
error: emojis[1].toString()
}));
message.channel.send({
content: mention,
embeds: [embed]
}).then(async (m) => {
2022-01-04 02:18:28 +05:00
await m.react(emojis[0]);
await m.react(emojis[1]);
});
});
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Poll;