Advertisement
TrickjumpServer

cooties

Nov 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. async function tj_cmd(message, client, Discord, prefix) {
  2. // Usage: tj <info/give/remove>
  3. let args = message.content.split(" ");
  4. args.shift(); // removes command from argument list
  5. const kv = require("keyv");
  6. const jumps = new kv("sqlite://modules/trickjump/dbs/jumps.db");
  7. const tiers = new kv("sqlite://modules/trickjump/dbs/jumps.db", {namespace: "tiers"});
  8. const user_roles = new kv("sqlite://modules/trickjump/dbs/roles.db");
  9. const tier_list = new kv("sqlite://modules/trickjump/dbs/tier-list.db")
  10. const upload = require("../../../upload_to_pastebin.js")
  11. switch (args[0]) {
  12. case "info":
  13. let to_split = prefix + "tj info ";
  14. jump_info = await jumps.get(message.content.split(to_split)[1])
  15. message.channel.send(jump_info.output + "\r\n\r\n Tier: " + jump_info.tier);
  16. break;
  17. case "give":
  18. jumps.get("jump_list").then(list => {
  19. if (!list.includes(message.content.split(prefix + "tj give ")[1])) {
  20. message.channel.send("That role doesn't exist.")
  21. }
  22. else {
  23. user_roles.get(message.author.id).then(roles => {
  24. if (!roles) {
  25. let list = [message.content.split(prefix + "tj give ")[1]];
  26. if (message.guild.member(message.author).roles.get('634764145765515274')) {
  27. try {
  28. message.guild.member(message.author).setNickname(require("../auto_name.js")(true, message.guild.member(message.author).nickname))
  29. }
  30. catch (err) {
  31. console.log(err)
  32. }
  33. }
  34. message.channel.send("Gave you the role.")
  35. user_roles.set(message.author.id, list);
  36. }
  37. else if (!(roles.includes(message.content.split(prefix + "tj give ")[1]))) {
  38. let list = roles;
  39. if (message.guild.member(message.author).roles.get('634764145765515274')) {
  40. try {
  41. message.guild.member(message.author).setNickname(require("../auto_name.js")(true, message.guild.member(message.author).nickname))
  42. }
  43. catch (err) {
  44. console.log(err)
  45. }
  46. }
  47. list.push(message.content.split(prefix + "tj give ")[1]);
  48. message.channel.send("Gave you the role.")
  49. user_roles.set(message.author.id, list);
  50. }
  51. else {
  52. message.channel.send("You already have that role.");
  53. }
  54. });
  55. }
  56. })
  57. break;
  58. case "remove":
  59. user_roles.get(message.author.id).then(list => {
  60. // Removes element from jump_list, if it exists
  61. let jump_list = list
  62. let index = list.indexOf(message.content.split(prefix + "tj remove ")[1]);
  63. if (index > -1) {
  64. message.channel.send("Removed the role from your list.")
  65. jump_list.splice(index, 1);
  66. }
  67. else {
  68. message.channel.send("You don't have that role.")
  69. }
  70. if (message.guild.member(message.author).roles.get('634764145765515274')) {
  71. try {
  72. message.guild.member(message.author).setNickname(require("../auto_name.js")(false, message.guild.member(message.author).nickname))
  73. }
  74. catch (err) {
  75. console.log(err)
  76. }
  77. }
  78. user_roles.set(message.author.id, jump_list)
  79. });
  80. break;
  81. case "tier":
  82. let tier = message.content.split(prefix + "tj tier ")[1];
  83. tiers.get(tier).then(list => {
  84. if (list) {
  85. upload(list.length + "\r\n\r\n - " + list.join("\r\n - "), function(url) {
  86. message.channel.send("List of jumps in that tier: " + "https://paste.ee/r/" + url);
  87. })
  88. }
  89. else {
  90. message.channel.send("No jumps in that tier exist.")
  91. }
  92. })
  93. break;
  94. case "list":
  95. if (message.content.split(prefix + "tj list ")[1]) {
  96. user_roles.get(message.content.split(prefix + "tj list ")[1]).then(async function (jump_list){
  97. // Join with dashes and newlines and then upload to hastebin and send link to hastebin, if there are any elements
  98. if (!jump_list) {
  99. message.channel.send("You do not have any roles.");
  100. }
  101. else {
  102. var all_jumps = await jumps.get("jump_list")
  103. var total_count = all_jumps.length;
  104. var count = jump_list.length;
  105. var buffer = "Your Jumps\r\n=================================\r\n" + count + "/" + total_count
  106. buffer += "\r\n - " + jump_list.join("\r\n - ")
  107. upload(buffer, function(url) {
  108. message.channel.send("List of roles you have: " + "https://paste.ee/r/" + url);
  109. })
  110. }
  111. })
  112. }
  113. user_roles.get(message.author.id).then(async function (jump_list){
  114. // Join with dashes and newlines and then upload to hastebin and send link to hastebin, if there are any elements
  115. if (!jump_list) {
  116. message.channel.send("You do not have any roles.");
  117. }
  118. else {
  119. var all_jumps = await jumps.get("jump_list")
  120. var total_count = all_jumps.length;
  121. var count = jump_list.length;
  122. var buffer = "Your Jumps\r\n=================================\r\n" + count + "/" + total_count
  123. buffer += "\r\n - " + jump_list.join("\r\n - ")
  124. upload(buffer, function(url) {
  125. message.channel.send("List of roles you have: " + "https://paste.ee/r/" + url);
  126. })
  127. }
  128. })
  129. break;
  130. case "list_all":
  131. let jump_list = await jumps.get("jump_list")
  132. // Join with dashes and newlines and then upload to hastebin and send link to hastebin, if there are any elements
  133. if (jump_list.length === 0) {
  134. message.channel.send("No jumps exist.");
  135. }
  136. else {
  137. let all_tiers = await tier_list.get("list")
  138. let buffer = "ALL ROLES\r\n=================\r\n\r\n\r\n"
  139. let count = 0;
  140. for (var i = 0; i < all_tiers.length; i++) {
  141. buffer += all_tiers[i] + "\r\n==============\r\n"
  142. let current_jumps = await tiers.get(all_tiers[i])
  143. if (!current_jumps) {
  144. all_tiers.splice(all_tiers.indexOf(all_tiers[i]), 1)
  145. tier_list.set(all_tiers)
  146. }
  147. else {
  148. for (var j = 0; j < current_jumps.length; j++) {
  149. if (jump_list.includes(current_jumps[j])) {
  150. buffer += current_jumps[j] + "\r\n"
  151. count++;
  152. }
  153. else {
  154. current_jumps.splice(current_jumps.indexOf(current_jumps[i]), 1)
  155. tiers.set(all_tiers[i], current_jumps)
  156. }
  157. }
  158. buffer += "\r\n\r\n"
  159. }
  160. }
  161. upload(buffer, link => {
  162. message.channel.send(`All jumps (${count}): ` + "https://paste.ee/r/" + link);
  163. })
  164. }
  165. break;
  166. default:
  167. message.channel.send(`Invalid usage. Use ${prefix}commands for usage.`)
  168. break;
  169. }
  170. }
  171. module.exports = tj_cmd;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement