Advertisement
toast_account_i_made

index.js

Jan 10th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const { Client } = require("discord.js");
  3. const { config } = require("dotenv");
  4. const request = require('request');
  5. fs = require("fs");
  6.  
  7. prefix = "!";
  8. embedCol = "#00b300";
  9.  
  10. const client = new Client({
  11.     disableEveryone: true
  12. });
  13.  
  14. config({
  15.     path: __dirname + "/.env"
  16. });
  17.  
  18. function getArgs(messagecont) {
  19.     return messagecont.split(" ");
  20. }
  21.  
  22. client.on("ready", () => {
  23.     console.log("i am depresion");
  24.     jsonunparsed = fs.readFileSync("cmds.json");
  25.     cmdsjson = JSON.parse(jsonunparsed)
  26.     commands = [];
  27.     textcmds = [];
  28.     for (i in cmdsjson) {
  29.         commands[i] = cmdsjson[i]["cmd"];
  30.     }
  31.     for (i in cmdsjson) {
  32.         textcmds[i] = cmdsjson[i]["text"];
  33.     }
  34.     console.log(commands);
  35.     client.user.setPresence({
  36.         activity: {
  37.             name: '!help',
  38.             type: "LISTENING"
  39.         },
  40.         status:"online"
  41.     });
  42. });
  43.  
  44. client.on('message', message => {
  45.     if (message.author.bot==true) {return;};
  46.     msgc = message.content;
  47.     for (i in commands) {
  48.         if (msgc.toLowerCase().startsWith(prefix + commands[i])) {
  49.             if (cmdsjson[i]["response"]!=undefined) {
  50.                 message.channel.send(cmdsjson[i]["response"]);
  51.             }
  52.             if (cmdsjson[i]["func"]!=undefined) {
  53.                 eval(cmdsjson[i]["func"]);
  54.             }
  55.         } else if (msgc.toLowerCase().startsWith(textcmds[i])) {
  56.             if (cmdsjson[i]["response"]!=undefined) {
  57.                 message.channel.send(cmdsjson[i]["response"]);
  58.             }
  59.             if (cmdsjson[i]["func"]!=undefined) {
  60.                 eval(cmdsjson[i]["func"]);
  61.             }
  62.         }
  63.     }
  64. });
  65.  
  66. function helpembed(msg) {
  67.     args = getArgs(msg.content);
  68.     if (args[1]=="") {args[1]=undefined;}
  69.     embededhelp = new Discord.MessageEmbed()
  70.         .setColor(embedCol)
  71.         .setTitle("Commands:")
  72.         .setDescription("All(ish) Commands");
  73.     for (i in cmdsjson) {
  74.         if (cmdsjson[i]["command_help"] != undefined && cmdsjson[i]["help_page"] == args[1]) {
  75.             if (cmdsjson[i]["text"] != undefined) {
  76.                 var textval = cmdsjson[i]["text"];
  77.             } else if (cmdsjson[i]["cmd"] != undefined) {
  78.                 var textval = cmdsjson[i]["cmd"];
  79.             }
  80.            
  81.             var descval = cmdsjson[i]["command_help"];
  82.             eval('embededhelp.addFields({name:"'+textval+'", value:"'+descval+'"});');
  83.         }
  84.     }
  85.     msg.channel.send("",{embed: embededhelp});
  86. }
  87.  
  88. function searchReddit(message, searchquery) {
  89.     request('https://www.reddit.com/r/'+searchquery+'.json', function (error, response, body) {
  90.         var returnedJSON = JSON.parse(body);
  91.         var postnum=returnedJSON["data"]["children"].length;
  92.         //console.log(returnedJSON["data"]["children"].length);
  93.         //console.log(returnedJSON["data"]["children"][0]["data"]["thumbnail"]);
  94.         var imageDat = returnedJSON["data"]["children"][Math.floor(Math.random()*postnum)]["data"]/*["thumbnail"]*/;
  95.        
  96.         if (imageDat["selftext"] != "" || imageDat["url"].includes("gallery")) {searchReddit(message, searchquery); return;}
  97.  
  98.         //console.log(imageDat["media"])
  99.  
  100.         if (imageDat["media"] == null) {
  101.             var postMainCont=imageDat["url"];
  102.         } /*else if (imageDat["media"]["reddit_video"]["scrubber_media_url"] != undefined) {
  103.             var postMainCont=imageDat["media"]["reddit_video"]["scrubber_media_url"];
  104.         }*/ else {
  105.             var postMainCont=imageDat["thumbnail"];
  106.         }
  107.  
  108.         embededhelp = new Discord.MessageEmbed()
  109.             .setColor(embedCol)
  110.             .setDescription("From r/"+imageDat["subreddit"]+" by u/"+imageDat["author_fullname"])
  111.             .setImage(postMainCont);
  112.        
  113.         message.channel.send("",{embed: embededhelp});
  114.     })
  115.      
  116. }
  117.  
  118. function delBotMsgs(msg) {
  119.     msg.react('👌');
  120.  
  121.     /*function filter(m) {
  122.         console.log("Test 1");
  123.         if (m.content.startsWith('!')) {
  124.             console.log("Test 2");
  125.         };
  126.         console.log(m.content);
  127.         return (m.content.startsWith('!'));
  128.     }*/
  129.  
  130.     const filter = m => m.content.startsWith('!');
  131.  
  132.     var channel = msg.channel;
  133.  
  134.     const collector = channel.createMessageCollector(filter, { time: 15000 });
  135.  
  136.     collector.on('collect', m => console.log(`Collected ${m.content}`));
  137.     collector.on('dispose', m => console.log(`disposed ${m.content}`));
  138.     collector.on('end', collected => {
  139.         console.log("ended");
  140.         channel.bulkDelete(collected)
  141.             .then(messages => console.log(messages))
  142.             .catch(console.error)
  143.     });
  144. }
  145. client.login(process.env.TOKEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement