Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

ala89 May 19th, 2020 (edited) 885 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateMemberInGuild(userID, guild, filterForce, filterRemove) {
  2.    
  3.     const member = guild.members.get(userID)
  4.  
  5.     const guildSettings = getGuildSettings(guild)
  6.  
  7.     if (guildSettings.blacklist && member.roles.has(guildSettings.blacklist)) return
  8.  
  9.     if (filterForce && !guildSettings.autoRole && !member.roles.some(e => guildSettings.roles.some(f => f.id === e.id))) return
  10.  
  11.     const userData = getUserData(userID)
  12.  
  13.     let subscriberCount
  14.  
  15.     if (userData.channel) subscriberCount = userData.channel.subscriberCount
  16.  
  17.     else if (filterRemove) subscriberCount = -1
  18.  
  19.     else return
  20.  
  21.     return new Promise(res => {
  22.  
  23.         const roles = guildSettings.roles
  24.             .filter(e => guild.roles.get(e.id).calculatedPosition < guild.me.highestRole.calculatedPosition)
  25.  
  26.         if (!roles.size) return res([guild.id, []])
  27.  
  28.         const newRoles = new Set(member.roles.map(e => e.id))
  29.        
  30.         if (guildSettings.rolesStack) {
  31.  
  32.             const [ toAdd, toRemove ] = roles.partition((v, k) => subscriberCount >= k)
  33.  
  34.             toAdd.forEach(e => newRoles.add(e.id))
  35.  
  36.             toRemove.forEach(e => newRoles.delete(e.id))
  37.  
  38.             member.edit({
  39.                 roles: [...newRoles]
  40.             }).finally(() => {
  41.  
  42.                 res([guild.id, toAdd.array()])
  43.  
  44.             })
  45.            
  46.         }
  47.  
  48.         else {
  49.  
  50.             roles.forEach(e => newRoles.delete(e.id))
  51.  
  52.             const topRole = roles.get(Math.max(...roles.filter((v, k) => subscriberCount >= k).keyArray()))
  53.  
  54.             if (topRole) newRoles.add(topRole.id)
  55.  
  56.             member.edit({
  57.                 roles: [...newRoles]
  58.             }).finally(() => res([guild.id, topRole ? [ topRole.id ] : []]))
  59.            
  60.         }
  61.  
  62.     })
  63.  
  64. }
  65.  
  66. async function updateUserGlobal(userID) {
  67.  
  68.     const result = await Promise.all(client.guilds.filter(guild => guild.members.has(userID) && guild.me.hasPermission('MANAGE_ROLES')).map(guild => updateMemberInGuild(userID, guild, true, true)))
  69.     return new Discord.Collection(result.filter(e => e))
  70.  
  71. }
  72.  
  73. // une commande
  74.  
  75. commands.set('getrole', {
  76.  
  77.     run: function (message, args, guildSettings, language) {
  78.  
  79.         const member = message.mentions.members.first() || message.member
  80.  
  81.         const isRemote = member.id !== message.author.id
  82.  
  83.         const userData = getUserData(member.id)
  84.  
  85.         if (isRemote) {
  86.  
  87.             if (!message.guild.me.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  88.                 .setError(language.missingManageRolesPermission))
  89.  
  90.             if (member.user.bot) return message.channel.send(new Embed()
  91.                 .setError(language.getRoleBot(guildSettings.prefix)))
  92.  
  93.             if (guildSettings.blacklist && member.roles.has(guildSettings.blacklist)) return message.channel.send(new Embed()
  94.                 .setError(language.getRoleBlacklistedRemote(member.id)))
  95.  
  96.             if (guildSettings.linkRole) {
  97.  
  98.                 if (guildSettings.linkRole === message.guild.defaultRole.id && !message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  99.                     .setError(language.cantUseGetRole(guildSettings.prefix)))
  100.  
  101.                 if (!message.member.roles.has(guildSettings.linkRole) && !message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  102.                     .setError(language.missingRoleOrPermission(guildSettings.linkRole, 'MANAGE_ROLES')))
  103.  
  104.             }
  105.  
  106.             else {
  107.  
  108.                 if (!message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  109.                     .setError(language.missingPermission('MANAGE_ROLES')))
  110.  
  111.             }
  112.  
  113.             if (!userData.channel) return message.channel.send(new Embed()
  114.                 .setWarning(language.memeberHasNoLinkedChannel(member.id, guildSettings.prefix)))
  115.  
  116.             updateMemberInGuild(member.id, message.guild).then(function () {
  117.  
  118.                 message.channel.send(new Embed()
  119.                     .setSuccess(language.getRoleRemoteSuccess(member.id)))
  120.  
  121.             })
  122.  
  123.         }
  124.  
  125.         else {
  126.  
  127.             if (userData.channel) {
  128.  
  129.                 if (!message.guild.me.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  130.                     .setError(language.missingManageRolesPermission))
  131.                
  132.                 if (guildSettings.blacklist && message.member.roles.has(guildSettings.blacklist)) return message.channel.send(new Embed()
  133.                     .setError(language.getRoleBlacklisted))
  134.  
  135.                 if (guildSettings.linkRole) {
  136.  
  137.                     if (!message.member.roles.has(guildSettings.linkRole) && !message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  138.                         .setError(language.missingRoleOrPermission(guildSettings.linkRole, 'MANAGE_ROLES')))
  139.  
  140.                 }
  141.  
  142.                 else {
  143.  
  144.                     if (!message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  145.                         .setError(language.missingPermission('MANAGE_ROLES')))
  146.  
  147.                 }
  148.  
  149.                 updateMemberInGuild(member.id, message.guild).then(function () {
  150.  
  151.                     message.channel.send(new Embed()
  152.                         .setSuccess(language.getRoleSuccess))
  153.    
  154.                 })
  155.    
  156.             }
  157.  
  158.             else {
  159.  
  160.                 const { nonce, linkURL } = generateLinkURL()
  161.    
  162.                 provisionalLinks.set(nonce, {
  163.                     channelID: message.channel.id,
  164.                     guildID: message.guild.id,
  165.                     type: 'getrole'
  166.                 })
  167.  
  168.                 if (!message.guild.me.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  169.                     .setWarning(language.unlinkedDiscordAccount, true)
  170.                     .setDescription(`${language.getRoleMissingManageRolesPermission}\n\n${language.linkSteps(linkURL)}`))
  171.  
  172.                 if (guildSettings.blacklist && message.member.roles.has(guildSettings.blacklist)) return message.channel.send(new Embed()
  173.                     .setWarning(language.unlinkedDiscordAccount, true)
  174.                     .setDescription(`${language.getRoleSelfBlacklisted}\n\n${language.linkSteps(linkURL)}`))
  175.  
  176.                 if (!(guildSettings.linkRole && message.member.roles.has(guildSettings.linkRole)) && !message.member.hasPermission('MANAGE_ROLES')) return message.channel.send(new Embed()
  177.                     .setWarning(language.unlinkedDiscordAccount, true)
  178.                     .setDescription(`${language.getRoleSelfMissingPerm(guildSettings.linkRole, 'MANAGE_ROLES')}\n\n${language.linkSteps(linkURL)}`))
  179.    
  180.                 message.channel.send(new Embed()
  181.                     .setWarning(language.unlinkedDiscordAccount, true)
  182.                     .setDescription(language.linkSteps(linkURL)))
  183.  
  184.             }
  185.  
  186.         }
  187.        
  188.     },
  189.  
  190.     guildOnly: true
  191.  
  192. })
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
Top