Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Command } = require('klasa');
- const { MessageEmbed, TextChannel, Role,GuildMember,User } = require('discord.js')
- module.exports = class extends Command {
- constructor(...args) {
- /**
- * Any default options can be omitted completely.
- * if all options are default, you can omit the constructor completely
- */
- super(...args, {
- enabled: true,
- runIn: ['text', 'dm', 'group'],
- requiredPermissions: [],
- requiredSettings: [],
- aliases: [],
- autoAliases: true,
- bucket: 1,
- cooldown: 0,
- promptLimit: 0,
- promptTime: 30000,
- deletable: false,
- guarded: false,
- nsfw: false,
- permissionLevel: 0,
- description: language => language.get('COMMAND_VTC_DESC'),
- extendedHelp: 'No extended help available.',
- usage: '<register|delete|setchannel|addowner|roles|questions|accept|deny|applications|info|help|apply|setlogo|setdescription> [channel:channel|user:user|other:string] [role:role|other:string] [...]',
- usageDelim: " ",
- quotedStringSupport: false,
- subcommands: false
- });
- this.customizeResponse("register",message =>
- {
- return "Welcome to TruckyBot VTC Command!\nTo get started, please do `.vtc help` for some help. \nIf you are here to apply the vtc, please do `.apply`\n.`vtc register` to start a vtc";
- }
- )
- }
- run(message, [type, ...params]) {
- var vtc = message.guild.settings.vtc
- return this[type](message, vtc, params);
- }
- //#region Manage VTC
- async register(message, vtc, [...param]) {
- if (vtc) return message.reply('You can\'t have two VTC on a Discord server.');
- if (!message.channel.permissionsFor(message.guild.me).has('MANAGE_ROLES')) return message.send("Sorry but to use the VTC feature, the bot must have permission to manage roles in the server.\n Please readd the permission to manage roles in order to proceed.")
- var vtcName = await this.loopMessage(message, "Let\'s start, What is your VTC\'s name", null);
- if (vtcName == "cancel") return;
- var listAdminRoles = await this.loopMessage(message, "**Which Role is the admin role?** \nThis role can manage applications and questions.\n*Please don't delete this role afterwards otherwise your vtc will be invalid!*", "roles");
- if (listAdminRoles == "cancel") return;
- while (true) {
- var listMemberRoles = await this.loopMessage(message, "**Which Role is the member role?** \nUsers will be automatically added to the first role mentioned if they got accepted\nEvery member in this role are VTC member\n*You can add multiple roles*\n*Please don't delete this role afterwards otherwise your vtc will be invalid!*", "roles");
- if (listMemberRoles == "cancel") return;
- if (listAdminRoles.some(r => listMemberRoles.includes(r))) {
- message.send("The member roles is one of the admin role. Please retry.")
- continue;
- }
- break;
- }
- var newVTC =
- {
- name: vtcName,
- owners: [message.author.id],
- adminRoles: listAdminRoles,
- memberRoles: listMemberRoles,
- defaultRole: listMemberRoles[0]
- }
- await message.guild.settings.update("vtc", newVTC, { action: "overwrite" })
- await message.guild.settings.update("applyChannel", message.channel, { action: "overwrite" })
- await message.channel.send("The VTC has been created!\n You can now setup questions for applicants and other settings!\nApplications will be posted now. To Change this, do `.vtc setchannel <channel>`");
- const commands = [
- "`.vtc roles <addadmin|removeadmin|addmember|removemember> <role>` - Add or remove a role for admin or member role",
- "`.vtc setdescription <description>` - Set a description for your vtc",
- "`.vtc questions` - Show all the created questions",
- "`.vtc questions add <question>` - Add a question",
- "`.vtc questions remove <pos>` - Remove a question from the list of questions. For the positions, please refer to `.vtc questions`",
- "`.vtc setchannel <channel>` - Set a channel for applications, the bot will post applications whenever there is one",
- "`.vtc <accept|deny> <id>` - Accept or deny an application.",
- "`.vtc applications` - Show all the active applications",
- "`.vtc delete` - Delete the whole VTC, note that this is irreversible"
- ]
- await message.sendEmbed(new MessageEmbed({
- title: "Admin Command",
- description: commands.join("\n")
- }))
- }
- async setdescription(message, vtc, [...param])
- {
- if (!vtc) return message.reply('There is no VTC linked with this server.');
- if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
- if(!param[0]) return message.reply('Please provide the description.');
- vtc = JSON.parse(JSON.stringify(vtc))
- vtc.description = param.join(" ")
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The description has been set successfully.")
- }
- async addowner(message, vtc, [...param])
- {
- if (!vtc) return message.reply('There is no VTC linked with this server.');
- if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
- if(!param[0]) return message.reply('Please provide the user.');
- if(!(param[0] instanceof User)) return message.reply('Please provide the user.');
- vtc = JSON.parse(JSON.stringify(vtc))
- vtc.owners.push(param[0].id)
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The owner has been added successfully.")
- }
- async setlogo(message, vtc, [...param])
- {
- if (!vtc) return message.reply('There is no VTC linked with this server.');
- if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
- if(!param[0]) return message.reply('Please provide the description.');
- vtc = JSON.parse(JSON.stringify(vtc))
- vtc.logo = param[0]
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The Logo has been set successfully.")
- }
- async loopMessage(message, question, require) {
- await message.channel.send(question + "\n*Type `cancel` to cancel the registration process*");
- while (true) {
- var error = false;
- const reply = await message.channel.awaitMessages(m => m.author.id == message.author.id, {
- max: 1,
- time: 200000,
- errors: ['time'],
- })
- if (reply.first().content == "cancel" || error == true) {
- message.send("**Cancelling registration process.**\nPlease do `.vtc register` to restart the process.")
- return "cancel";
- }
- if (require == "roles") {
- if (reply.first().mentions.roles.size > 0) {
- return reply.first().mentions.roles.map(role => role.id);
- };
- await message.channel.send("**Invalid Role.** Please tag a role.\n*Type `cancel` to cancel the registration process*");
- }
- else {
- return reply.first().content;
- }
- }
- }
- async delete(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server.');
- if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
- if (param[0] === 'confirm') {
- message.guild.settings.reset("vtc");
- message.channel.send('The VTC has been deleted from Trucky !');
- } else {
- message.reply(`Are you sure that you want to delete the whole VTC?\n Please mind that this action is irreversible.\nIf you are sure about this, Please confirm the action with: \`${message.guild.prefix}vtc delete confirm\``);
- }
- }
- //#endregion
- //#region Admin area
- async setchannel(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!message.member.roles.some(role => vtc.adminRoles.includes(role.id)) && !vtc.owners.includes(message.author.id)) return message.send("Only Admin of VTC can use this command.");
- if (!(param[0] instanceof TextChannel)) return message.reply(`Please provide a Text Channel`)
- await message.guild.settings.update("applyChannel", param[0])
- await message.send(`Updated the application channel to ${param[0]}. Application will be posted there`);
- }
- async roles(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!vtc.owners.includes(message.author.id)) return message.send("Only VTC Owners can use this command!")
- if (!(param[1] instanceof Role)) return message.send("You have provided an invalid role.")
- if (param[0] == "addadmin") {
- vtc = JSON.parse(JSON.stringify(vtc))
- if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is already an admin role!")
- if (vtc.memberRoles.includes(param[1].id)) return message.reply("This role is a member role! Please change the member role if you wish to proceed.")
- vtc.adminRoles.push(param[1].id);
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The role has been added to the admin roles successfully.")
- }
- else if (param[0] == "removeadmin") {
- vtc = JSON.parse(JSON.stringify(vtc))
- if (!vtc.adminRoles.includes(param[1].id)) return message.reply("This role is not an admin role!")
- vtc.adminRoles = vtc.adminRoles.filter(roles => roles != param[1].id);
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The role has been removed from the admin roles successfully.")
- }
- if (param[0] == "addmember") {
- vtc = JSON.parse(JSON.stringify(vtc))
- if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is already an admin role!")
- if (vtc.memberRoles.includes(param[1].id)) return message.reply("This role is a member role! Please change the member role if you wish to proceed.")
- vtc.memberRoles = vtc.memberRoles.push(param[1].id)
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The role has been added to the admin roles successfully.")
- }
- else if (param[0] == "removemember") {
- vtc = JSON.parse(JSON.stringify(vtc))
- if (!vtc.memberRoles.includes(param[1].id)) return message.reply("This role is not an member role!")
- if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is an admin role! Please change the member role if you wish to proceed.")
- vtc.memberRoles = vtc.memberRoles.filter(role => role != param[1].id)
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The role has been removed from the admin roles successfully.")
- }
- else if (param[0] == "setapplicant") {
- vtc = JSON.parse(JSON.stringify(vtc))
- if (vtc.memberRoles.includes(param[1].id)) return message.reply("This role is a member role!")
- if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is an admin role! ")
- vtc.applicantRole = param[1].id;
- await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
- return message.send("The role has been set for applicant roles successfully.")
- }
- else { return message.send("Unknown Action. Avaliable commands: (`addadmin`|`removeadmin`|`addmember`|`removemember`|`setapplicant`)") }
- }
- async questions(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!message.member.roles.some(role => vtc.adminRoles.includes(role.id)) && !vtc.owners.includes(message.author.id)) return message.send("Only VTC Admins can use this command!")
- if (param[0] == "add") {
- param.shift()
- if (!param[1]) return message.send("No question was provided, Please provide a question")
- message.guild.settings.update("questions", param.join(" "), { action: "add" })
- message.send("Question Added!")
- }
- else if (param[0] == "remove") {
- var questions = message.guild.settings.get("questions")
- if (questions.length == 0) return message.send("No question were setup!")
- var questionToBeRemoved = questions[param[1] - 1]
- console.log(questionToBeRemoved)
- await message.guild.settings.update("questions", questionToBeRemoved, { action: "remove" })
- await message.send("Question Removed!")
- }
- else {
- var questions = message.guild.settings.get("questions")
- if (!questions) return message.send("No question were setup!")
- const embed = {
- title: "Created Questions",
- description: questions.map((question, index) => `${index + 1}- ${question}`).join("\n")
- }
- await message.sendEmbed(new MessageEmbed(embed))
- }
- }
- async accept(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!message.member.roles.some(role => vtc.adminRoles.includes(role.id)) && !vtc.owners.includes(message.author.id)) return message.send("Only VTC Admins can use this command!")
- var applications = message.guild.settings.get("applications")
- if(applications.length == 0) return message.send("Application Not Found");
- var application = applications.find(app => app.id == param[0])
- if(!application) return message.send("Application Not Found");
- var userAccepted = await message.guild.members.fetch(application.applicantUserID)
- if(!(userAccepted instanceof GuildMember)) await message.send('Applicant has left the server. The Application is closed');
- else
- {
- await userAccepted.roles.add(vtc.defaultRole);
- userAccepted.user.send(`You have been accepted to the VTC in ${vtc.name}!`);
- await message.send("Application accepted. The Application is now closed")
- }
- await message.guild.settings.update("applications",application,{action:"remove"});
- }
- async deny(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!message.member.roles.some(role => vtc.adminRoles.includes(role.id)) && !vtc.owners.includes(message.author.id)) return message.send("Only VTC Admins can use this command!")
- var applications = message.guild.settings.get("applications")
- if(applications.length == 0) return message.send("Application Not Found");
- var application = applications.find(app => app.id == param[0])
- if(!application) return message.send("Application Not Found");
- var userAccepted = await message.guild.members.fetch(application.applicantUserID)
- if(!(userAccepted instanceof GuildMember)) await message.send('Applicant has left the server. The Application is closed');
- else
- {
- userAccepted.user.send(`Unfortunately you have been denied in ${vtc.name}...`);
- await message.send("Application refused. The Application is now closed")
- }
- await message.guild.settings.update("applications",application,{action:"remove"});
- }
- async applications(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
- if (!message.member.roles.some(role => vtc.adminRoles.includes(role.id)) && !vtc.owners.includes(message.author.id)) return message.send("Only VTC Admins can use this command!")
- const embed = new MessageEmbed({
- title: "Active Applications"
- })
- const applications = message.guild.settings.get("applications")
- if(applications.length == 0) embed.setDescription("No Applications")
- else
- {
- var formatted = applications.map(app => `Application No ${app.id} - Submitted by <@${app.applicantUserID}>`).join("\n")
- embed.setDescription(formatted);
- }
- message.sendEmbed(embed)
- }
- //#endregion
- async info(message, vtc, [...param]) {
- if (!vtc) return message.reply('There is no VTC linked with this server.');
- var listAdminRole = vtc.adminRoles.map(role => `<@&${role}>`).join(" ")
- var listMemberRoles = vtc.memberRoles.map(role => `<@&${role}>`).join(" ")
- var listUsersAdmin = [];
- var listUsersMember = [];
- for (let index = 0; index < vtc.adminRoles.length; index++) {
- const role = vtc.adminRoles[index];
- var listAdmin = await message.guild.roles.fetch(role)
- listUsersAdmin.push(...listAdmin.members.map(member => `<@${member.id}>`))
- }
- for (let index = 0; index < vtc.memberRoles.length; index++) {
- const role = vtc.memberRoles[index];
- var listMember = await message.guild.roles.fetch(role)
- listUsersMember.push(...listMember.members.map(member => `<@${member.id}>`))
- }
- var displayAdmin = listUsersAdmin.join(" ")
- var displayMember = listUsersMember.join(" ")
- if(displayMember.length >= 1000) displayMember = `${listUsersMember.length} members\nToo Many Members to show`
- if (listUsersAdmin.length == 0) displayAdmin = "No Admins";
- if (listUsersMember.length == 0) displayMember = "No Members";
- var description = vtc.description ? vtc.description : "No description provided"
- var logo = vtc.logo ? vtc.logo : ""
- const embed =
- {
- title: vtc.name,
- thumbnail:{
- url:logo
- },
- description: `Admin Roles: ${listAdminRole}\nMember Role: ${listMemberRoles}`,
- fields: [
- {
- name: "Description:",
- value: description
- },
- {
- name: "Owners:",
- value: vtc.owners.map(member => `<@${member}>`).join(" "),
- inline:true
- },
- {
- name: "Admin:",
- value: displayAdmin,
- inline:true
- },
- {
- name: "Member:",
- value: displayMember,
- inline:true
- },
- ],
- }
- await message.sendEmbed(new MessageEmbed(embed))
- }
- async help(message, vtc, [...param]) {
- message.send("**Trucky VTC Command Help**\nIf you are the admin of the server wish to start a vtc, please do `.vtc register`\nIf you wish to apply vtc in this server, please do `.apply`")
- const commands = [
- "`.vtc roles <addadmin|removeadmin|addmember|removemember> <role>` - Add or remove a role for admin or member role",
- "`.vtc setdescription <description>` - Set a description for your vtc",
- "`.vtc questions` - Show all the created questions",
- "`.vtc questions add <question>` - Add a question",
- "`.vtc questions remove <pos>` - Remove a question from the list of questions. For the positions, please refer to `.vtc questions`",
- "`.vtc setchannel <channel>` - Set a channel for applications, the bot will post applications whenever there is one",
- "`.vtc <accept|deny> <id>` - Accept or deny an application.",
- "`.vtc applications` - Show all the active applications",
- "`.vtc delete` - Delete the whole VTC, note that this is irreversible"
- ]
- await message.sendEmbed(new MessageEmbed({
- title: "Admin Command",
- description: commands.join("\n")
- }))
- }
- //#region normal people can accede
- //#endregion
- async init() {
- /*
- * You can optionally define this method which will be run when the bot starts
- * (after login, so discord data is available via this.client)
- */
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement