2021-12-10 21:39:54 +05:00
|
|
|
const Command = require("../../base/Command.js"),
|
|
|
|
ms = require("ms");
|
|
|
|
|
|
|
|
class Giveaway extends Command {
|
|
|
|
constructor (client) {
|
|
|
|
super(client, {
|
|
|
|
name: "giveaway",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
|
|
|
aliases: [ "gway" ],
|
|
|
|
memberPermissions: [ "MENTION_EVERYONE" ],
|
|
|
|
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ],
|
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
|
|
|
cooldown: 5000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run (message, args, data) {
|
|
|
|
const status = args[0];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!status)return message.error("moderation/giveaway:MISSING_STATUS");
|
2021-12-10 21:39:54 +05:00
|
|
|
|
2021-12-11 01:11:50 +05:00
|
|
|
if (status === "create") {
|
2021-12-10 21:39:54 +05:00
|
|
|
const currentGiveaways = this.client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id && !g.ended).length;
|
2021-12-11 01:11:50 +05:00
|
|
|
if (currentGiveaways > 3) return message.error("moderation/giveaway:MAX_COUNT");
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
const time = args[1];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!time) return message.error("moderation/giveaway:INVALID_CREATE", { prefix: data.guild.prefix });
|
|
|
|
if (isNaN(ms(time))) return message.error("misc:INVALID_TIME");
|
|
|
|
if (ms(time) > ms("15d")) return message.error("moderation/giveaway:MAX_DURATION");
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
const winnersCount = args[2];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!winnersCount) return message.error("moderation/giveaway:INVALID_CREATE", { prefix: data.guild.prefix });
|
|
|
|
if (isNaN(winnersCount) || winnersCount > 10 || winnersCount < 1) return message.error("misc:INVALID_NUMBER_RANGE", { min: 1, max: 10 });
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
const prize = args.slice(3).join(" ");
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!prize) return message.error("moderation/giveaway:INVALID_CREATE", { prefix: data.guild.prefix });
|
2021-12-10 21:39:54 +05:00
|
|
|
this.client.giveawaysManager.start(message.channel, {
|
|
|
|
time: ms(time),
|
|
|
|
prize: prize,
|
|
|
|
winnerCount: parseInt(winnersCount, 10),
|
|
|
|
messages: {
|
|
|
|
giveaway: message.translate("moderation/giveaway:TITLE"),
|
|
|
|
giveawayEnded: message.translate("moderation/giveaway:ENDED"),
|
|
|
|
timeRemaining: message.translate("moderation/giveaway:TIME_REMAINING"),
|
|
|
|
inviteToParticipate: message.translate("moderation/giveaway:INVITE_PARTICIPATE"),
|
|
|
|
winMessage: message.translate("moderation/giveaway:WIN_MESSAGE"),
|
|
|
|
embedFooter: message.translate("moderation/giveaway:FOOTER"),
|
|
|
|
noWinner: message.translate("moderation/giveaway:NO_WINNER"),
|
|
|
|
winners: message.translate("moderation/giveaway:WINNERS"),
|
|
|
|
endedAt: message.translate("moderation/giveaway:END_AT"),
|
|
|
|
units: {
|
|
|
|
seconds: message.translate("time:SECONDS", { amount: "" }).trim(),
|
|
|
|
minutes: message.translate("time:MINUTES", { amount: "" }).trim(),
|
|
|
|
hours: message.translate("time:HOURS", { amount: "" }).trim(),
|
|
|
|
days: message.translate("time:DAYS", { amount: "" }).trim()
|
2021-12-11 01:11:50 +05:00
|
|
|
}
|
2021-12-10 21:39:54 +05:00
|
|
|
}
|
|
|
|
}).then(() => {
|
|
|
|
message.success("moderation/giveaway:GIVEAWAY_CREATED");
|
|
|
|
});
|
|
|
|
} else if(status === "reroll"){
|
|
|
|
const messageID = args[1];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!messageID)return message.error("moderation/giveaway:MISSING_ID");
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
this.client.giveawaysManager.reroll(messageID, {
|
|
|
|
congrat: message.translate("moderation/giveaway:REROLL_CONGRAT"),
|
|
|
|
error: message.translate("moderation/giveaway:REROLL_ERROR")
|
|
|
|
}).then(() => {
|
|
|
|
return message.success("moderation/giveaway:GIVEAWAY_REROLLED");
|
|
|
|
}).catch(() => {
|
2021-12-11 01:11:50 +05:00
|
|
|
return message.error("moderation/giveaway:NOT_FOUND_ENDED", { messageID });
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
} else if(status === "delete"){
|
|
|
|
const messageID = args[1];
|
2021-12-11 01:11:50 +05:00
|
|
|
if(!messageID) return message.error("moderation/giveaway:MISSING_ID");
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
this.client.giveawaysManager.delete(messageID).then(() => {
|
|
|
|
return message.success("moderation/giveaway:GIVEAWAY_DELETED");
|
|
|
|
}).catch(() => {
|
2021-12-11 01:11:50 +05:00
|
|
|
return message.error("moderation/giveaway:NOT_FOUND", { messageID });
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
} else if(status === "end"){
|
|
|
|
const messageID = args[1];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!messageID) return message.error("moderation/giveaway:MISSING_ID");
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
try {
|
2021-12-11 01:11:50 +05:00
|
|
|
this.client.giveawaysManager.edit(messageID, { setEndTimestamp: Date.now() });
|
2021-12-10 21:39:54 +05:00
|
|
|
return message.success("moderation/giveaway:GIVEAWAY_ENDED");
|
|
|
|
} catch(e){
|
2021-12-11 01:11:50 +05:00
|
|
|
return message.error("moderation/giveaway:NOT_FOUND", { messageID });
|
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
} else {
|
|
|
|
return message.error("moderation/giveaway:MISSING_STATUS");
|
|
|
|
}
|
|
|
|
}
|
2021-12-11 01:11:50 +05:00
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
module.exports = Giveaway;
|