ļ»æ
Guest User

Untitled

a guest
Dec 14th, 2019
623
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const config = require("./config.json");
  2. const Discord = require("discord.js");
  3. const bot = new Discord.Client({disableEveryone: true});
  4. const commandTimeout = new Set();
  5. const invites = {};
  6. const wait = require('util').promisify(setTimeout);
  7.  
  8. bot.on("ready", async () => {
  9. // "ready" isn't really ready. We need to wait a spell.
  10. wait(1000);
  11.  
  12. // Load all invites for all guilds and save them to the cache.
  13. bot.guilds.forEach(g => {
  14. g.fetchInvites().then(guildInvites => {
  15. invites[g.id] = guildInvites;
  16. });
  17. });
  18. console.log(`Invites | Logged in as ${bot.user.username}#${bot.user.discriminator}`)
  19. var status = (`${bot.users.size} users | ${config.prefix}help`)
  20. bot.user.setActivity(status, { type: 'LISTENING' });
  21. console.log(`Invites | Status set to '${status}'`)
  22. if (bot.guilds.size < 2) {
  23. console.log(`Invites | ${bot.guilds.size} Guild`)
  24. } else {
  25. console.log(`Invites | ${bot.guilds.size} Guilds`)
  26. }
  27. if (bot.users.size < 2) {
  28. console.log(`Invites | ${bot.users.size} User`)
  29. } else {
  30. console.log(`Invites | ${bot.users.size} Users`)
  31. }
  32. console.log(`Invites | Client ID: ${bot.user.id}`)
  33. console.log(`Invites | Token: ${config.token}`)
  34. console.log(`Invites | Invite Link: https://discordapp.com/oauth2/authorize?&client_id=${bot.user.id}&scope=bot&permissions=8`)
  35. });
  36.  
  37. bot.on('guildMemberAdd', member => {
  38. console.log(`[LOG] ${member.user.username}#${member.user.discriminator} joined the server`)
  39. member.addRole(member.guild.roles.find(val => val.name === 'Member'));
  40. member.guild.fetchInvites().then(guildInvites => {
  41. // This is the *existing* invites for the guild.
  42. const ei = invites[member.guild.id];
  43. // Update the cached invites for the guild.
  44. invites[member.guild.id] = guildInvites;
  45. // Look through the invites, find the one for which the uses went up.
  46. const invite = guildInvites.find(i => ei.get(i.code).uses < i.uses);
  47. // This is just to simplify the message being sent below (inviter doesn't have a tag property)
  48. const inviter = bot.users.get(invite.inviter.id);
  49. const logChannel = member.guild.channels.find(channel => channel.name === "šŸšŖ-join-leave");
  50. var fs = require('fs')
  51. var joinedlist = fs.readFileSync('joined.txt', 'utf8');
  52. var newjoinedlist = joinedlist + `\n${member.user.id}`
  53. fs.writeFile("joined.txt", newjoinedlist, function(err) {
  54. if(err) {
  55. return console.log(err);
  56. }
  57. })
  58. if (joinedlist.includes(member.user.id) === false) {
  59. var path = `${inviter.id}.txt`
  60. if (fs.existsSync(path)) {
  61. var invitecount = fs.readFileSync(path, 'utf8');
  62. var newinvitecount = parseInt(invitecount) + parseInt(1)
  63. fs.writeFile(path, newinvitecount, function(err) {
  64. if(err) {
  65. return console.log(err);
  66. }
  67. })
  68. console.log(`[LOG] ${path} modified.`)
  69. logChannel.send(`<@${member.user.id}> joined using invite code **${invite.code}** from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **${newinvitecount}** invites.`);
  70. if ((newinvitecount % 3) === 0) {
  71. var keylist = fs.readFileSync('keys.txt', 'utf8');
  72. var keyarray = keylist.split('\n')
  73. var keyarrayforrewrite = keylist.split('\n')
  74. var newkeyarray = keyarrayforrewrite.splice(1)
  75. var newkeylist = newkeyarray.join('\n')
  76. fs.writeFile("keys.txt", newkeylist, function(err) {
  77. if(err) {
  78. return console.log(err);
  79. }
  80. })
  81. bot.users.get(inviter.id).send(keyarray[0])
  82. }
  83. else {
  84. return;
  85. }
  86. if (newinvitecount === 3) {
  87. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Rookie (3+ Invites)'));
  88. }
  89. else if (newinvitecount === 5) {
  90. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Super (5+ Invites)'));
  91. }
  92. else if (newinvitecount === 10) {
  93. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Elite (10+ Invites)'));
  94. }
  95. else if (newinvitecount === 25) {
  96. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Ultra (25+ Invites)'));
  97. }
  98. else if (newinvitecount === 50) {
  99. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Pro (50+ Invites)'));
  100. }
  101. else if (newinvitecount === 100) {
  102. member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'VIP (100+ Invites)'));
  103. }
  104. }
  105. else {
  106. fs.writeFile(path, '1', function (err) {
  107. if (err) throw err;
  108. console.log(`[LOG] ${path} created.`)
  109. })
  110. logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **1** invite.`);
  111. }
  112. }
  113. else {
  114. var path = `${inviter.id}.txt`
  115. if (fs.existsSync(path)) {
  116. var invitecount = fs.readFileSync(path, 'utf8');
  117. var newinvitecount = parseInt(invitecount) + parseInt(0)
  118. fs.writeFile(path, newinvitecount, function(err) {
  119. if(err) {
  120. return console.log(err);
  121. }
  122. })
  123. console.log(`[LOG] ${path} modified.`)
  124. logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **${newinvitecount}** invites.`);
  125. }
  126. else {
  127. logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.`);
  128. }
  129. }
  130. });
  131. })
  132.  
  133. bot.on("message", async message => {
  134. var status = (`${bot.users.size} users | ${config.prefix}help`)
  135. bot.user.setActivity(status, { type: 'LISTENING' });
  136. if (message.author.bot) return;
  137. if (!message.content.startsWith(config.prefix)) {
  138. if (message.channel.id !== "654808100897030160") {
  139. return;
  140. }
  141. else {
  142. if (message.member.voiceChannel === undefined) {
  143. message.delete()
  144. message.author.send("Messages can only be sent in <#654808100897030160> if you're in a voice channel.")
  145. }
  146. else {
  147. return;
  148. }
  149. }
  150. };
  151. var args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  152. var command = args.shift().toLowerCase();
  153. if (command === "ping") {
  154. console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}ping`)
  155. var m = await message.channel.send("Pong!")
  156. m.edit(`Pong! ${m.createdTimestamp - message.createdTimestamp}ms`)
  157. }
  158. else if (command === "help") {
  159. console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}help`)
  160. message.react('āœ…')
  161. var helpembed = new Discord.RichEmbed()
  162. .setColor('#ee3734')
  163. .setTitle('Help')
  164. .setDescription(`__**General**__\n**${config.prefix}help** Displays all commands\n\n__**Casino**__\n**${config.prefix}spin** Take your chances at winning a steam key!`)
  165. message.author.send(helpembed)
  166. }
  167. else if (command === "spin") {
  168. const casinoleft = bot.emojis.get("655003282707841065");
  169. const casinoright = bot.emojis.get("655004694988455937");
  170. console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}spin`)
  171. if (message.channel.id !== "654804323535945765") {
  172. message.channel.send(`Daily spins can only be completed in <#654804323535945765>.`)
  173. return;
  174. }
  175. else {
  176. if (commandTimeout.has(message.author.id)) {
  177. message.channel.send(`You can only spin once every 24 hours!`)
  178. }
  179. else {
  180. commandTimeout.add(message.author.id)
  181. setTimeout(() => {
  182. commandTimeout.delete(message.author.id);
  183. }, 86400000);
  184. var spinrng = (Math.random() * (9 - 0) + 0)
  185. console.log(`[SPIN] ${message.author.username}#${message.author.discriminator} rolled ${spinrng}`)
  186. if (spinrng > 8) {
  187. var n = await message.channel.send(`${casinoleft} | šŸŽ° | ${casinoright}\nāŒ | āŒ | āœ…\nāœ… | āŒ | āœ…\nāŒ | āŒ | āŒ`)
  188. setTimeout(() => {
  189. n.edit(`${casinoleft} | šŸŽ° | ${casinoright}\nāœ… | āœ… | āœ…\nāŒ | āŒ | āœ…\nāœ… | āŒ | āœ…`);
  190. }, 1500);
  191. setTimeout(() => {
  192. n.edit(`${casinoleft} | šŸŽ° | ${casinoright}\nāœ… | āŒ | āŒ\nāœ… | āœ… | āœ…\nāŒ | āŒ | āœ…`);
  193. }, 2500);
  194. setTimeout(() => {
  195. message.channel.send(`**Winnings:**\nšŸŽ‰ <@${message.author.id}> You have won 1x Steam Key! Check your DMs for your prize! šŸŽ‰`)
  196. }, 2600);
  197. setTimeout(() => {
  198. var fs = require('fs');
  199. var keylist = fs.readFileSync('keys.txt', 'utf8');
  200. var keyarray = keylist.split('\n')
  201. var keyarrayforrewrite = keylist.split('\n')
  202. var newkeyarray = keyarrayforrewrite.splice(1)
  203. var newkeylist = newkeyarray.join('\n')
  204. fs.writeFile("keys.txt", newkeylist, function(err) {
  205. if(err) {
  206. return console.log(err);
  207. }
  208. })
  209. message.author.send(keyarray[0])
  210. }, 2600);
  211. }
  212. else {
  213. var n = await message.channel.send(`${casinoleft} | šŸŽ° | ${casinoright}\nāŒ | āŒ | āœ…\nāœ… | āŒ | āœ…\nāŒ | āŒ | āŒ`)
  214. setTimeout(() => {
  215. n.edit(`${casinoleft} | šŸŽ° | ${casinoright}\nāŒ | āŒ | āŒ\nāŒ | āŒ | āœ…\nāœ… | āŒ | āœ…`);
  216. }, 1500);
  217. setTimeout(() => {
  218. n.edit(`${casinoleft} | šŸŽ° | ${casinoright}\nāœ… | āŒ | āŒ\nāŒ | āŒ | āŒ\nāŒ | āŒ | āœ…`);
  219. }, 2500);
  220. setTimeout(() => {
  221. message.channel.send(`āŒ You have lost! Try again tomorrow! āŒ`)
  222. }, 2600);
  223. }
  224. }
  225. }
  226. }
  227. });
  228.  
  229. bot.login(config.token);
RAW Paste Data