Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const fs = require('fs');
  3. const axios = require('axios');
  4.  
  5. module.exports.run = async (bot, message, args) => {
  6.  
  7.  
  8. //Assign variables and read files.
  9. let settings = JSON.parse(fs.readFileSync('./data/settings.json', 'utf8'));
  10. let cmdChannel = settings[message.guild.id].defaultcommands
  11. let linkedroles = JSON.parse(fs.readFileSync('./data/linkedroles.json', 'utf8'));
  12. let linkedgroups = JSON.parse(fs.readFileSync('./data/linkedgroups.json', 'utf8'));
  13. let author = message.guild.members.get(message.author.id);
  14.  
  15.  
  16. //Catch if they try and send it in an incorrect channel.
  17. if (cmdChannel !== "#UnknownChannel#" && message.channel.id !== cmdChannel) {
  18. message.delete();
  19. let warningEmbed = new Discord.RichEmbed()
  20. .setColor('E91E4B')
  21. .setTitle('Warning:')
  22. .setDescription(author + " you may only use this command in " + bot.channels.get(cmdChannel).toString() + ".");
  23. return message.channel.send(warningEmbed)
  24. .then(botMessage => {botMessage.delete(10000)});
  25. }
  26.  
  27.  
  28. function updateData(userInfo) {
  29. if (message.member.roles.some(r => ['Lyn Bypass'].includes(r.name))) return;
  30.  
  31. let robloxId;
  32. if (userInfo && userInfo.robloxId){robloxId = userInfo.robloxId;}
  33. let robloxUsername;
  34. if (userInfo && userInfo.robloxUsername){robloxUsername = userInfo.robloxUsername;}
  35. message.member.setNickname(robloxUsername);
  36.  
  37. //Get the group role for the first for loop.
  38. async function getGroup(i, robloxId){
  39. console.log('Check 2')
  40. var response = await axios.get(`https://assetgame.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRole&playerid=${robloxId}&groupid=${i}`);
  41. return response;
  42. }
  43.  
  44. //Get the group role for the second for loop.
  45. async function getGroup2(index2, robloxId){
  46. console.log('Check 3')
  47. var response = await axios.get(`https://assetgame.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRole&playerid=${robloxId}&groupid=${index2.slice(message.guild.id.length)}`)
  48. return response;
  49. }
  50.  
  51. //Assign the group roles if the user is in that group.
  52. for (let i in linkedgroups) {
  53. getGroup(i, robloxId).then( function(response){
  54. if (linkedgroups[i].role !== "N/A") {
  55. let role = message.guild.roles.get(linkedgroups[i].role);
  56. if (response.data !== "Guest") {
  57. message.member.addRole(role);
  58. }
  59. else message.member.removeRole(role);
  60. }
  61. });
  62. }
  63.  
  64. //Assign the group roles for the main group.
  65. for (let index2 in linkedroles) {
  66. getGroup2(index2, robloxId).then( function(response){
  67. var roleName = response.data;
  68. if (linkedroles[index2].role.includes(roleName)) {
  69. let role = message.guild.roles.find(r => r.name === roleName);
  70. message.member.addRole(role);
  71. for (let roleCheck in linkedroles[index2].role) {
  72. let roles = linkedroles[index2].role[roleCheck]
  73. let roleHas = message.member.roles.some(r => r.name === roles);
  74. if (roleHas === true && roles !== roleName) {
  75. let removeRole = message.guild.roles.find(r => r.name === roles);
  76. message.member.removeRole(removeRole);
  77. }
  78. }
  79. }
  80. })
  81. }
  82. }
  83.  
  84. ;(async () => {
  85. var response = await axios({
  86. url: `https://verify.eryn.io/api/user/${message.author.id}`,
  87. method: 'get'
  88. })
  89. let status;
  90. if ( response && response.data && response.data.status){status = response.data.status;}
  91. let robloxUsername;
  92. if (response && response.data && response.data.robloxUsername){robloxUsername = response.data.robloxUsername;}
  93. if (status === "ok") {
  94. let informationEmbed = new Discord.RichEmbed()
  95. .setColor('3498DB')
  96. .setTitle('Information:')
  97. .setDescription(author + " your currently linked Roblox account is `" + robloxUsername + "`. In order to reverify your account, go to https://verify.eryn.io/ and follow the instructions provided.");
  98. message.channel.send(informationEmbed);
  99. updateData(response.data);
  100. }
  101. else if (status === "error") {
  102. let informationEmbed = new Discord.RichEmbed()
  103. .setColor('E91E4B')
  104. .setTitle('Information:')
  105. .setDescription(author + " you do not have a linked Roblox account yet, head to https://verify.eryn.io/ and follow the instructions provided to link your account.");
  106. return message.channel.send(informationEmbed);
  107. }
  108. else {
  109. let errorEmbed = new Discord.RichEmbed()
  110. .setColor('E91E4B')
  111. .setTitle('Error:')
  112. .setDescription(author + " the API, https://verify.eryn.io/, has encountered a critical error. If this persists contact a member of the Manufacturing Department immediately.");
  113. return message.channel.send(errorEmbed);
  114. }
  115. })()
  116. }
  117.  
  118. module.exports.config = {
  119.  
  120. command: 'verify'
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement