Advertisement
Guest User

asdasdasd

a guest
Nov 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.35 KB | None | 0 0
  1. // Things we need
  2. const Discord = require("discord.js");
  3. const client = new Discord.Client();
  4. const fs = require("fs");
  5. const config = require("./config.json");
  6. const YTDL = require("ytdl-core");
  7. let points = JSON.parse(fs.readFileSync("./points.json", "utf8"));
  8. let flowerType;
  9. var servers = {};
  10.  
  11. function play(connection, message) {
  12. var server = servers[message.guild.id];
  13.  
  14. server.dispatcher = connection.playStream(YTDL(server.queue[0], { filter: "audioonly" }));
  15.  
  16. server.queue.shift();
  17.  
  18. server.dispatcher.on("end", function () {
  19. if (server.queue[0]) play(connection, message);
  20. else connection.disconnect();
  21. });
  22. }
  23.  
  24. function pickNumber() {
  25. return Math.floor(Math.random() * Math.floor(1001));
  26. }
  27.  
  28. function pickFlower(number) {
  29. if (number == 0) {
  30. flowerType = 'white';
  31. }
  32. if (number == 1) {
  33. flowerType = 'black';
  34. }
  35. if (number > 2 && number < 142) {
  36. flowerType = 'red';
  37. }
  38. if (number > 142 && number < 295) {
  39. flowerType = 'blue';
  40. }
  41. if (number > 295 && number < 441) {
  42. flowerType = 'yellow';
  43. }
  44. if (number > 441 && number < 598) {
  45. flowerType = 'purple'
  46. }
  47. if (number > 598 && number < 742) {
  48. flowerType = 'orange'
  49. }
  50. if (number > 742 && number < 888) {
  51. flowerType = 'mixed'
  52. }
  53. if (number > 888 && number < 1000) {
  54. flowerType = 'assorted'
  55. }
  56. }
  57.  
  58. // Sends things in the cmd and sets the bots activity and status
  59. client.on("ready", function (evt) {
  60. console.log(" ")
  61. console.log(" Connected!")
  62. console.log(" Logged in as: " + client.user.username + " " + client.user.id)
  63. console.log("========================================")
  64. console.log(" ")
  65. client.user.setActivity('oksure', { type: 'PLAYING' });
  66. client.user.setStatus('dnd');
  67. });
  68.  
  69. // This loop reads the /events/ folder and attaches each event file to the appropriate event.
  70. fs.readdir("./events/", (err, files) => {
  71. if (err) return console.error(err);
  72. files.forEach(file => {
  73. let eventFunction = require(`./events/${file}`);
  74. let eventName = file.split(".")[0];
  75. // super-secret recipe to call events with all their proper arguments *after* the `client` var.
  76. client.on(eventName, (...args) => eventFunction.run(client, ...args));
  77. });
  78. });
  79.  
  80. client.on("message", message => {
  81. if (message.author.bot) return;
  82. if (message.content.indexOf(config.prefix) !== 0) return;
  83.  
  84.  
  85. // Define args
  86. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  87. const command = args.shift().toLowerCase();
  88.  
  89. // If the command isnt prefix then find the command it is
  90. if (command != "prefix") {
  91. if (command != "play") {
  92. if (command != "skip") {
  93. if (command != "stop") {
  94. if (command != "level") {
  95. if (command != "give") {
  96. if (command != "remove") {
  97. if (command != "gamble") {
  98. try {
  99. let commandFile = require(`./commands/${command}.js`);
  100. commandFile.run(client, message, args);
  101. } catch (err) {
  102. console.error(err);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. });
  113.  
  114. client.on("message", async message => {
  115. if (message.author.bot) return;
  116. if (message.content.indexOf(config.prefix) !== 0) return;
  117.  
  118. // Define args
  119. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  120. const command = args.shift().toLowerCase();
  121.  
  122. let gameType;
  123. let hocPick;
  124.  
  125. // if the points don"t exist, init to 0;
  126. if (!points[message.author.id]) points[message.author.id] = {
  127. points: 0,
  128. level: 0
  129. };
  130.  
  131. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  132. if (err) console.error(err)
  133. });
  134.  
  135. switch (command) {
  136. case "prefix":
  137. if (message.author.id == config.ownerID) {
  138. let newPrefix = message.content.split(" ").slice(1, 2)[0];
  139.  
  140. if (!newPrefix) {
  141. message.channel.send("cant change prefix to blank");
  142. return;
  143. }
  144. if (newPrefix) {
  145. config.prefix = newPrefix;
  146.  
  147. fs.writeFile("./config.JSON", JSON.stringify(config), (err) => console.error);
  148.  
  149. message.channel.send("prefix has been set to " + newPrefix);
  150. console.log("prefix has been set to " + newPrefix);
  151. }
  152. }
  153.  
  154. if (message.author.id != config.ownerID) {
  155. message.channel.send("you dont have access to this");
  156. }
  157. break;
  158.  
  159. case "play":
  160. if (message.channel.type === 'dm') return;
  161. let linkFromMessage = args.slice(0).join(" ");
  162. const link = linkFromMessage;
  163.  
  164. if (!args[0]) {
  165. message.channel.send("linkplsfuck");
  166. return;
  167. }
  168. if (!message.member.voiceChannel) {
  169. message.channel.send("not in channel");
  170. return;
  171. }
  172. if (!servers[message.guild.id]) servers[message.guild.id] = {
  173. queue: []
  174. };
  175.  
  176. if (link.startsWith('https://www.youtube.com/watch?v=')) {
  177. var server = servers[message.guild.id];
  178.  
  179. server.queue.push(args[0]);
  180.  
  181. if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function (connection) {
  182. play(connection, message);
  183. });
  184.  
  185. console.log("Playing: " + link);
  186. }
  187. if (!link.startsWith('https://www.youtube.com/watch?v=')) {
  188. message.channel.send("not valid");
  189. }
  190. break;
  191.  
  192. case "skip":
  193. if (message.channel.type === 'dm') return;
  194. var server = servers[message.guild.id];
  195.  
  196. if (server.dispatcher) server.dispatcher.end();
  197. break;
  198.  
  199. case "stop":
  200. if (message.channel.type === 'dm') return;
  201. var server = servers[message.guild.id];
  202.  
  203. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  204. break;
  205.  
  206. case "give":
  207. if (message.channel.type === 'dm') return;
  208. let amountFromMessage = args.slice(1).join(" ");
  209. const giveMember = message.mentions.members.first();
  210.  
  211. // if the points don"t exist, init to 0;
  212. if (!points[giveMember.id]) points[giveMember.id] = {
  213. points: 0,
  214. level: 0
  215. };
  216.  
  217. message.reply("gave " + giveMember + " " + amountFromMessage + " points");
  218.  
  219. var x = +points[giveMember.id].points + +amountFromMessage;
  220.  
  221. points[giveMember.id].points = x;
  222.  
  223. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  224. if (err) console.error(err)
  225. });
  226.  
  227. break;
  228.  
  229. case "remove":
  230. if (message.channel.type === 'dm') return;
  231. let amRemoveFromMessage = args.slice(1).join(" ");
  232. const takeMember = message.mentions.members.first();
  233.  
  234. message.reply("took " + amRemoveFromMessage + " points from " + takeMember);
  235.  
  236. var y = +points[takeMember.id].points + -amRemoveFromMessage;
  237.  
  238. points[takeMember.id].points = y;
  239.  
  240. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  241. if (err) console.error(err)
  242. });
  243.  
  244. break;
  245.  
  246. case "level":
  247. let userData = points[message.author.id];
  248.  
  249. if (userData.points < 83) {
  250. userData.level = 0;
  251.  
  252. message.reply(`You are currently level ${userData.level}, with ${userData.points} points.`);
  253. }
  254.  
  255. if (userData.points >= 83 && userData.level != 1) {
  256. userData.level = 1;
  257. }
  258.  
  259. if (userData.level >= 1) {
  260. let curLevel = Math.floor(userData.points / 70);
  261. userData.level = curLevel;
  262.  
  263. message.reply(`You are currently level ${userData.level}, with ${userData.points} points.`);
  264.  
  265. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  266. if (err) console.error(err)
  267. });
  268. }
  269. break;
  270.  
  271. case "gamble":
  272. let gambleData = points[message.author.id];
  273. let amToGamble = args.slice(0).join(" ");
  274.  
  275. message.delete().catch(O_o => { });
  276.  
  277. if (amToGamble > gambleData.points) {
  278. message.reply(`you dont have enough points to gamble that much you only have ` + gambleData.points + " points");
  279. }
  280.  
  281. if (gambleData.points >= amToGamble) {
  282. let mesg = await message.reply(`you have ` + gambleData.points + ` and you're trying to gamble ` + amToGamble + " confirm:");
  283. await mesg.react('👍');
  284. await mesg.react('👎');
  285.  
  286. const filter = (reaction, user) => {
  287. return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
  288. };
  289.  
  290. const reactions = await mesg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
  291. .then(collected => {
  292. const reaction = collected.first();
  293.  
  294. if (reaction.emoji.name === '👍') {
  295. gameType = 'hoc';
  296. mesg.delete().catch(console.error);
  297. console.log(gameType);
  298. }
  299. if (reaction.emoji.name === '👎') {
  300. gameType = 'null';
  301. mesg.delete();
  302. message.reply('closing gamble request');
  303. console.log(gameType);
  304. }
  305. })
  306. .catch(collected => {
  307. message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
  308. message.channel.send('closing gamble request');
  309. mesg.delete();
  310. });
  311. }
  312.  
  313. if (gameType == 'hoc') {
  314. let hocmesg = await message.reply(`hot or cold?`);
  315. await hocmesg.react('🔥');
  316. await hocmesg.react('🍧');
  317.  
  318. const filter = (reaction, user) => {
  319. return ['🔥', '🍧'].includes(reaction.emoji.name) && user.id === message.author.id;
  320. };
  321.  
  322. const reactions = await hocmesg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
  323. .then(collected => {
  324. const reaction = collected.first();
  325.  
  326. if (reaction.emoji.name === '🔥') {
  327. message.reply('you chose hot').then(msg => msg.delete(10000));
  328. hocPick = 'hot';
  329. let numeber = pickNumber();
  330. console.log(numeber);
  331. let flower = pickFlower(numeber)
  332. console.log(flowerType);
  333. message.channel.send('Flower was: ' + flowerType).then(msg => msg.delete(10000));
  334. hocmesg.delete();
  335. }
  336. if (reaction.emoji.name === '🍧') {
  337. message.reply('you chose cold').then(msg => msg.delete(10000));
  338. hocPick = 'cold';
  339. let numeber = pickNumber();
  340. console.log(numeber);
  341. let flower = pickFlower(numeber)
  342. console.log(flowerType);
  343. message.channel.send('Flower was: ' + flowerType).then(msg => msg.delete(10000));
  344. hocmesg.delete();
  345. }
  346. })
  347. .catch(collected => {
  348. message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
  349. message.channel.send('closing gamble request');
  350. mesg.delete();
  351. });
  352.  
  353. if (hocPick == 'hot')
  354. if (flowerType == 'red' || flowerType == 'yellow' || flowerType == 'orange') {
  355. message.channel.send('won').then(msg => msg.delete(10000));
  356.  
  357. var n = +points[message.author.id].points + +amToGamble;
  358. points[message.author.id].points = n;
  359.  
  360. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  361. if (err) console.error(err)
  362. });
  363.  
  364. return;
  365. }
  366. if (hocPick == 'hot')
  367. if (flowerType == 'purple' || flowerType == 'blue' || flowerType == 'assorted') {
  368. message.channel.send('lose ggez').then(msg => msg.delete(10000));
  369.  
  370. var o = +points[message.author.id].points - +amToGamble;
  371. points[message.author.id].points = o;
  372.  
  373. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  374. if (err) console.error(err)
  375. });
  376.  
  377. return;
  378. }
  379. if (hocPick == 'cold')
  380. if (flowerType == 'purple' || flowerType == 'blue' || flowerType == 'assorted') {
  381. message.channel.send('won').then(msg => msg.delete(10000));
  382.  
  383. var n = +points[message.author.id].points + +amToGamble;
  384. points[message.author.id].points = n;
  385.  
  386. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  387. if (err) console.error(err)
  388. });
  389.  
  390. return;
  391. }
  392. if (hocPick == 'cold')
  393. if (flowerType == 'red' || flowerType == 'yellow' || flowerType == 'orange') {
  394. message.channel.send('lose ggez').then(msg => msg.delete(10000));
  395.  
  396. var o = +points[message.author.id].points - +amToGamble;
  397. points[message.author.id].points = o;
  398.  
  399. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  400. if (err) console.error(err)
  401. });
  402.  
  403. return;
  404. }
  405.  
  406. if (flowerType == 'mixed') {
  407. message.channel.send('auto lose ggez').then(msg => msg.delete(10000));
  408.  
  409. var o = +points[message.author.id].points - +amToGamble;
  410. points[message.author.id].points = o;
  411.  
  412. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  413. if (err) console.error(err)
  414. });
  415.  
  416. return;
  417. }
  418. if (flowerType == 'white' || flowerType == 'black') {
  419. message.channel.send('Wow, thats rare.. x100 win').then(msg => msg.delete(10000));
  420.  
  421. var n = +points[message.author.id].points + (+amToGamble * 100);
  422. points[message.author.id].points = n;
  423.  
  424. fs.writeFile("./points.json", JSON.stringify(points), (err) => {
  425. if (err) console.error(err)
  426. });
  427.  
  428. return;
  429. }
  430. }
  431. break;
  432. }
  433. });
  434.  
  435. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement