Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, version, RichEmbed } = require('discord.js');
- const fs = require('fs');
- let timeRemaining = require('./time.json');
- const settings = require('./settings.json');
- const moment = require('moment');
- require('moment-duration-format');
- const client = new Client();
- const tick = 1000;
- const popura = require('popura');
- const animeClient = popura(settings.mal.username, settings.mal.password);
- const he = require('he');
- const commandConfigs = require('./commandconfigs.json');
- const prefix = '-';
- const os = require('os');
- const snekfetch = require('snekfetch');
- const xml = require('util').promisify(require('xml-simple').parse);
- log('Logging in...');
- client.login(settings.token);
- client.on('ready', () => {
- log(`Logged in as ${client.user.tag}.`);
- });
- client.on('message', async (msg) => {
- msg.content = msg.content.replace(client.user.toString(), '').toLowerCase().trim();
- let command = msg.content.split(' ')[0];
- const args = msg.content.split(' ').slice(1);
- if (msg.isMentioned(client.user.id)) {
- if (command === 'clean') {
- if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
- return msg.channel.send('You\'re not authorized to use this command.');
- }
- if (args[0] === '--force') {
- msg.channel.send('This command will clean the channel **immediately, without a warning**. Proceed?\nAnswer with `yes`/`no`.');
- const collector = msg.channel.createMessageCollector(m => msg.author.id === m.author.id, { time: 40000 });
- collector.on('collect', (m) => {
- if (m.content.toLowerCase() === 'yes') {
- msg.channel.send('Force cleaning..');
- timeRemaining = 1000;
- } else {
- msg.channel.send('Force clean canceled.');
- }
- return collector.stop();
- });
- } else {
- timeRemaining = settings.timeBeforeWarning;
- msg.channel.send(`Clean commencing in ${moment.duration(timeRemaining, 'milliseconds').format('hh:mm:ss')}.`);
- }
- }
- Object.keys(commandConfigs.mentionresponses)
- .forEach(reply => {
- if (msg.content.replace(/ /g, '').includes(reply)) {
- let text = commandConfigs.mentionresponses[reply].replyText.replace(/\$author/g, msg.author.toString());
- let image = commandConfigs.mentionresponses[reply].imageURL;
- if (commandConfigs.mentionresponses[reply].customResponses) {
- if (Object.keys(commandConfigs.mentionresponses[reply].customResponses).includes(msg.author.id)) {
- text = commandConfigs.mentionresponses[reply].customResponses[msg.author.id].replyText;
- image = commandConfigs.mentionresponses[reply].customResponses[msg.author.id].imageURL;
- }
- }
- msg.channel.send(text, { file: image });
- }
- });
- } else if (msg.content.startsWith(prefix)) {
- command = command.slice(prefix.length, command.length);
- if (command === 'hentai') {
- let numarg;
- if (!parseInt(args[0])) {
- numarg = 2;
- } else if (parseInt(args[0]) > 25 || parseInt(args[0]) < 1) {
- return msg.channel.send('The amount of images must be between 1 and 25.')
- } else if (parseInt(args[0])) {
- numarg = parseInt(args[0])
- }
- const text = parseInt(args[0]) ? args.slice(1).join(' ') || '' : args.join(' ') || ''
- try {
- console.log(text)
- console.log(numarg)
- let res = await snekfetch.get(`https://gelbooru.com/index.php?page=dapi&s=post&q=index${'&tags=' + text || ''}&json=1`);
- res = randomsFromArr(JSON.parse(res.text), numarg)
- console.log(res)
- res.map(obj => msg.channel.send({ file: `http://${obj.file_url.replace('//', '')}` }))
- } catch (err) {
- return msg.channel.send('No results found. Try a different query or ask for less results.')
- }
- }
- if (command === 'eval') {
- let input = args.join(' ');
- const silent = input.includes('--silent');
- const asynchr = input.includes('--async');
- if (silent || asynchr) {
- input = input.replace(/--silent|--async/g, '');
- }
- let result;
- try {
- result = asynchr ? eval(`(async()=>{return ${input}})();`) : eval(input);
- if (result instanceof Promise && asynchr) {
- result = await result;
- }
- if (typeof result !== 'string') {
- result = util.inspect(result, { depth: 0 });
- }
- const tokenRegex = new RegExp(client.token, 'gi');
- result = result.replace(tokenRegex, '[TOKEN]');
- } catch (err) {
- result = err.message;
- }
- if (!silent) {
- msg.edit(`${input}\n\`\`\`js\n${result}\n\`\`\``);
- } else {
- msg.delete();
- }
- }
- if (command === 'anime') {
- let res = await animeClient.searchAnimes(args.join(' '));
- res = res[0];
- if (!res) {
- return msg.channel.send(`No anime results found for ${args.join(' ')}. Did you perhaps mean to use the \`manga\` command?`);
- }
- 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: {
- title: 'Information',
- url: `https://myanimelist.net/anime/${res.id}`,
- 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}`,
- thumbnail: { url: res.image }
- }, code: true });
- }
- if (command === 'manga') {
- let res = await animeClient.searchMangas(args.join(' '));
- res = res[0];
- if (!res) {
- return msg.channel.send(`No manga results found for ${args.join(' ')}. Did you perhaps mean to use the \`anime\` command?`);
- }
- 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: {
- title: 'Information',
- url: `https://myanimelist.net/manga/${res.id}`,
- 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}`,
- thumbnail: { url: res.image }
- }, code: true });
- }
- if (command === 'neko') {
- if (args[0] === 'lewd') {
- if (!msg.channel.nsfw) {
- return msg.channel.send('I don\'t think I\'m allowed to post those here... Maybe try a NSFW marked channel?');
- }
- const res = await snekfetch.get('https://nekos.life/api/lewd/neko');
- msg.channel.send({ embed: {
- image: { url: res.body.neko },
- footer: { text: `Requested by ${msg.author.tag}` }
- } })
- } else {
- const res = await snekfetch.get('https://nekos.life/api/neko')
- msg.channel.send({ embed: {
- image: { url: res.body.neko },
- footer: { text: `Requested by ${msg.author.tag}` }
- } })
- }
- }
- if (command === 'quote') {
- msg.channel.send(commandConfigs.quotes[Math.floor(Math.random() * commandConfigs.quotes.length)]);
- }
- if (command === 'ping') {
- msg.channel.send(`:ping_pong: Pong! ${client.pings[0]}ms`);
- }
- if (command === 'stats') {
- const embed = new RichEmbed()
- .setTitle(`Yuno ${settings.version}`)
- .addField('Uptime', moment.duration(process.uptime(), 'seconds').format('dd:hh:mm:ss'), true)
- .addField('Ping', `${client.ping.toFixed(0)} ms`, true)
- .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)
- .addField('System Info', `${process.platform} (${process.arch})\n${(os.totalmem() > 1073741824 ? `${(os.totalmem() / 1073741824).toFixed(1)} GB` : `${(os.totalmem() / 1048576).toFixed(2)} MB`)}`, true)
- .addField('Libraries', `[Discord.js](https://discord.js.org) v${version}\n[Node.js](https://nodejs.org) ${process.version}`, true)
- .addField('\u200b', '\u200b', true)
- .setFooter('Created by Aetheryx#2222 ');
- msg.channel.send({ embed });
- }
- if (command === 'ban') {
- if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
- return;
- }
- let userMentions = msg.mentions.users
- if (userMentions.size === 0) {
- return msg.channel.send('No users mentioned.')
- }
- let bannableusers = userMentions.filter(d => msg.guild.member(d).bannable)
- bannableusers.forEach(x => {
- msg.guild.ban(x).then(() => {
- msg.channel.send({ embed: {
- description: `User ${x.username} successfully banned.`
- }})
- })
- })
- }
- if (command === 'kick') {
- if (!['239882051166142465', '281306546858754058'].includes(msg.author.id)) {
- return;
- }
- let userMentions = msg.mentions.users
- if (userMentions.size === 0) {
- return msg.channel.send('No users mentioned.')
- }
- let kickableusers = userMentions.filter(d => msg.guild.member(d).kickable)
- kickableusers.forEach(x => {
- msg.guild.member(x).kick().then(() => {
- msg.channel.send({ embed: {
- description: `User ${x.username} successfully kicked.`
- }})
- })
- })
- }
- if (command === 'scold') {
- if (!msg.mentions.users.size) {
- return msg.channel.send('Who do you want me to scold?');
- }
- msg.channel.send(msg.mentions.users.first().toString(), { file: commandConfigs.scoldImages[Math.floor(Math.random() * commandConfigs.scoldImages.length)] });
- }
- if (command === 'praise') {
- if (!msg.mentions.users.size) {
- return msg.channel.send('Who do you want me to praise?');
- }
- msg.channel.send(msg.mentions.users.first().toString(), { file: commandConfigs.praiseImages[Math.floor(Math.random() * commandConfigs.praiseImages.length)] });
- }
- if (command === '8ball') {
- if (!args[0]) {
- return msg.channel.send('What do you want to ask the Magic 8 ball?')
- }
- const randomized = Math.floor(Math.random() * Object.keys(commandConfigs.eightball).length);
- msg.channel.send({ embed: {
- description: Object.keys(commandConfigs.eightball)[randomized],
- color: parseInt(commandConfigs.eightball[Object.keys(commandConfigs.eightball)[randomized]], '16')
- }});
- }
- if (command === 'time') {
- msg.channel.send(`${moment.duration(timeRemaining, 'milliseconds').format('dd:hh:mm:ss')} left before clean.`);
- }
- if (command === 'delay') {
- if (!args[0] || !parseInt(args[0]) || parseInt(args[0]) < 1 || parseInt(args[0]) > 10) {
- 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.');
- }
- if (timeRemaining > settings.timeBeforeWarning) {
- 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')}.`);
- }
- timeRemaining += parseInt(args[0]) * 60 * 1000;
- msg.channel.send(`Cleaning delayed by ${args[0]} minutes.`);
- }
- }
- });
- client.on('guildMemberRemove', member => {
- if (member.guild.id === '310020264475885570') {
- member.guild.defaultChannel.send(`${member.user.username}, you were unworthy of the Hentai Enthusiasts`, { file: 'https://68.media.tumblr.com/tumblr_lh3xpn7ZZJ1qf4vs7o1_500.png' })
- }
- })
- client.once('ready', () => {
- setInterval(() => {
- if (!client.channels.get(settings.channelID)) {
- return
- return log('Channel not found; returning... :(');
- }
- const channel = client.channels.get(settings.channelID);
- if (timeRemaining === settings.timeBeforeWarning + tick) {
- channel.send({ embed: {
- author: { name: `Yuno is going to clean in ${settings.timeBeforeWarning / 1000 / 60} minutes. Speak now or forever hold your peace.`,
- icon_url: client.user.avatarURL } // eslint-disable-line indent
- } });
- }
- if (timeRemaining > 0) {
- timeRemaining -= tick;
- updateTime(timeRemaining);
- } else {
- timeRemaining = settings.timeBetweenClean;
- updateTime(timeRemaining);
- channel.delete();
- channel.clone(channel.name, true, true).then(newChannel => {
- settings.channelID = newChannel.id;
- updateSettings(settings);
- newChannel.setPosition(channel.position);
- newChannel.send('@everyone', { embed: {
- description: 'Yuno is done cleaning.',
- image: { url: 'https://vignette3.wikia.nocookie.net/futurediary/images/9/94/Mirai_Nikki_-_06_-_Large_05.jpg' }
- } });
- });
- }
- }, tick);
- });
- function updateTime (timeRemaining) {
- fs.writeFileSync('./time.json', timeRemaining);
- }
- function updateSettings (settings) {
- fs.writeFileSync('./settings.json', JSON.stringify(settings, '', '\t'));
- }
- function log (str) {
- console.log(`[${Date().toString().split(' ').slice(1, 5).join(' ')}] ${str}`); // eslint-disable-line no-console
- }
- function randomsFromArr (sourceArray, neededElements) {
- var result = [];
- for (let i = 0; i < neededElements; i++) {
- result.push(sourceArray[Math.floor(Math.random()*sourceArray.length)]);
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement