Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = {
  2.   name: `mute`,
  3.   description: `Permet de mute des utilisateurs`,
  4.   description_en: `Mutes people`,
  5.   usage: `mute [@user] <raison> <time> (infinite if not given)\nFormat pour le temps : 5j 2h... (Maximum secondes)`,
  6.   usage_en: `mute [@user] <reason> <time> (infinite if not given)\nTime Format : 5d 2h... (Seconds are the max you can go.)`,
  7.   exemple: `mute @annoying_user il était chiant 5j 8h`,
  8.   cooldown: 5,
  9.   execute(Discord, date, mysql, fs, config, guide, guide_en, bot, con, message, pref, lan, blocked, fullGuide, args, commandName, command, GeneralNow, dateNow, log_channel, dev_log_channel, log_success, log_fail, log_err_permissions, log_err_bot_permissions, log_err_arguments, log_err_invalid_arguments) {  
  10.     let member = message.mentions.members.first();
  11.     let time_array = []
  12.     let reason_array = []
  13.     console.log(args)
  14.     for (i = 0; i < args.length; i++) {
  15.       if (args[i].endsWith('a') || args[i].endsWith('y') || args[i].endsWith('d') || args[i].endsWith('j') || args[i].endsWith('h') || args[i].endsWith('m') || args[i].endsWith('s')) {
  16.         if (parseInt(args[i].slice(0, args[i].length - 1)) == args[i].slice(0, `${args[i].length - 1}`) && args[i] != member) {
  17.           time_array.push(args[i])
  18.  
  19.         };
  20.  
  21.       } else if (args[i] != member) {
  22.         reason_array.push(args[i])
  23.  
  24.       };
  25.     };
  26.     if (!member) {
  27.       const mute_help_embed = new Discord.RichEmbed()
  28.         .setColor(`#66b54a`)
  29.         .setTimestamp()
  30.         if (lan == 'fr') {
  31.           mute_help_embed.setTitle(`Commande ${pref}mute :`)
  32.           mute_help_embed.addField(`Utilisation :`, `${pref}mute [@utilisateur] <raison> <temps>\n[@utilisateur] est obligatoire, <raison> et <temps> ne le sont pas.`)
  33.  
  34.         } else if (lan == 'en') {
  35.           mute_help_embed.setTitle(`${pref}mute command :`)
  36.           mute_help_embed.addField(`Usage :`, `${pref}mute [@user] <reason> <time>\n[@user] is mandatory, <reason> and <time> are not.`)
  37.         };
  38.       message.channel.send(mute_help_embed)
  39.       log_channel.send(log_success);
  40.       return;
  41.  
  42.     } else if (!message.member.hasPermission("MANAGE_ROLES")) {
  43.       if (lan == 'fr') {message.channel.send(`:x: Tu n'as pas la permission de mute des utilisateurs ! (MANAGE_ROLES)`)};
  44.      if (lan == 'en') {message.channel.send(`:x: You don't have the permission to mute members ! (MANAGE_ROLES)`)}
  45.       log_channel.send(log_err_permissions);
  46.       return;
  47.  
  48.     } else if (!message.guild.me.hasPermission("MANAGE_ROLES")) {
  49.       if (lan == 'fr') {message.channel.send(`:x: Je n'ai pas la permission de mute les utilisateurs ! (MANAGE_ROLES)`)};
  50.      if (lan == 'en') {message.channel.send(`:x: I don't have the permission to mute users ! (MANAGE_ROLES)`)};
  51.       log_channel.send(log_err_bot_permissions);
  52.       return;
  53.  
  54.     } else if (member.highestRole.comparePositionTo(message.guild.me.highestRole) > "1") {
  55.       if (lan == 'fr') {message.channel.send(`:x: Cet utilisateur à des rôles plus haut que les miens, je ne peut pas le mute !`)};
  56.       if (lan == 'en') {message.channel.send(`:x: I cannot mute this user, his roles are higher than mine !`)};
  57.       log_channel.send(log_err_bot_permissions);
  58.       return;
  59.  
  60.     } else if (member == message.author.tag) {
  61.       if (lan == 'fr') {message.channel.send(`:warning: Tu comptais sérieusement te mute toi même ?`)};
  62.       if (lan == 'en') {message.channel.send(`:warning: You were really trying to mute yourself ?`)};
  63.       log_channel.send(log_err_invalid_argument);
  64.       return;
  65.  
  66.     } else if (member == message.guild.owner.tag) {
  67.       if (lan == 'fr') {message.channel.send(`:warning: Je ne peux pas mute le propritéaire du serveur !`)};
  68.       if (lan == 'en') {message.channel.send(`:warning: Trying to mute the server's owner is a waste of time right ?`)};
  69.      log_channel.send(log_err_invalid_argument);
  70.      return;
  71.  
  72.    } else {
  73.        con.query("SELECT * FROM `servers` WHERE `server_id` = '"+ message.guild.id +"';", async (err, result) => { if(err) throw err;
  74.          let muted_role_id = result[0].muted_role_id;
  75.          let guild = bot.guilds.get(result[0].server_id);
  76.          if (muted_role_id.length == 0) {
  77.            guild.createRole({
  78.              name: `Muted`,
  79.              color: `BLACK`,
  80.              position: `0`,
  81.              mentionable: `false`,
  82.              permissions: `VIEW_CHANNEL`,
  83.            }, `Mute role created`).then(role => con.query("UPDATE `servers` SET `muted_role_id` = '"+ role.id +"' WHERE `server_id` = '"+ guild.id +"';"), async (err) => { if(err) throw err})
  84.          } else {
  85.            con.query("SELECT * FROM `servers` WHERE `server_id` = '"+ message.guild.id +"';", async (err, result) => { if(err) throw err;
  86.              let muted_role_id = result[0].muted_role_id;
  87.              let guild = bot.guilds.get(result[0].server_id);
  88.              let muted_role = guild.roles.get(muted_role_id);
  89.              message.guild.channels.forEach(channel => channel.overwritePermissions(muted_role, {
  90.                SEND_MESSAGES: false,
  91.                ATTACH_FILES: false,
  92.                ADD_REACTIONS: false
  93.              }, `Mute role's permissions overwritten for every channel.`))
  94.               //member.addRole(muted_role, reason_array)
  95.               if (time_array != 0) {
  96.                 let time_without_date;
  97.                 let time_without_number;
  98.                 let timeout = message.createdTimestamp
  99.                 for (i = 0; i < time_array.length; i++) {
  100.                   time_without_date = time_array[i].slice(0, time_array[i].length - 1);
  101.                   time_without_number = time_array[i].slice(time_array[i].length - 1, time_array[i].length);
  102.                   if (time_without_number == 'y' || time_without_number == 'a') {
  103.                     console.log(`${time_without_date} années`)
  104.                     console.log(`${time_without_date * 365 * 24 * 60 * 60 * 1000} milisecondes en plus`)
  105.                     timeout = timeout + time_without_date * 365 * 24 * 60 * 60 * 1000
  106.                   };
  107.  
  108.                   if (time_without_number == 'd' || time_without_number == 'j') {
  109.                     console.log(`${time_without_date} jours`)
  110.                     console.log(`${time_without_date * 24 * 60 * 60 * 1000} milisecondes en plus`)
  111.                     timeout = timeout + time_without_date  * 24 * 60 * 60 * 1000
  112.                   };
  113.  
  114.                   if (time_without_number == 'h') {
  115.                     console.log(`${time_without_date} heures`)
  116.                     console.log(`${time_without_date * 60 * 60 * 1000} milisecondes en plus`)
  117.                     timeout = timeout + time_without_date * 60 * 60 * 1000
  118.                   };
  119.  
  120.                   if (time_without_number == 'm') {
  121.                     console.log(`${time_without_date} minutes`)
  122.                     console.log(`${time_without_date * 60 * 1000} milisecondes en plus`)
  123.                     timeout = timeout + time_without_date * 60 * 1000
  124.                   };
  125.  
  126.                   if (time_without_number == 's') {
  127.                     console.log(`${time_without_date} secondes`)
  128.                     console.log(`${time_without_date * 1000} milisecondes en plus`)
  129.                     timeout = timeout + time_without_date * 1000
  130.  
  131.                   } else {
  132.                     timeout = 2147483647
  133.                   }
  134.                 };
  135.                 log_channel.send(member.user.tag)
  136.                 log_channel.send(reason_array)
  137.                 log_channel.send(time_array)
  138.                 //con.query("INSERT INTO `users_sanctions` (`type`, `server_id`, `user_username`, `user_id`, `timestamp`, `muted_role_id`) VALUES ('mute', '"+ guild.id +"', '"+ member.user.username +"', '"+ member.id +"', '"+ timeout +"', '"+ muted_role_id +"');", async (err) => { if(err) throw err;})
  139.               }
  140.           });
  141.           }
  142.         });
  143.     };
  144.   },
  145. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement