Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.21 KB | None | 0 0
  1. const { Command } = require('klasa');
  2. const { MessageEmbed, TextChannel, Role,GuildMember,User } = require('discord.js')
  3.  
  4. module.exports = class extends Command {
  5.  
  6. constructor(...args) {
  7. /**
  8. * Any default options can be omitted completely.
  9. * if all options are default, you can omit the constructor completely
  10. */
  11. super(...args, {
  12. enabled: true,
  13. runIn: ['text', 'dm', 'group'],
  14. requiredPermissions: [],
  15. requiredSettings: [],
  16. aliases: [],
  17. autoAliases: true,
  18. bucket: 1,
  19. cooldown: 0,
  20. promptLimit: 0,
  21. promptTime: 30000,
  22. deletable: false,
  23. guarded: false,
  24. nsfw: false,
  25. permissionLevel: 0,
  26. description: language => language.get('COMMAND_VTC_DESC'),
  27. extendedHelp: 'No extended help available.',
  28. 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] [...]',
  29. usageDelim: " ",
  30. quotedStringSupport: false,
  31. subcommands: false
  32. });
  33. this.customizeResponse("register",message =>
  34. {
  35. 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";
  36. }
  37. )
  38. }
  39.  
  40. run(message, [type, ...params]) {
  41. var vtc = message.guild.settings.vtc
  42. return this[type](message, vtc, params);
  43. }
  44. //#region Manage VTC
  45. async register(message, vtc, [...param]) {
  46. if (vtc) return message.reply('You can\'t have two VTC on a Discord server.');
  47. 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.")
  48. var vtcName = await this.loopMessage(message, "Let\'s start, What is your VTC\'s name", null);
  49. if (vtcName == "cancel") return;
  50. 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");
  51. if (listAdminRoles == "cancel") return;
  52.  
  53. while (true) {
  54. 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");
  55. if (listMemberRoles == "cancel") return;
  56. if (listAdminRoles.some(r => listMemberRoles.includes(r))) {
  57. message.send("The member roles is one of the admin role. Please retry.")
  58. continue;
  59. }
  60. break;
  61. }
  62. var newVTC =
  63. {
  64. name: vtcName,
  65. owners: [message.author.id],
  66. adminRoles: listAdminRoles,
  67. memberRoles: listMemberRoles,
  68. defaultRole: listMemberRoles[0]
  69. }
  70. await message.guild.settings.update("vtc", newVTC, { action: "overwrite" })
  71. await message.guild.settings.update("applyChannel", message.channel, { action: "overwrite" })
  72. 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>`");
  73. const commands = [
  74. "`.vtc roles <addadmin|removeadmin|addmember|removemember> <role>` - Add or remove a role for admin or member role",
  75. "`.vtc setdescription <description>` - Set a description for your vtc",
  76. "`.vtc questions` - Show all the created questions",
  77. "`.vtc questions add <question>` - Add a question",
  78. "`.vtc questions remove <pos>` - Remove a question from the list of questions. For the positions, please refer to `.vtc questions`",
  79. "`.vtc setchannel <channel>` - Set a channel for applications, the bot will post applications whenever there is one",
  80. "`.vtc <accept|deny> <id>` - Accept or deny an application.",
  81. "`.vtc applications` - Show all the active applications",
  82. "`.vtc delete` - Delete the whole VTC, note that this is irreversible"
  83. ]
  84. await message.sendEmbed(new MessageEmbed({
  85. title: "Admin Command",
  86. description: commands.join("\n")
  87. }))
  88.  
  89.  
  90. }
  91.  
  92. async setdescription(message, vtc, [...param])
  93. {
  94. if (!vtc) return message.reply('There is no VTC linked with this server.');
  95. if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
  96. if(!param[0]) return message.reply('Please provide the description.');
  97. vtc = JSON.parse(JSON.stringify(vtc))
  98. vtc.description = param.join(" ")
  99. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  100. return message.send("The description has been set successfully.")
  101. }
  102.  
  103. async addowner(message, vtc, [...param])
  104. {
  105. if (!vtc) return message.reply('There is no VTC linked with this server.');
  106. if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
  107. if(!param[0]) return message.reply('Please provide the user.');
  108. if(!(param[0] instanceof User)) return message.reply('Please provide the user.');
  109. vtc = JSON.parse(JSON.stringify(vtc))
  110. vtc.owners.push(param[0].id)
  111. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  112. return message.send("The owner has been added successfully.")
  113. }
  114.  
  115. async setlogo(message, vtc, [...param])
  116. {
  117. if (!vtc) return message.reply('There is no VTC linked with this server.');
  118. if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
  119. if(!param[0]) return message.reply('Please provide the description.');
  120. vtc = JSON.parse(JSON.stringify(vtc))
  121. vtc.logo = param[0]
  122. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  123. return message.send("The Logo has been set successfully.")
  124. }
  125.  
  126.  
  127.  
  128.  
  129. async loopMessage(message, question, require) {
  130. await message.channel.send(question + "\n*Type `cancel` to cancel the registration process*");
  131. while (true) {
  132. var error = false;
  133. const reply = await message.channel.awaitMessages(m => m.author.id == message.author.id, {
  134. max: 1,
  135. time: 200000,
  136. errors: ['time'],
  137. })
  138. if (reply.first().content == "cancel" || error == true) {
  139. message.send("**Cancelling registration process.**\nPlease do `.vtc register` to restart the process.")
  140. return "cancel";
  141. }
  142. if (require == "roles") {
  143. if (reply.first().mentions.roles.size > 0) {
  144. return reply.first().mentions.roles.map(role => role.id);
  145. };
  146. await message.channel.send("**Invalid Role.** Please tag a role.\n*Type `cancel` to cancel the registration process*");
  147. }
  148. else {
  149. return reply.first().content;
  150. }
  151. }
  152. }
  153.  
  154.  
  155. async delete(message, vtc, [...param]) {
  156. if (!vtc) return message.reply('There is no VTC linked with this server.');
  157. if (!(vtc.owners.includes(message.author.id))) return message.reply('You are not the owner of the VTC.');
  158.  
  159. if (param[0] === 'confirm') {
  160. message.guild.settings.reset("vtc");
  161. message.channel.send('The VTC has been deleted from Trucky !');
  162. } else {
  163. 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\``);
  164. }
  165.  
  166. }
  167.  
  168. //#endregion
  169.  
  170.  
  171. //#region Admin area
  172.  
  173.  
  174. async setchannel(message, vtc, [...param]) {
  175. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  176. 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.");
  177. if (!(param[0] instanceof TextChannel)) return message.reply(`Please provide a Text Channel`)
  178. await message.guild.settings.update("applyChannel", param[0])
  179. await message.send(`Updated the application channel to ${param[0]}. Application will be posted there`);
  180. }
  181.  
  182.  
  183. async roles(message, vtc, [...param]) {
  184. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  185. if (!vtc.owners.includes(message.author.id)) return message.send("Only VTC Owners can use this command!")
  186. if (!(param[1] instanceof Role)) return message.send("You have provided an invalid role.")
  187. if (param[0] == "addadmin") {
  188. vtc = JSON.parse(JSON.stringify(vtc))
  189. if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is already an admin role!")
  190. 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.")
  191. vtc.adminRoles.push(param[1].id);
  192. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  193. return message.send("The role has been added to the admin roles successfully.")
  194. }
  195. else if (param[0] == "removeadmin") {
  196. vtc = JSON.parse(JSON.stringify(vtc))
  197. if (!vtc.adminRoles.includes(param[1].id)) return message.reply("This role is not an admin role!")
  198. vtc.adminRoles = vtc.adminRoles.filter(roles => roles != param[1].id);
  199. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  200. return message.send("The role has been removed from the admin roles successfully.")
  201. }
  202. if (param[0] == "addmember") {
  203. vtc = JSON.parse(JSON.stringify(vtc))
  204. if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is already an admin role!")
  205. 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.")
  206. vtc.memberRoles = vtc.memberRoles.push(param[1].id)
  207. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  208. return message.send("The role has been added to the admin roles successfully.")
  209. }
  210. else if (param[0] == "removemember") {
  211. vtc = JSON.parse(JSON.stringify(vtc))
  212. if (!vtc.memberRoles.includes(param[1].id)) return message.reply("This role is not an member role!")
  213. 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.")
  214. vtc.memberRoles = vtc.memberRoles.filter(role => role != param[1].id)
  215. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  216. return message.send("The role has been removed from the admin roles successfully.")
  217. }
  218. else if (param[0] == "setapplicant") {
  219. vtc = JSON.parse(JSON.stringify(vtc))
  220. if (vtc.memberRoles.includes(param[1].id)) return message.reply("This role is a member role!")
  221. if (vtc.adminRoles.includes(param[1].id)) return message.reply("This role is an admin role! ")
  222. vtc.applicantRole = param[1].id;
  223. await message.guild.settings.update("vtc",vtc,{action:"overwrite"});
  224. return message.send("The role has been set for applicant roles successfully.")
  225. }
  226.  
  227. else { return message.send("Unknown Action. Avaliable commands: (`addadmin`|`removeadmin`|`addmember`|`removemember`|`setapplicant`)") }
  228. }
  229.  
  230. async questions(message, vtc, [...param]) {
  231. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  232. 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!")
  233. if (param[0] == "add") {
  234. param.shift()
  235. if (!param[1]) return message.send("No question was provided, Please provide a question")
  236. message.guild.settings.update("questions", param.join(" "), { action: "add" })
  237. message.send("Question Added!")
  238.  
  239. }
  240. else if (param[0] == "remove") {
  241. var questions = message.guild.settings.get("questions")
  242. if (questions.length == 0) return message.send("No question were setup!")
  243. var questionToBeRemoved = questions[param[1] - 1]
  244. console.log(questionToBeRemoved)
  245. await message.guild.settings.update("questions", questionToBeRemoved, { action: "remove" })
  246. await message.send("Question Removed!")
  247. }
  248. else {
  249. var questions = message.guild.settings.get("questions")
  250. if (!questions) return message.send("No question were setup!")
  251. const embed = {
  252. title: "Created Questions",
  253. description: questions.map((question, index) => `${index + 1}- ${question}`).join("\n")
  254. }
  255. await message.sendEmbed(new MessageEmbed(embed))
  256. }
  257. }
  258.  
  259.  
  260. async accept(message, vtc, [...param]) {
  261. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  262. 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!")
  263. var applications = message.guild.settings.get("applications")
  264. if(applications.length == 0) return message.send("Application Not Found");
  265. var application = applications.find(app => app.id == param[0])
  266. if(!application) return message.send("Application Not Found");
  267. var userAccepted = await message.guild.members.fetch(application.applicantUserID)
  268. if(!(userAccepted instanceof GuildMember)) await message.send('Applicant has left the server. The Application is closed');
  269. else
  270. {
  271. await userAccepted.roles.add(vtc.defaultRole);
  272. userAccepted.user.send(`You have been accepted to the VTC in ${vtc.name}!`);
  273. await message.send("Application accepted. The Application is now closed")
  274. }
  275. await message.guild.settings.update("applications",application,{action:"remove"});
  276. }
  277.  
  278. async deny(message, vtc, [...param]) {
  279. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  280. 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!")
  281. var applications = message.guild.settings.get("applications")
  282. if(applications.length == 0) return message.send("Application Not Found");
  283. var application = applications.find(app => app.id == param[0])
  284. if(!application) return message.send("Application Not Found");
  285. var userAccepted = await message.guild.members.fetch(application.applicantUserID)
  286. if(!(userAccepted instanceof GuildMember)) await message.send('Applicant has left the server. The Application is closed');
  287. else
  288. {
  289. userAccepted.user.send(`Unfortunately you have been denied in ${vtc.name}...`);
  290. await message.send("Application refused. The Application is now closed")
  291. }
  292. await message.guild.settings.update("applications",application,{action:"remove"});
  293. }
  294.  
  295.  
  296. async applications(message, vtc, [...param]) {
  297. if (!vtc) return message.reply('There is no VTC linked with this server. Please do `.vtc register` do create one.');
  298. 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!")
  299. const embed = new MessageEmbed({
  300. title: "Active Applications"
  301. })
  302. const applications = message.guild.settings.get("applications")
  303. if(applications.length == 0) embed.setDescription("No Applications")
  304. else
  305. {
  306. var formatted = applications.map(app => `Application No ${app.id} - Submitted by <@${app.applicantUserID}>`).join("\n")
  307. embed.setDescription(formatted);
  308. }
  309. message.sendEmbed(embed)
  310.  
  311.  
  312.  
  313.  
  314. }
  315.  
  316.  
  317. //#endregion
  318.  
  319.  
  320. async info(message, vtc, [...param]) {
  321. if (!vtc) return message.reply('There is no VTC linked with this server.');
  322. var listAdminRole = vtc.adminRoles.map(role => `<@&${role}>`).join(" ")
  323. var listMemberRoles = vtc.memberRoles.map(role => `<@&${role}>`).join(" ")
  324. var listUsersAdmin = [];
  325. var listUsersMember = [];
  326. for (let index = 0; index < vtc.adminRoles.length; index++) {
  327. const role = vtc.adminRoles[index];
  328. var listAdmin = await message.guild.roles.fetch(role)
  329. listUsersAdmin.push(...listAdmin.members.map(member => `<@${member.id}>`))
  330. }
  331. for (let index = 0; index < vtc.memberRoles.length; index++) {
  332. const role = vtc.memberRoles[index];
  333. var listMember = await message.guild.roles.fetch(role)
  334. listUsersMember.push(...listMember.members.map(member => `<@${member.id}>`))
  335. }
  336. var displayAdmin = listUsersAdmin.join(" ")
  337. var displayMember = listUsersMember.join(" ")
  338. if(displayMember.length >= 1000) displayMember = `${listUsersMember.length} members\nToo Many Members to show`
  339. if (listUsersAdmin.length == 0) displayAdmin = "No Admins";
  340. if (listUsersMember.length == 0) displayMember = "No Members";
  341. var description = vtc.description ? vtc.description : "No description provided"
  342. var logo = vtc.logo ? vtc.logo : ""
  343. const embed =
  344. {
  345. title: vtc.name,
  346. thumbnail:{
  347. url:logo
  348. },
  349. description: `Admin Roles: ${listAdminRole}\nMember Role: ${listMemberRoles}`,
  350. fields: [
  351. {
  352. name: "Description:",
  353. value: description
  354. },
  355. {
  356. name: "Owners:",
  357. value: vtc.owners.map(member => `<@${member}>`).join(" "),
  358. inline:true
  359. },
  360. {
  361. name: "Admin:",
  362. value: displayAdmin,
  363. inline:true
  364.  
  365. },
  366. {
  367. name: "Member:",
  368. value: displayMember,
  369. inline:true
  370. },
  371. ],
  372.  
  373.  
  374. }
  375. await message.sendEmbed(new MessageEmbed(embed))
  376. }
  377.  
  378. async help(message, vtc, [...param]) {
  379. 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`")
  380. const commands = [
  381. "`.vtc roles <addadmin|removeadmin|addmember|removemember> <role>` - Add or remove a role for admin or member role",
  382. "`.vtc setdescription <description>` - Set a description for your vtc",
  383. "`.vtc questions` - Show all the created questions",
  384. "`.vtc questions add <question>` - Add a question",
  385. "`.vtc questions remove <pos>` - Remove a question from the list of questions. For the positions, please refer to `.vtc questions`",
  386. "`.vtc setchannel <channel>` - Set a channel for applications, the bot will post applications whenever there is one",
  387. "`.vtc <accept|deny> <id>` - Accept or deny an application.",
  388. "`.vtc applications` - Show all the active applications",
  389. "`.vtc delete` - Delete the whole VTC, note that this is irreversible"
  390. ]
  391. await message.sendEmbed(new MessageEmbed({
  392. title: "Admin Command",
  393. description: commands.join("\n")
  394. }))
  395. }
  396.  
  397.  
  398.  
  399.  
  400. //#region normal people can accede
  401.  
  402.  
  403.  
  404.  
  405. //#endregion
  406.  
  407. async init() {
  408. /*
  409. * You can optionally define this method which will be run when the bot starts
  410. * (after login, so discord data is available via this.client)
  411. */
  412. }
  413.  
  414. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement