SHARE
TWEET

Untitled

a guest Jun 16th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Command } = require('discord.js-commando');
  2.  
  3. module.exports = class command extends Command {
  4.     constructor(client) {
  5.         super(client, {
  6.             name: 'assign',
  7.             group: 'moderation',
  8.             memberName: 'assign',
  9.             aliases:['a'],
  10.             format:'assign <@member> <clan name>',
  11.             description: 'Assigns a member to clan',
  12.             examples:['assign @evilpauwse#9985 Cult of the Bots'],
  13.             details:"{'userPermission':'MANAGE_ROLES','description':''}"
  14.         });
  15.     }
  16.  
  17.     run(message) {
  18.     const {examples, format, client} = this
  19.     const db = require("quick.db")
  20.     const args = message.argString.trim().split(/ +/g);
  21.     const bot = require("../../bot.js")
  22.     const config = require('../../config.json')
  23.     function errorMessage(title, content) {
  24.     message.channel.send({
  25.       embed: {
  26.         color: 0xff0000,
  27.         title: title,
  28.         description: content,
  29.         fields: [{
  30.           name: "Usage",
  31.           value: "```" + client.options.commandPrefix + format.replace("|| ",("|| " + client.options.commandPrefix)) + "```"
  32.         },
  33.         {
  34.           name: "Examples",
  35.           value: client.options.commandPrefix + examples[0].split("\n").join("\n" + client.options.commandPrefix)
  36.         },
  37.         ],
  38.         footer: {
  39.           text: "This message will auto-delete in 10 seconds.",
  40.       },
  41.       }
  42.     }).then(msg => {
  43.       msg.delete(10000)
  44.     });
  45.   }
  46.   function missingPermissions() {
  47.     message.channel.send({
  48.       embed: {
  49.         color: 0xff0000,
  50.         title: "No permission!",
  51.         description: "You do not have permission to use this command!",
  52.         footer: {
  53.           text: "This message will auto-delete in 10 seconds.",
  54.       },
  55.       }
  56.     }).then(msg => {
  57.       msg.delete(10000)
  58.     });
  59.   }
  60.   function alreadyAssigned() {
  61.     message.channel.send({
  62.       embed: {
  63.         color: 0xff0000,
  64.         title: "An error occured",
  65.         description: "This member is already a part of a clan!",
  66.         footer: {
  67.           text: "This message will auto-delete in 10 seconds.",
  68.       },
  69.       }
  70.     }).then(msg => {
  71.       msg.delete(10000)
  72.     });
  73.   }
  74.       //
  75.       //!Mod+
  76.       let aroles = message.member.roles.array();
  77.     let arole = message.guild.roles.get("385744602231078923") //admin role
  78.     let mrole = message.guild.roles.get("385744604886204416") //mod role
  79.     if(aroles.indexOf(arole) === -1 && aroles.indexOf(mrole) === -1) {
  80.         return;
  81.     }
  82.     let theNumber;
  83.     let oauth = message.guild.member(message.author);
  84.     let z;
  85.     if(!args[0]) {
  86.     return errorMessage("Invalid member", "Please mention a valid member of the server!");
  87.     }
  88.     let targetMember;
  89.     try {
  90.       targetMember = message.guild.member(message.mentions.members.first());
  91.     } catch(err) {
  92.     return errorMessage("Invalid member", "Please mention a valid member of the server!");
  93.     }
  94.     if(!args[1]) {
  95.     return errorMessage("Invalid clan", "Please include a valid clan to assign the member to!");
  96.     }
  97.     let clanName = message.content.slice(8+args[0].length).toLowerCase().trim();
  98.     // db format: clanArray: [{name: "something", members: [{id: <id>, name: "evilpauwse", dateAdded: <date>}], role: {enabled: true/false, id: <id>}}]
  99.     db.fetch("assignedUsers").then(p => {
  100.  
  101.       if(p != undefined && p != null && p.includes(targetMember.id)) {
  102.  
  103.         return alreadyAssigned();
  104.  
  105.       }
  106.       db.fetch("clanArrayb").then(i => {
  107.         if(!i || i === undefined || i === null) {
  108.           return message.reply("unexcepted error, please contact ``evilpauwse#9985`` asap!")
  109.         }
  110.         for(z=0; z<i.length; z++) {
  111.         if(i[z].toLowerCase() === clanName) {
  112.           console.log(i[z]);
  113.           return theNumber = z;
  114.         }
  115.         }
  116.         });
  117.         db.fetch("clanArray").then(o => {
  118.         if(o[theNumber]===undefined){
  119.         return errorMessage("An error occured", "There are no clans that match this name!");
  120.         }
  121.         let role = false;
  122.         let collector;
  123.         //-console.log(o[z]);
  124.         message.channel.send({embed : {description :"Would you like to assign **"+targetMember.user.username+"** to the clan: **"+o[z].name+"**"}}).then(message => {message.react("✅")
  125.         setTimeout(function() {message.react("✅")}, 500);
  126.         message.react("❌")
  127.         const filter = (reaction, user) => user.id === oauth.id
  128.         const collector = message.createReactionCollector(filter, { time: 1500000 });
  129.         collector.on('collect', r => {collector.stop();});
  130.         collector.on('end', collected => {
  131.         console.log(collected.last().emoji.name);
  132.         if(collector.collected.last().emoji.name ==="✅") {
  133.         //check if role exists:
  134.         console.log(o[theNumber])
  135.         targetMember.addRole(message.guild.roles.get(o[theNumber].branchId)).catch(err => {message.reply("There was an error in adding this role. Please contact evilpauwse#9985 if this occurs.")})
  136.         if(o[theNumber].role.enabled === true) {
  137.          //if role exists:
  138.          
  139.          targetMember.addRole(message.guild.roles.get(o[theNumber].role.id)).catch(err => {message.reply("There was an error in adding this role. Please contact evilpauwse#9985 if this occurs.")})
  140.         }
  141.         //date getting:
  142.         var date = new Date();
  143.         var hour = date.getHours();
  144.         hour = (hour < 10 ? "0" : "") + hour;
  145.         var min  = date.getMinutes();
  146.         min = (min < 10 ? "0" : "") + min;
  147.         var sec  = date.getSeconds();
  148.         sec = (sec < 10 ? "0" : "") + sec;
  149.         var year = date.getFullYear();
  150.         var month = date.getMonth() + 1;
  151.         month = (month < 10 ? "0" : "") + month;
  152.         var day  = date.getDate();
  153.         day = (day < 10 ? "0" : "") + day;
  154.         var date = month + "/" + day + "/" + year + " - " + hour + ":" + min + ":" + sec;
  155.         // logic for a confirm:
  156.         let memberarray = {id: targetMember.id, name: targetMember.name, dateAdded: date}
  157.         var objdupe = o;
  158.    
  159.         var members = objdupe[z].members;
  160.         //console.log(objdupe);
  161.         members.push(memberarray);
  162.         objdupe[z].members = members;    
  163.         db.set("clanArray", objdupe);
  164.         db.push("assignedUsers", targetMember.id);
  165.         db.fetch("modAssignsb").then(i => {
  166.           let p = i.indexOf(oauth.id);
  167.           if(i === null || i === undefined) {
  168.             db.push("modAssigns", {id: oauth.id, count: 1});
  169.             db.push("modAssignsb", oauth.id);
  170.           }
  171.           else if(!i.includes(oauth.id)) {
  172.             db.push("modAssigns", {id: oauth.id, count: 1});
  173.             db.push("modAssignsb", oauth.id);
  174.           } else {
  175.             db.fetch("modAssigns").then(i => {
  176.             console.log(i);
  177.             let newarray = i;
  178.             console.log(p)
  179.             newarray[p] = newarray[p].count + 1;
  180.             db.set("modAssigns", newarray);
  181.           })
  182.             /*
  183.             let newEmbed = message.guild.channels.get(channel_id).fetchMessage(message_id).embeds[0]
  184.             newEmbed.fields[i.indexOf(message.author.id)].value = `${newarray[i.indexOf(message.author.id)].count} assigns`
  185.             message.guild.channels.get(channel_id).fetchMessage(message_id).edit(newEmbed);
  186.             */
  187.           }
  188.  
  189.         })
  190.         message.guild.channels.get(config.modFeed).send({embed:{title: `Alliance Member has been Assigned`, color: config.success, description: `Moderator Info: ${oauth.displayName} (${oauth.id})\nMember Info: <@!${targetMember.id}> (${targetMember.id}) - ${targetMember.displayName}\nClan: ${clanName}\nBranch Role: <@&${o[theNumber].branchId}>`}})
  191.         return message.edit({embed : { color: 65280, description :`Successfully added **${targetMember.user.username}** to the clan **${o[z].name}**.`}});
  192.        
  193.         }
  194.         else {
  195.         return message.edit({embed : { description :`Clan assignment has been canceled.`}});
  196.         }
  197.         });
  198.         });
  199.         })
  200.  
  201.     })
  202.  
  203.     }
  204. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top