JaBa/commands/Administration/welcome.js

111 lines
3.2 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Resolvers = require("../../helpers/resolvers");
class Welcome extends Command {
constructor(client) {
super(client, {
name: "welcome",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["welc"],
memberPermissions: ["MANAGE_GUILD"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
if (args[0] === "test" && data.guild.plugins.welcome.enabled) {
this.client.emit("guildMemberAdd", message.member);
return message.success("administration/welcome:TEST_SUCCESS");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
if ((!args[0] || !["edit", "off"].includes(args[0])) && data.guild.plugins.welcome.enabled) return message.error("administration/welcome:MISSING_STATUS");
if (args[0] === "off") {
data.guild.plugins.welcome = {
enabled: false,
message: null,
channelID: null,
withImage: null
};
data.guild.markModified("plugins.welcome");
data.guild.save();
return message.error("administration/welcome:DISABLED", {
prefix: data.guild.prefix
});
} else {
const welcome = {
enabled: true,
channel: null,
message: null,
withImage: null,
};
message.sendT("administration/welcome:FORM_1", {
author: message.author.toString()
});
const filter = m => m.author.id === message.author.id;
const collector = message.channel.createMessageCollector({
filter,
2022-01-04 02:18:28 +05:00
time: 120000 // 2 minutes
});
collector.on("collect", async msg => {
// If the message is filled, it means the user sent yes or no for the image
if (welcome.message) {
if (msg.content.toLowerCase() === message.translate("common:YES").toLowerCase()) {
welcome.withImage = true;
} else if (msg.content.toLowerCase() === message.translate("common:NO").toLowerCase()) {
welcome.withImage = false;
} else {
return message.error("misc:INVALID_YES_NO");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
data.guild.plugins.welcome = welcome;
data.guild.markModified("plugins.welcome");
await data.guild.save();
message.sendT("administration/welcome:FORM_SUCCESS", {
prefix: data.guild.prefix,
channel: `<#${welcome.channel}>`
});
return collector.stop();
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
// If the channel is filled and the message is not, it means the user sent the message
if (welcome.channel && !welcome.message) {
if (msg.content.length < 1800) {
welcome.message = msg.content;
return message.sendT("administration/welcome:FORM_3");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
return message.error("administration/goodbye:MAX_CHARACT");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
// If the channel is not filled, it means the user sent it
if (!welcome.channel) {
const channel = await Resolvers.resolveChannel({
message: msg,
channelType: "GUILD_TEXT"
2022-01-04 02:18:28 +05:00
});
if (!channel) return message.error("misc:INVALID_CHANNEL");
welcome.channel = channel.id;
message.sendT("administration/welcome:FORM_2", {
guildName: message.guild.name,
author: msg.author.tag,
memberCount: msg.guild.memberCount
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
});
collector.on("end", (_, reason) => {
2022-01-13 00:26:23 +05:00
if (reason === "time") return message.error("misc:TIMES_UP");
2022-01-04 02:18:28 +05:00
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Welcome;