Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, version, RichEmbed } = require('discord.js');
  2. const fs = require('fs');
  3. let timeRemaining = require('./time.json');
  4. const settings = require('./settings.json');
  5. const moment = require('moment');
  6. require('moment-duration-format');
  7. const client = new Client();
  8. const tick = 1000;
  9. const popura = require('popura');
  10. const animeClient = popura(settings.mal.username, settings.mal.password);
  11. const he = require('he');
  12. const commandConfigs = require('./commandconfigs.json');
  13. const prefix = '-';
  14. const os = require('os');
  15. const snekfetch = require('snekfetch');
  16. const xml = require('util').promisify(require('xml-simple').parse);
  17.  
  18.  
  19. log('Logging in...');
  20. client.login(settings.token);
  21.  
  22. client.on('ready', () => {
  23.     log(`Logged in as ${client.user.tag}.`);
  24. });
  25.  
  26. client.on('message', async (msg) => {
  27.     msg.content = msg.content.replace(client.user.toString(), '').toLowerCase().trim();
  28.  
  29.     let command = msg.content.split(' ')[0];
  30.     const args = msg.content.split(' ').slice(1);
  31.  
  32.     if (msg.isMentioned(client.user.id)) {
  33.         if (command === 'clean') {
  34.             if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
  35.                 return msg.channel.send('You\'re not authorized to use this command.');
  36.             }
  37.             if (args[0] === '--force') {
  38.                 msg.channel.send('This command will clean the channel **immediately, without a warning**. Proceed?\nAnswer with `yes`/`no`.');
  39.                 const collector = msg.channel.createMessageCollector(m => msg.author.id === m.author.id, { time: 40000 });
  40.                 collector.on('collect', (m) => {
  41.                     if (m.content.toLowerCase() === 'yes') {
  42.                         msg.channel.send('Force cleaning..');
  43.                         timeRemaining = 1000;
  44.                     } else {
  45.                         msg.channel.send('Force clean canceled.');
  46.                     }
  47.                     return collector.stop();
  48.                 });
  49.             } else {
  50.                 timeRemaining = settings.timeBeforeWarning;
  51.                 msg.channel.send(`Clean commencing in ${moment.duration(timeRemaining, 'milliseconds').format('hh:mm:ss')}.`);
  52.             }
  53.         }
  54.         Object.keys(commandConfigs.mentionresponses)
  55.             .forEach(reply => {
  56.                 if (msg.content.replace(/ /g, '').includes(reply)) {
  57.                     let text = commandConfigs.mentionresponses[reply].replyText.replace(/\$author/g, msg.author.toString());
  58.                     let image = commandConfigs.mentionresponses[reply].imageURL;
  59.                     if (commandConfigs.mentionresponses[reply].customResponses) {
  60.                         if (Object.keys(commandConfigs.mentionresponses[reply].customResponses).includes(msg.author.id)) {
  61.                             text = commandConfigs.mentionresponses[reply].customResponses[msg.author.id].replyText;
  62.                             image = commandConfigs.mentionresponses[reply].customResponses[msg.author.id].imageURL;
  63.                         }
  64.                     }
  65.                     msg.channel.send(text, { file: image });
  66.                 }
  67.             });
  68.     } else if (msg.content.startsWith(prefix)) {
  69.         command = command.slice(prefix.length, command.length);
  70.         if (command === 'hentai') {
  71.             let numarg;
  72.             if (!parseInt(args[0])) {
  73.                 numarg = 2;
  74.             } else if (parseInt(args[0]) > 25 || parseInt(args[0]) < 1) {
  75.                 return msg.channel.send('The amount of images must be between 1 and 25.')
  76.             } else if (parseInt(args[0])) {
  77.                 numarg = parseInt(args[0])
  78.             }
  79.             const text = parseInt(args[0]) ? args.slice(1).join(' ') || '' : args.join(' ') || ''
  80.             try {
  81.                 console.log(text)
  82.                 console.log(numarg)
  83.                 let res = await snekfetch.get(`https://gelbooru.com/index.php?page=dapi&s=post&q=index${'&tags=' + text || ''}&json=1`);
  84.                 res = randomsFromArr(JSON.parse(res.text), numarg)
  85.                 console.log(res)
  86.                 res.map(obj => msg.channel.send({ file: `http://${obj.file_url.replace('//', '')}` }))
  87.             } catch (err) {
  88.                 return msg.channel.send('No results found. Try a different query or ask for less results.')
  89.             }
  90.         }
  91.  
  92.         if (command === 'eval') {
  93.             let input = args.join(' ');
  94.             const silent = input.includes('--silent');
  95.             const asynchr = input.includes('--async');
  96.             if (silent || asynchr) {
  97.                 input = input.replace(/--silent|--async/g, '');
  98.             }
  99.  
  100.             let result;
  101.             try {
  102.                 result = asynchr ? eval(`(async()=>{return ${input}})();`) : eval(input);
  103.                 if (result instanceof Promise && asynchr) {
  104.                     result = await result;
  105.                 }
  106.                 if (typeof result !== 'string') {
  107.                     result = util.inspect(result, { depth: 0 });
  108.                 }
  109.                 const tokenRegex = new RegExp(client.token, 'gi');
  110.                 result = result.replace(tokenRegex, '[TOKEN]');
  111.             } catch (err) {
  112.                 result = err.message;
  113.             }
  114.  
  115.             if (!silent) {
  116.                 msg.edit(`${input}\n\`\`\`js\n${result}\n\`\`\``);
  117.             } else {
  118.                 msg.delete();
  119.             }
  120.         }
  121.  
  122.         if (command === 'anime') {
  123.             let res = await animeClient.searchAnimes(args.join(' '));
  124.             res = res[0];
  125.             if (!res) {
  126.                 return msg.channel.send(`No anime results found for ${args.join(' ')}. Did you perhaps mean to use the \`manga\` command?`);
  127.             }
  128.             msg.channel.send(he.decode(res.synopsis.replace(/\n\r\n\n\r\n/g, '\n\n').replace('[Written by MAL Rewrite]', '')).slice(0, 1990), { embed: {
  129.                 title: 'Information',
  130.                 url: `https://myanimelist.net/anime/${res.id}`,
  131.                 description: `Type: ${res.type}\nTitle: ${res.title} ${res.english ? `(English: ${res.english})` : ''}\nStatus: ${res.status}\nStart date: ${res.start_date}\nEnd date: ${res.end_date === '0000-00-00' ? 'TBD' : res.end_date}\nEpisodes: ${res.episodes === 0 ? 'TBD' : res.episodes}\nScore: ${res.score}\n${res.synonyms.length ? `Synonyms: ${res.synonyms.join(', ')}` : ''}\nURL: https://myanimelist.net/anime/${res.id}`,
  132.                 thumbnail: { url: res.image }
  133.             }, code: true });
  134.         }
  135.  
  136.         if (command === 'manga') {
  137.             let res = await animeClient.searchMangas(args.join(' '));
  138.             res = res[0];
  139.             if (!res) {
  140.                 return msg.channel.send(`No manga results found for ${args.join(' ')}. Did you perhaps mean to use the \`anime\` command?`);
  141.             }
  142.             msg.channel.send(he.decode(res.synopsis.replace(/\n\r\n\n\r\n/g, '\n\n').replace('[Written by MAL Rewrite]', '')).slice(0, 1990), { embed: {
  143.                 title: 'Information',
  144.                 url: `https://myanimelist.net/manga/${res.id}`,
  145.                 description: `Type: ${res.type}\nTitle: ${res.title} ${res.english === res.title ? `(English: ${res.english})` : ''}\nStatus: ${res.status}\nStart date: ${res.start_date}\nEnd date: ${res.end_date === '0000-00-00' ? 'TBD' : res.end_date}\nChapters: ${res.chapters === 0 ? 'TBD' : res.chapters}\nVolumes: ${res.volumes === 0 ? 'TBD' : res.volumes}\nScore: ${res.score}\n${res.synonyms.length ? `Synonyms: ${res.synonyms.join(', ')}` : ''}\nURL: https://myanimelist.net/anime/${res.id}`,
  146.                 thumbnail: { url: res.image }
  147.             }, code: true });
  148.         }
  149.  
  150.         if (command === 'neko') {
  151.             if (args[0] === 'lewd') {
  152.                 if (!msg.channel.nsfw) {
  153.                     return msg.channel.send('I don\'t think I\'m allowed to post those here... Maybe try a NSFW marked channel?');
  154.                 }
  155.                 const res = await snekfetch.get('https://nekos.life/api/lewd/neko');
  156.                 msg.channel.send({ embed: {
  157.                     image: { url: res.body.neko },
  158.                     footer: { text: `Requested by ${msg.author.tag}` }
  159.                 } })
  160.             } else {
  161.                 const res = await snekfetch.get('https://nekos.life/api/neko')
  162.                 msg.channel.send({ embed: {
  163.                     image: { url: res.body.neko },
  164.                     footer: { text: `Requested by ${msg.author.tag}` }
  165.                 } })
  166.             }
  167.         }
  168.  
  169.         if (command === 'quote') {
  170.             msg.channel.send(commandConfigs.quotes[Math.floor(Math.random() * commandConfigs.quotes.length)]);
  171.         }
  172.  
  173.         if (command === 'ping') {
  174.             msg.channel.send(`:ping_pong: Pong! ${client.pings[0]}ms`);
  175.         }
  176.  
  177.         if (command === 'stats') {
  178.             const embed = new RichEmbed()
  179.                 .setTitle(`Yuno ${settings.version}`)
  180.                 .addField('Uptime', moment.duration(process.uptime(), 'seconds').format('dd:hh:mm:ss'), true)
  181.                 .addField('Ping', `${client.ping.toFixed(0)} ms`, true)
  182.                 .addField('RAM Usage', `${(process.memoryUsage().rss / 1048576).toFixed()}MB/${(os.totalmem() > 1073741824 ? `${(os.totalmem() / 1073741824).toFixed(1)} GB` : `${(os.totalmem() / 1048576).toFixed()} MB`)}\n(${(process.memoryUsage().rss / os.totalmem() * 100).toFixed(2)}%)`, true)
  183.                 .addField('System Info', `${process.platform} (${process.arch})\n${(os.totalmem() > 1073741824 ? `${(os.totalmem() / 1073741824).toFixed(1)} GB` : `${(os.totalmem() / 1048576).toFixed(2)} MB`)}`, true)
  184.                 .addField('Libraries', `[Discord.js](https://discord.js.org) v${version}\n[Node.js](https://nodejs.org) ${process.version}`, true)
  185.                 .addField('\u200b', '\u200b', true)
  186.                 .setFooter('Created by Aetheryx#2222 ');
  187.  
  188.             msg.channel.send({ embed });
  189.         }
  190.  
  191.         if (command === 'ban') {
  192.             if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
  193.                 return;
  194.             }
  195.             let userMentions = msg.mentions.users
  196.             if (userMentions.size === 0) {
  197.                 return msg.channel.send('No users mentioned.')
  198.             }
  199.             let bannableusers = userMentions.filter(d => msg.guild.member(d).bannable)
  200.             bannableusers.forEach(x => {
  201.                 msg.guild.ban(x).then(() => {
  202.                     msg.channel.send({ embed: {
  203.                         description: `User ${x.username} successfully banned.`
  204.                     }})
  205.                 })
  206.             })
  207.         }
  208.  
  209.         if (command === 'kick') {
  210.             if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
  211.                 return;
  212.             }
  213.             let userMentions = msg.mentions.users
  214.             if (userMentions.size === 0) {
  215.                 return msg.channel.send('No users mentioned.')
  216.             }
  217.             let kickableusers = userMentions.filter(d => msg.guild.member(d).kickable)
  218.             kickableusers.forEach(x => {
  219.                 msg.guild.member(x).kick().then(() => {
  220.                     msg.channel.send({ embed: {
  221.                         description: `User ${x.username} successfully kicked.`
  222.                     }})
  223.                 })
  224.             })
  225.         }
  226.  
  227.         if (command === 'scold') {
  228.             if (!msg.mentions.users.size) {
  229.                 return msg.channel.send('Who do you want me to scold?');
  230.             }
  231.  
  232.             msg.channel.send(msg.mentions.users.first().toString(), { file: commandConfigs.scoldImages[Math.floor(Math.random() * commandConfigs.scoldImages.length)] });
  233.         }
  234.  
  235.         if (command === 'praise') {
  236.             if (!msg.mentions.users.size) {
  237.                 return msg.channel.send('Who do you want me to praise?');
  238.             }
  239.  
  240.             msg.channel.send(msg.mentions.users.first().toString(), { file: commandConfigs.praiseImages[Math.floor(Math.random() * commandConfigs.praiseImages.length)] });
  241.         }
  242.  
  243.         if (command === '8ball') {
  244.             if (!args[0]) {
  245.                 return msg.channel.send('What do you want to ask the Magic 8 ball?')
  246.             }
  247.             const randomized = Math.floor(Math.random() * Object.keys(commandConfigs.eightball).length);
  248.             msg.channel.send({ embed: {
  249.                 description: Object.keys(commandConfigs.eightball)[randomized],
  250.                 color: parseInt(commandConfigs.eightball[Object.keys(commandConfigs.eightball)[randomized]], '16')
  251.             }});
  252.         }
  253.  
  254.         if (command === 'time') {
  255.             msg.channel.send(`${moment.duration(timeRemaining, 'milliseconds').format('dd:hh:mm:ss')} left before clean.`);
  256.         }
  257.  
  258.         if (command === 'delay') {
  259.             if (!args[0] || !parseInt(args[0]) || parseInt(args[0]) < 1 || parseInt(args[0]) > 10) {
  260.                 return msg.channel.send('You need to tell me how much you want to delay, and it needs to be in between 1 and 10.');
  261.             }
  262.             if (timeRemaining > settings.timeBeforeWarning) {
  263.                 return msg.channel.send(`You can only delay the clean after a warning has been posted. The next warning is in ${moment.duration(timeRemaining - settings.timeBeforeWarning).format('dd:hh:mm:ss')}.`);
  264.             }
  265.             timeRemaining += parseInt(args[0]) * 60 * 1000;
  266.             msg.channel.send(`Cleaning delayed by ${args[0]} minutes.`);
  267.         }
  268.     }
  269. });
  270.  
  271. client.on('guildMemberRemove', member => {
  272.     if (member.guild.id === '310020264475885570') {
  273.         member.guild.defaultChannel.send(`${member.user.username}, you were unworthy of the Hentai Enthusiasts`, { file: 'https://68.media.tumblr.com/tumblr_lh3xpn7ZZJ1qf4vs7o1_500.png' })
  274.     }
  275. })
  276.  
  277. client.once('ready', () => {
  278.     setInterval(() => {
  279.         if (!client.channels.get(settings.channelID)) {
  280.             return
  281.             return log('Channel not found; returning... :(');
  282.         }
  283.         const channel = client.channels.get(settings.channelID);
  284.         if (timeRemaining === settings.timeBeforeWarning + tick) {
  285.             channel.send({ embed: {
  286.                 author: { name: `Yuno is going to clean in ${settings.timeBeforeWarning / 1000 / 60} minutes. Speak now or forever hold your peace.`,
  287.                           icon_url: client.user.avatarURL } // eslint-disable-line indent
  288.             } });
  289.         }
  290.         if (timeRemaining > 0) {
  291.             timeRemaining -= tick;
  292.             updateTime(timeRemaining);
  293.         } else {
  294.             timeRemaining = settings.timeBetweenClean;
  295.             updateTime(timeRemaining);
  296.             channel.delete();
  297.             channel.clone(channel.name, true, true).then(newChannel => {
  298.                 settings.channelID = newChannel.id;
  299.                 updateSettings(settings);
  300.                 newChannel.setPosition(channel.position);
  301.                 newChannel.send('@everyone', { embed: {
  302.                     description: 'Yuno is done cleaning.',
  303.                     image: { url: 'https://vignette3.wikia.nocookie.net/futurediary/images/9/94/Mirai_Nikki_-_06_-_Large_05.jpg' }
  304.                 } });
  305.             });
  306.         }
  307.     }, tick);
  308. });
  309.  
  310. function updateTime (timeRemaining) {
  311.     fs.writeFileSync('./time.json', timeRemaining);
  312. }
  313.  
  314. function updateSettings (settings) {
  315.     fs.writeFileSync('./settings.json', JSON.stringify(settings, '', '\t'));
  316. }
  317.  
  318. function log (str) {
  319.     console.log(`[${Date().toString().split(' ').slice(1, 5).join(' ')}] ${str}`); // eslint-disable-line no-console
  320. }
  321.  
  322. function randomsFromArr (sourceArray, neededElements) {
  323.     var result = [];
  324.     for (let i = 0; i < neededElements; i++) {
  325.         result.push(sourceArray[Math.floor(Math.random()*sourceArray.length)]);
  326.     }
  327.     return result;
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement