mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
I use base64 a lot
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../util/Util');
|
||||
const { shorten, base64 } = require('../../util/Util');
|
||||
const { GITHUB_USERNAME, GITHUB_PASSWORD } = process.env;
|
||||
|
||||
module.exports = class GitHubCommand extends Command {
|
||||
@@ -34,7 +34,7 @@ module.exports = class GitHubCommand extends Command {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get(`https://api.github.com/repos/${author}/${repository}`)
|
||||
.set({ Authorization: `Basic ${Buffer.from(`${GITHUB_USERNAME}:${GITHUB_PASSWORD}`).toString('base64')}` });
|
||||
.set({ Authorization: `Basic ${base64(`${GITHUB_USERNAME}:${GITHUB_PASSWORD}`)}` });
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xFFFFFF)
|
||||
.setAuthor('GitHub', 'https://i.imgur.com/e4HunUm.png', 'https://github.com/')
|
||||
|
||||
@@ -4,7 +4,7 @@ const snekfetch = require('snekfetch');
|
||||
const { parseString } = require('xml2js');
|
||||
const { promisify } = require('util');
|
||||
const xml = promisify(parseString);
|
||||
const { shorten, cleanXML } = require('../../util/Util');
|
||||
const { shorten, base64, cleanXML } = require('../../util/Util');
|
||||
const { MAL_USERNAME, MAL_PASSWORD } = process.env;
|
||||
|
||||
module.exports = class MyAnimeListAnimeCommand extends Command {
|
||||
@@ -31,7 +31,7 @@ module.exports = class MyAnimeListAnimeCommand extends Command {
|
||||
const { text } = await snekfetch
|
||||
.get('https://myanimelist.net/api/anime/search.xml')
|
||||
.query({ q: query })
|
||||
.set({ Authorization: `Basic ${Buffer.from(`${MAL_USERNAME}:${MAL_PASSWORD}`).toString('base64')}` });
|
||||
.set({ Authorization: `Basic ${base64(`${MAL_USERNAME}:${MAL_PASSWORD}`)}` });
|
||||
const body = await xml(text);
|
||||
const data = body.anime.entry[0];
|
||||
const embed = new MessageEmbed()
|
||||
|
||||
@@ -4,7 +4,7 @@ const snekfetch = require('snekfetch');
|
||||
const { parseString } = require('xml2js');
|
||||
const { promisify } = require('util');
|
||||
const xml = promisify(parseString);
|
||||
const { shorten, cleanXML } = require('../../util/Util');
|
||||
const { shorten, base64, cleanXML } = require('../../util/Util');
|
||||
const { MAL_USERNAME, MAL_PASSWORD } = process.env;
|
||||
|
||||
module.exports = class MyAnimeListMangaCommand extends Command {
|
||||
@@ -31,7 +31,7 @@ module.exports = class MyAnimeListMangaCommand extends Command {
|
||||
const { text } = await snekfetch
|
||||
.get('https://myanimelist.net/api/manga/search.xml')
|
||||
.query({ q: query })
|
||||
.set({ Authorization: `Basic ${Buffer.from(`${MAL_USERNAME}:${MAL_PASSWORD}`).toString('base64')}` });
|
||||
.set({ Authorization: `Basic ${base64(`${MAL_USERNAME}:${MAL_PASSWORD}`)}` });
|
||||
const body = await xml(text);
|
||||
const data = body.manga.entry[0];
|
||||
const embed = new MessageEmbed()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { base64 } = require('../../util/Util');
|
||||
const { TWITTER_KEY, TWITTER_SECRET } = process.env;
|
||||
|
||||
module.exports = class TwitterCommand extends Command {
|
||||
@@ -64,7 +65,7 @@ module.exports = class TwitterCommand extends Command {
|
||||
const { body } = await snekfetch
|
||||
.post('https://api.twitter.com/oauth2/token')
|
||||
.set({
|
||||
Authorization: `Basic ${Buffer.from(`${TWITTER_KEY}:${TWITTER_SECRET}`).toString('base64')}`,
|
||||
Authorization: `Basic ${base64(`${TWITTER_KEY}:${TWITTER_SECRET}`)}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
||||
})
|
||||
.send('grant_type=client_credentials');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { base64 } = require('../../util/Util');
|
||||
|
||||
module.exports = class Base64Command extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,7 +15,7 @@ module.exports = class Base64Command extends Command {
|
||||
prompt: 'What text would you like to convert to Base64?',
|
||||
type: 'string',
|
||||
validate: text => {
|
||||
if (Buffer.from(text).toString('base64').length < 2000) return true;
|
||||
if (base64(text).length < 2000) return true;
|
||||
return 'Invalid text, your text is too long.';
|
||||
}
|
||||
}
|
||||
@@ -23,6 +24,6 @@ module.exports = class Base64Command extends Command {
|
||||
}
|
||||
|
||||
run(msg, { text }) {
|
||||
return msg.say(Buffer.from(text).toString('base64'));
|
||||
return msg.say(base64(text));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,6 +51,10 @@ class Util {
|
||||
return arr;
|
||||
}
|
||||
|
||||
static base64(text) {
|
||||
return Buffer.from(text).toString('base64');
|
||||
}
|
||||
|
||||
static cleanXML(text) {
|
||||
return text
|
||||
.replace(/<br \/>/g, '')
|
||||
|
||||
Reference in New Issue
Block a user