Advertisement
Guest User

index.js

a guest
May 28th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const commando = require('discord.js-commando');
  2. const bot = new commando.Client();
  3. var mysql = require('mysql');
  4. var http = require('http');
  5.  
  6. var count = 0;
  7. var ownerId = 278170906688356352;
  8. var opn = require('opn');
  9.  
  10. var isSearching = false;
  11.  
  12. var itemsCooldown = {};
  13.  
  14. /*var con = mysql.createConnection({
  15.     host: "localhost",
  16.     user: "yourusername",
  17.     password: "yourpassword"
  18.   });
  19.  
  20.   con.connect(function(err) {
  21.     if (err) throw err;
  22.     console.log("Connected!");
  23.   });
  24.   */
  25. bot.registry.registerGroup('random', 'Random');
  26. bot.registry.registerGroup('currencies', 'Currencies');
  27. bot.registry.registerGroup('fun', 'Fun');
  28.  
  29. bot.registry.registerDefaults();
  30. bot.registry.registerCommandsIn(__dirname + "/commands");
  31.  
  32. bot.on('ready', () => {
  33.     console.log('Bot is ready!');
  34.     const defChannel = bot.channels.get("450321378600681476")
  35.     defChannel.send(":wave: Bot loaded successfully!");
  36.   });
  37.  
  38. // set message listener
  39. bot.on('message', message => {
  40.     switch(message.content.toUpperCase()) {
  41.         case '?RESET':
  42.             if (message.author.id != ownerId) {
  43.                 message.reply("You are not able to use this command!");
  44.             } else {
  45.                 resetBot(message.channel);
  46.             }
  47.             break;
  48.  
  49.             case '?SHUTDOWN':
  50.             if (message.author.id != ownerId) {
  51.                 message.reply("You are not able to use this command!");
  52.             } else {
  53.                 shutdownBot(message.channel);
  54.                
  55.             }
  56.             break;
  57.  
  58.         // ... other commands
  59.     }
  60. });
  61.  
  62. // Turn bot off (destroy), then turn it back on
  63. function resetBot(channel) {
  64.     channel.send('Resetting...')
  65.     .then(msg => client.destroy())
  66.     .then(() => client.login("NDUwMzIzMjE1MjU3MTc0MDQ2.Dexkhw.ewim1iShj3fK-kkG2blORwUdk-U"));
  67. }
  68.  
  69. function shutdownBot(channel) {
  70.     channel.send('Shutting down...')
  71.     .then(msg => client.destroy());
  72.     //BREAKMELOLTHISISNTAFUNCTIONSOITWILLDEFINITELYBREAKLMAOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO();
  73. }
  74.  
  75. bot.on('message', message => {
  76.     //if (message.author != "<@450323215257174046>") {
  77.     //    message.channel.send(message.content);
  78.     //}
  79.  
  80.     if (message.content.includes("bot") && message.author != "<@450323215257174046>") {
  81.         message.reply("i heard my name so wat");
  82.     }
  83.  
  84.     if (message.content.startsWith("player info id ")) {
  85.         var id = encodeURIComponent(message.content.slice(15));
  86.         //var url = "http://api.roblox.com/users/" + id;
  87.  
  88.         var url = "/users/" + id;
  89.         var options = {
  90.             host: 'api.roblox.com',
  91.             path: url
  92.         }
  93.         var request = http.request(options, function (res) {
  94.             var data = '';
  95.             res.on('data', function (chunk) {
  96.                 data += chunk;
  97.             });
  98.             res.on('end', function () {
  99.                 var user = JSON.parse(data);
  100.  
  101.                 if (user["errors"]) {
  102.                     message.channel.send(":warning: An error occurred! :warning:"
  103.                     + "\n**Error Code**: " + user['errors'][0]['code'] + "\n**Message**: " + user['errors'][0]['message']);
  104.                 } else {
  105.                     message.channel.send(
  106.                         ":white_check_mark: Got user info! :white_check_mark:" +
  107.                         "\n\n**ID**: " + user["Id"] +
  108.                         "\n**Username**: " + user["Username"] +
  109.                         "\n**AvatarUri**: " + user["AvatarUri"] +
  110.                         "\n**AvatarFinal**: " + user["AvatarFinal"] +
  111.                         "\n**IsOnline**: " + user["IsOnline"]
  112.                 );
  113.                 }
  114.             });
  115.         });
  116.         request.on('error', function (e) {
  117.             console.log(e.message);
  118.         });
  119.         request.end();
  120.     }
  121.  
  122.     if (message.content.startsWith("player info username ")) {
  123.         var id = encodeURIComponent(message.content.slice(21));
  124.         //var url = "http://api.roblox.com/users/" + id;
  125.  
  126.         var url = "/users/get-by-username?username=" + id;
  127.         var options = {
  128.             host: 'api.roblox.com',
  129.             path: url
  130.         }
  131.         var request = http.request(options, function (res) {
  132.             var data = '';
  133.             res.on('data', function (chunk) {
  134.                 data += chunk;
  135.             });
  136.             res.on('end', function () {
  137.                 var user = JSON.parse(data);
  138.  
  139.                 if (user["errors"]) {
  140.                     message.channel.send(":warning: An error occurred! :warning:"
  141.                     + "\nError Code: " + user['errors'][0]['code'] + "\nMessage: " + user['errors'][0]['message']);
  142.                 } else {
  143.                     message.channel.send(
  144.                         ":white_check_mark: Got user info! :white_check_mark:" +
  145.                         "\n\n**ID**: " + user["Id"] +
  146.                         "\n**Username**: " + user["Username"] +
  147.                         "\n**AvatarUri**: " + user["AvatarUri"] +
  148.                         "\n**AvatarFinal**: " + user["AvatarFinal"] +
  149.                         "\n**IsOnline**: " + user["IsOnline"]
  150.                 );
  151.                 }
  152.             });
  153.         });
  154.         request.on('error', function (e) {
  155.             console.log(e.message);
  156.         });
  157.         request.end();
  158.     }
  159.  
  160.     if (message.content === "start searching pls") {
  161.         if (!isSearching) {
  162.             isSearching = true;
  163.         message.channel.send("ok im now looking for cheap limiteds");
  164.         setInterval(function(){
  165.             count += 1;
  166.             console.log(count + "th/rd/st try");
  167.             //if (count == 1 || count == 50 || count == 100 || count == 500 || count == 1000 || count == 10000 || count == 25000 || count == 100000) {
  168.             //    message.channel.send(count + "th/rd/st try");
  169.             //}
  170.         var url = "/catalog/json?Category=2&Subcategory=2&SortType=4&Direction=2";
  171.         var options = {
  172.             host: 'search.roblox.com',
  173.             path: url
  174.         }
  175.         var request = http.request(options, function (res) {
  176.             var data = '';
  177.             res.on('data', function (chunk) {
  178.                 data += chunk;
  179.             });
  180.             res.on('end', function () {
  181.                 //message.channel.send("Retreiving data completed.");
  182.                 var catalog = JSON.parse(data);
  183.                 //message.channel.send("Name: " + catalog[0]["Name"] +
  184.                 //"\nPrice: " + catalog[0]["BestPrice"] + " R$" +
  185.                 //"\nID: " + catalog[0]["AssetId"] + "\nhttps://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId="+ catalog[0]["AssetId"]
  186.             //);
  187.  
  188.             for (i = 0; i < catalog.length; i++) {
  189.                 if (catalog[i]["BestPrice"] < 210) {
  190.  
  191.                     console.log("@here\n:exclamation: Cheap limited found! :exclamation:\n" +
  192.                     "Name: " + catalog[i]["Name"] +
  193.                     "\nPrice: " + catalog[i]["BestPrice"] + " R$" +
  194.                     "\nID: " + catalog[i]["AssetId"] + "\nhere is the url ok " + catalog[i]["AbsoluteUrl"]);
  195.  
  196.                     if (itemsCooldown[catalog[i]["AssetId"]] > Date.now()) return;
  197.                     message.channel.send("@here\n:exclamation: Cheap limited found! :exclamation:\n" +
  198.                         "Name: " + catalog[i]["Name"] +
  199.                         "\nPrice: " + catalog[i]["BestPrice"] + " R$" +
  200.                         "\nID: " + catalog[i]["AssetId"] + "\nhere is the url ok " + catalog[i]["AbsoluteUrl"]);
  201.  
  202.                     itemsCooldown[catalog[i]["AssetId"]] = Date.now() + (1000 * 4)
  203.                 }
  204.             }
  205.             });
  206.         });
  207.         request.on('error', function (e) {
  208.             console.log(e.message);
  209.         });
  210.         request.end();
  211.         }, 250);
  212.     } else {
  213.         message.channel.send("im already searching you dumbfuck");
  214.     }
  215.     }
  216.  
  217.     if (message.content === 'what is my avatar') {
  218.         message.reply(message.author.avatarURL);
  219.     }
  220.  
  221.     if (message.content === 'thx bot') {
  222.         message.reply("np");
  223.     }
  224.  
  225.     if (message.content === 'gtg') {
  226.         message.reply("bye");
  227.     }
  228.  
  229.     if (message.content === 'Hi bot') {
  230.         message.reply("Hello!");
  231.     }
  232.    
  233.   });
  234.  
  235. bot.login(THE BOT TOKEN PUT IT HERE KTHX BYE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement