Advertisement
BOMBUREK

Untitled

Jul 19th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. const botPrefix = tempVars('botPrefix');
  2. var reactionArray = [];
  3. var rectarray = globalVars('reactionRoleInf');
  4. const _this = this;
  5. var tempRole;
  6. var emojiArray = [];
  7. var roleArray = [];
  8.  
  9. msg.channel.send(`Welcome to the autrole promt.\nPlease now mention/name a role (case sensitive) along with an emoji.\nEx. @role/role ✅`)
  10. .then((message) => {
  11. msg.channel.awaitMessages(response => response.author.id == msg.author.id, {
  12. max: 1,
  13. time: 60000,
  14. errors: ['time'],
  15. })
  16. .then(async function(collected) {
  17. msg.author.lastMessage.delete();
  18. if (collected.first().content.split(/ +/g).length > 1) {
  19. if (collected.first().content.split(/ +/g)[0] != null) {
  20. const tstValidRole = await msg.guild.roles.find(role => role.name === collected.first().content.split(/ +/g)[0]);
  21. if (collected.first().mentions.roles.first() || tstValidRole != null) {
  22. var unicodeStored = collected.first().content.split(/ +/g)[1];
  23. var roleMentioned;
  24. if (collected.first().mentions.roles.first() != null) {
  25. roleMentioned = collected.first().mentions.roles.first();
  26. } else {
  27. roleMentioned = tstValidRole;
  28. }
  29. if (unicodeStored.charCodeAt(0 > 127)) {
  30. reactionArray.push([unicodeStored, roleMentioned.id, roleMentioned.name]);
  31. emojiArray.push(unicodeStored);
  32. roleArray.push(roleMentioned.id);
  33. message.edit(`You have attached the role **${roleMentioned.name}** to the reaction ${unicodeStored}.\nIf this is correct, please respond "confirm".\nIf not, please respond "cancel" to cancel the prompt.`);
  34. msg.channel.awaitMessages(response => response.author.id == msg.author.id, {
  35. max: 1,
  36. time: 60000,
  37. errors: ['time'],
  38. })
  39. .then((collected) => {
  40. msg.author.lastMessage.delete();
  41. if (collected.first().content.toLowerCase() == "confirm") {
  42. reAsk(message)
  43. } else if (collected.first().content.toLowerCase() == "cancel") {
  44. message.delete();
  45. msg.channel.send("Prompt has been cancelled.\nPlease re-execute the command to go through the prompt again!");
  46. } else {
  47. message.delete();
  48. msg.channel.send("Prompt has been cancelled, you didn't provide a valid response!\nPlease re-execute the command to go through the prompt again!");
  49. }
  50. }).catch(() => {
  51. message.delete();
  52. msg.channel.send('Sorry, you didnt provide a valid response in time!\nPlease re-execute the command to go through the prompt again!');
  53. });
  54. } else {
  55. message.delete();
  56. msg.channel.send("Prompt has been cancelled, you didn't provide a valid emoji!\nPlease re-execute the command to go through the prompt again!");
  57. }
  58.  
  59. } else {
  60. message.delete();
  61. msg.channel.send("Prompt has been cancelled, you didn't provide a valid response!\nPlease re-execute the command to go through the prompt again!");
  62. }
  63. } else {
  64. message.delete();
  65. msg.channel.send("Prompt has been cancelled, you didn't provide a valid mentioned role!\nPlease re-execute the command to go through the prompt again!");
  66. }
  67. } else {
  68. message.delete();
  69. msg.channel.send("Prompt has been cancelled, you didn't provide a emoji/mentioned role!\nPlease re-execute the command to go through the prompt again!");
  70. }
  71. }).catch((error) => {
  72. console.log(error);
  73. message.delete();
  74. msg.channel.send('Sorry, you didnt provide a valid response in time!\nPlease re-execute the command to go through the prompt again!');
  75. });
  76. })
  77.  
  78. function reAsk(message) {
  79. if (reactionArray.length != 10) {
  80. var finalText = "";
  81. reactionArray.forEach(subarray => {
  82. finalText = finalText + `${subarray[0]} => ${subarray[2]}\n`
  83. })
  84. message.edit(`So far you have the following connections (Max 10)\n ${finalText}\n\nIf you would like to attach another reaction to a role, please insert a role along with an emoji.\nIf not, please reply with "done".\nIf you would like to cancel the prompt, please respond with "cancel"`);
  85. msg.channel.awaitMessages(response => response.author.id == msg.author.id, {
  86. max: 1,
  87. time: 60000,
  88. errors: ['time'],
  89. })
  90. .then(async function(collected) {
  91. msg.author.lastMessage.delete();
  92. if (collected.first().content.toLowerCase() == "done") {
  93. done(message)
  94. } else if (collected.first().mentions.roles.first() == "cancel") {
  95. message.delete();
  96. msg.channel.send("Prompt has been cancelled.\nPlease re-execute the command to go through the prompt again!");
  97. } else {
  98. if (collected.first().content.split(/ +/g).length > 1) {
  99. const tstValidRole = await msg.guild.roles.find(role => role.name === collected.first().content.split(/ +/g)[0]);
  100. if (collected.first().mentions.roles.first() || tstValidRole != null) {
  101. var unicodeStored = collected.first().content.split(/ +/g)[1];
  102. if (collected.first().mentions.roles.first() != null) {
  103. roleMentioned = collected.first().mentions.roles.first();
  104. } else {
  105. roleMentioned = tstValidRole;
  106. }
  107. if (unicodeStored != null) {
  108. if (!emojiArray.includes(unicodeStored)) {
  109. if (!roleArray.includes(roleMentioned.id)) {
  110. if (unicodeStored.charCodeAt(0 > 127)) {
  111. reactionArray.push([unicodeStored, roleMentioned.id, roleMentioned.name]);
  112. emojiArray.push(unicodeStored);
  113. roleArray.push(roleMentioned.id);
  114. reAsk(message)
  115. } else {
  116. message.delete();
  117. msg.channel.send("Prompt has been cancelled, you used the same emoji twice for differnt roles!\nPlease re-execute the command to go through the prompt again!");
  118. }
  119. } else {
  120. message.delete();
  121. msg.channel.send("Prompt has been cancelled, you used the same role twice in the prompt!\nPlease re-execute the command to go through the prompt again!");
  122. }
  123. } else {
  124. message.delete();
  125. msg.channel.send("Prompt has been cancelled, you didn't provide a valid emoji!\nPlease re-execute the command to go through the prompt again!");
  126. }
  127. }
  128. } else {
  129. message.delete();
  130. msg.channel.send("Prompt has been cancelled, you didn't mention a valid role!\nPlease re-execute the command to go through the prompt again!");
  131. }
  132. } else {
  133. message.delete();
  134. msg.channel.send("Prompt has been cancelled, you didn't provide a emoji/mentioned role!\nPlease re-execute the command to go through the prompt again!");
  135. }
  136. }
  137. }).catch(() => {
  138. message.delete();
  139. msg.channel.send('Sorry, you didnt provide a valid response in time!\nPlease re-execute the command to go through the prompt again!');
  140. });
  141. } else {
  142. done(message);
  143. }
  144.  
  145. }
  146.  
  147. function done(message) {
  148. var finalText = "";
  149. reactionArray.forEach(subarray => {
  150. finalText = finalText + `${subarray[0]} => ${subarray[2]}\n`
  151. })
  152. message.edit(`Final conformation menu\n\nBelow is the list of reactions to their roles\n${finalText}\n\nIf this is correct, please respond with a mention to a text channel where the role menu will be sent.\nIf this isn't correct, respond with "cancel" to cancel the prompt.`)
  153. msg.channel.awaitMessages(response => response.author.id == msg.author.id, {
  154. max: 1,
  155. time: 60000,
  156. errors: ['time'],
  157. })
  158. .then((collected) => {
  159. msg.author.lastMessage.delete();
  160. if (collected.first().mentions.channels.first()) {
  161. var menchannel = collected.first().mentions.channels.first()
  162. message.delete();
  163. menchannel.send({
  164. embed: {
  165. color: 0xffff00,
  166. title: "Wybierz Swoją Płeć",
  167. description: `Użyj reakcji przypisanej do podanej roli aby otrzymąć daną rolę.\n${finalText}`,
  168. timestamp: new Date()
  169. }
  170. })
  171. .then(embedmessage => {
  172. reactionArray.forEach(async function(subarray) {
  173. await embedmessage.react(subarray[0])
  174. })
  175. rectarray.push({
  176. [embedmessage.id]: reactionArray
  177. })
  178. _this.storeValue(rectarray, 3, "reactionRoleInf", cache);
  179. _this.callNextAction(cache);
  180. })
  181. } else if (collected.first().content == "cancel") {
  182. message.delete();
  183. msg.channel.send("Prompt has been cancelled.\nPlease re-execute the command to go through the prompt again!");
  184. } else {
  185. message.delete();
  186. msg.channel.send("Prompt has been cancelled, you didn't provide a valid response!\nPlease re-execute the command to go through the prompt again!");
  187. }
  188. }).catch(() => {
  189. message.delete();
  190. msg.channel.send('Sorry, you didnt provide a valid response in time!\nPlease re-execute the command to go through the prompt again!');
  191. });
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement