mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
shorten in Util
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { cleanXML } = require('../../structures/Util');
|
||||
const { cleanXML, shorten } = require('../../structures/Util');
|
||||
const { promisify } = require('util');
|
||||
const xml = promisify(require('xml2js').parseString);
|
||||
const { ANIMELIST_LOGIN } = process.env;
|
||||
@@ -31,14 +31,14 @@ module.exports = class AnimeCommand extends Command {
|
||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`)
|
||||
.query({ q: query });
|
||||
const { anime } = await xml(text);
|
||||
const synopsis = cleanXML(anime.entry[0].synopsis[0].substr(0, 2048));
|
||||
const synopsis = cleanXML(anime.entry[0].synopsis[0]);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
||||
.setURL(`https://myanimelist.net/anime/${anime.entry[0].id[0]}`)
|
||||
.setThumbnail(anime.entry[0].image[0])
|
||||
.setTitle(`${anime.entry[0].title[0]} (English: ${anime.entry[0].english[0] || 'N/A'})`)
|
||||
.setDescription(synopsis)
|
||||
.setDescription(shorten(synopsis))
|
||||
.addField('❯ Type',
|
||||
`${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true)
|
||||
.addField('❯ Episodes',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class BulbapediaCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -40,7 +41,7 @@ module.exports = class BulbapediaCommand extends Command {
|
||||
.setColor(0x3E7614)
|
||||
.setTitle(body.query.pages[0].title)
|
||||
.setAuthor('Bulbapedia', 'https://i.imgur.com/09eYo5T.png')
|
||||
.setDescription(body.query.pages[0].extract.replace(/\n/g, '\n\n').substr(0, 2048));
|
||||
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { cleanXML } = require('../../structures/Util');
|
||||
const { cleanXML, shorten } = require('../../structures/Util');
|
||||
const { promisify } = require('util');
|
||||
const xml = promisify(require('xml2js').parseString);
|
||||
const { ANIMELIST_LOGIN } = process.env;
|
||||
@@ -31,14 +31,14 @@ module.exports = class MangaCommand extends Command {
|
||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`)
|
||||
.query({ q: query });
|
||||
const { manga } = await xml(text);
|
||||
const synopsis = cleanXML(manga.entry[0].synopsis[0].substr(0, 2048));
|
||||
const synopsis = cleanXML(manga.entry[0].synopsis[0]);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
||||
.setURL(`https://myanimelist.net/manga/${manga.entry[0].id[0]}`)
|
||||
.setThumbnail(manga.entry[0].image[0])
|
||||
.setTitle(`${manga.entry[0].title[0]} (English: ${manga.entry[0].english[0] || 'N/A'})`)
|
||||
.setDescription(synopsis)
|
||||
.setDescription(shorten(synopsis))
|
||||
.addField('❯ Type',
|
||||
`${manga.entry[0].type[0]} - ${manga.entry[0].status[0]}`, true)
|
||||
.addField('❯ Volumes / Chapters',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
const { TMDB_KEY } = process.env;
|
||||
|
||||
module.exports = class MovieCommand extends Command {
|
||||
@@ -40,7 +41,7 @@ module.exports = class MovieCommand extends Command {
|
||||
.setTitle(body.title)
|
||||
.setURL(`https://www.themoviedb.org/movie/${body.id}`)
|
||||
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
|
||||
.setDescription(body.overview ? body.overview.substr(0, 2048) : 'No description available.')
|
||||
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
|
||||
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
|
||||
.addField('❯ Runtime',
|
||||
body.runtime ? `${body.runtime} mins.` : 'N/A', true)
|
||||
|
||||
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const moment = require('moment');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class NPMCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -45,7 +46,7 @@ module.exports = class NPMCommand extends Command {
|
||||
.addField('❯ Main File',
|
||||
body.versions[body['dist-tags'].latest].main, true)
|
||||
.addField('❯ Keywords',
|
||||
body.keywords && body.keywords.length ? body.keywords.join(', ').substr(0, 1024) : 'None')
|
||||
body.keywords && body.keywords.length ? shorten(body.keywords.join(', '), 1000) : 'None')
|
||||
.addField('❯ Maintainers',
|
||||
body.maintainers.map(user => user.name).join(', '));
|
||||
return msg.embed(embed);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
const { TMDB_KEY } = process.env;
|
||||
|
||||
module.exports = class TVShowCommand extends Command {
|
||||
@@ -40,7 +41,7 @@ module.exports = class TVShowCommand extends Command {
|
||||
.setTitle(body.name)
|
||||
.setURL(`https://www.themoviedb.org/tv/${body.id}`)
|
||||
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
|
||||
.setDescription(body.overview ? body.overview.substr(0, 2048) : 'No description available.')
|
||||
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
|
||||
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
|
||||
.addField('❯ First Air Date',
|
||||
body.first_air_date || 'N/A', true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class UrbanCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -31,9 +32,9 @@ module.exports = class UrbanCommand extends Command {
|
||||
.setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png')
|
||||
.setURL(body.list[0].permalink)
|
||||
.setTitle(body.list[0].word)
|
||||
.setDescription(body.list[0].definition.substr(0, 2048))
|
||||
.setDescription(shorten(body.list[0].definition))
|
||||
.addField('❯ Example',
|
||||
body.list[0].example.substr(0, 1024) || 'None');
|
||||
shorten(body.list[0].example, 1000) || 'None');
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const moment = require('moment');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class VocaloidCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -40,7 +41,7 @@ module.exports = class VocaloidCommand extends Command {
|
||||
.setAuthor('VocaDB', 'https://i.imgur.com/9Tx9UIc.jpg')
|
||||
.setTitle(body.items[0].name)
|
||||
.setURL(`http://vocadb.net/S/${body.items[0].id}`)
|
||||
.setDescription(body.items[0].lyrics[0] ? body.items[0].lyrics[0].value.substr(0, 2048) : 'No lyrics available.')
|
||||
.setDescription(body.items[0].lyrics.length ? shorten(body.items[0].lyrics[0].value) : 'No lyrics available.')
|
||||
.setThumbnail(body.items[0].thumbUrl)
|
||||
.addField('❯ Artist',
|
||||
body.items[0].artistString)
|
||||
|
||||
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const moment = require('moment');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
const { WATTPAD_KEY } = process.env;
|
||||
|
||||
module.exports = class WattpadCommand extends Command {
|
||||
@@ -37,7 +38,7 @@ module.exports = class WattpadCommand extends Command {
|
||||
.setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png')
|
||||
.setURL(body.stories[0].url)
|
||||
.setTitle(body.stories[0].title)
|
||||
.setDescription(body.stories[0].description.substr(0, 2048))
|
||||
.setDescription(shorten(body.stories[0].description))
|
||||
.setThumbnail(body.stories[0].cover)
|
||||
.addField('❯ Created On',
|
||||
moment(body.stories[0].createDate).format('MMMM Do YYYY'), true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class WikiaCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -44,7 +45,7 @@ module.exports = class WikiaCommand extends Command {
|
||||
.setTitle(body.sections[0].title)
|
||||
.setURL(search.body.items[0].url)
|
||||
.setAuthor('Wikia', 'https://i.imgur.com/WzXWJka.png')
|
||||
.setDescription(body.sections[0].content.map(i => i.text).join('\n\n').substr(0, 2048))
|
||||
.setDescription(shorten(body.sections[0].content.map(section => section.text).join('\n\n')))
|
||||
.setThumbnail(body.sections[0].images.length ? body.sections[0].images[0].src : null);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
|
||||
module.exports = class WikipediaCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -39,7 +40,7 @@ module.exports = class WikipediaCommand extends Command {
|
||||
.setColor(0xE7E7E7)
|
||||
.setTitle(body.query.pages[0].title)
|
||||
.setAuthor('Wikipedia', 'https://i.imgur.com/a4eeEhh.png')
|
||||
.setDescription(body.query.pages[0].extract.replace(/\n/g, '\n\n').substr(0, 2048));
|
||||
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,13 +19,9 @@ module.exports = class UpvoteCommand extends Command {
|
||||
const { body } = await snekfetch
|
||||
.get(`https://discordbots.org/api/bots/${this.client.user.id}/votes`)
|
||||
.set({ Authorization: DBOTSORG_KEY });
|
||||
const haste = await snekfetch
|
||||
.post('https://hastebin.com/documents')
|
||||
.send(body.map(user => `${user.username}#${user.discriminator}`).join('\n'));
|
||||
return msg.say(stripIndents`
|
||||
Upvote Xiao and get rewards while joining ${body.length} others!
|
||||
<https://discordbots.org/bot/${this.client.user.id}>
|
||||
List of Upvoters: <https://hastebin.com/${haste.body.key}>
|
||||
<https://discordbots.org/bot/xiaobot>
|
||||
`);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "31.0.1",
|
||||
"version": "31.0.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -75,6 +75,10 @@ class Util {
|
||||
static list(arr, conj = 'and') {
|
||||
return `${arr.slice(0, -1).join(', ')}${arr.length > 1 ? `${arr.length > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`; // eslint-disable-line max-len
|
||||
}
|
||||
|
||||
static shorten(text, maxLen = 2000) {
|
||||
return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user