mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix tweet
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB |
@@ -1,56 +0,0 @@
|
|||||||
const Command = require('../../framework/Command');
|
|
||||||
const request = require('node-superfetch');
|
|
||||||
const { Agent } = require('https');
|
|
||||||
const { list } = require('../../util/Util');
|
|
||||||
const fonts = require('../../assets/json/cool-text');
|
|
||||||
const noRejectAgent = new Agent({ rejectUnauthorized: false });
|
|
||||||
|
|
||||||
module.exports = class CoolTextCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'cool-text',
|
|
||||||
group: 'edit-image-text',
|
|
||||||
memberName: 'cool-text',
|
|
||||||
description: 'Writes text in some cool fonts.',
|
|
||||||
details: `**Fonts:** ${Object.keys(fonts).join(', ')}`,
|
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'Cool Text Graphics Generator',
|
|
||||||
url: 'https://cooltext.com/',
|
|
||||||
reason: 'API'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'font',
|
|
||||||
prompt: `What font do you want to use? Either ${list(Object.keys(fonts), 'or')}.`,
|
|
||||||
type: 'string',
|
|
||||||
oneOf: Object.keys(fonts),
|
|
||||||
parse: font => font.toLowerCase()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'text',
|
|
||||||
prompt: 'What text do you want to write?',
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { font, text }) {
|
|
||||||
try {
|
|
||||||
const { body, text: content } = await request
|
|
||||||
.post('https://cooltext.com/PostChange')
|
|
||||||
.attach({
|
|
||||||
...fonts[font],
|
|
||||||
Text: text
|
|
||||||
});
|
|
||||||
if (!content) return msg.say('Failed to create an image with this text.');
|
|
||||||
const { body: imageBody } = await request.get(body.renderLocation, { agent: noRejectAgent });
|
|
||||||
const format = body.isAnimated ? 'gif' : 'png';
|
|
||||||
return msg.say({ files: [{ attachment: imageBody, name: `${font}.${format}` }] });
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
const Command = require('../../framework/Command');
|
|
||||||
const request = require('node-superfetch');
|
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
module.exports = class NewspaperCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'newspaper',
|
|
||||||
group: 'edit-image-text',
|
|
||||||
memberName: 'newspaper',
|
|
||||||
description: 'Creates a fake newspaper with the headline and body of your choice.',
|
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'The Newspaper Clipping Generator',
|
|
||||||
url: 'https://www.fodey.com/generators/newspaper/snippet.asp',
|
|
||||||
reason: 'API'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'headline',
|
|
||||||
prompt: 'What do you want the headline to be?',
|
|
||||||
type: 'string',
|
|
||||||
max: 20
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'body',
|
|
||||||
prompt: 'What should the body of the article be?',
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { headline, body }) {
|
|
||||||
try {
|
|
||||||
const { text } = await request
|
|
||||||
.post('https://www.fodey.com/generators/newspaper/snippet.asp')
|
|
||||||
.attach('name', 'The Daily Whatever')
|
|
||||||
.attach('date', moment().format('dddd, MMMM D, YYYY'))
|
|
||||||
.attach('headline', headline)
|
|
||||||
.attach('text', body);
|
|
||||||
const newspaperURL = text.match(/<img src="(https:\/\/r[0-9]+\.fodey\.com\/[0-9]+\/.+\.jpg)"/i)[1];
|
|
||||||
return msg.say({ files: [newspaperURL] });
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
const Command = require('../../framework/Command');
|
|
||||||
const request = require('node-superfetch');
|
|
||||||
|
|
||||||
module.exports = class ShieldsIoBadgeCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'shields-io-badge',
|
|
||||||
aliases: ['shields-io'],
|
|
||||||
group: 'edit-image-text',
|
|
||||||
memberName: 'shields-io-badge',
|
|
||||||
description: 'Creates a badge from shields.io.',
|
|
||||||
clientPermissions: ['ATTACH_FILES'],
|
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'Shields.io',
|
|
||||||
url: 'https://shields.io/',
|
|
||||||
reason: 'API'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'subject',
|
|
||||||
prompt: 'What is the subject of the badge?',
|
|
||||||
type: 'string',
|
|
||||||
parse: subject => encodeURIComponent(subject.replaceAll('-', '--').replaceAll('_', '__'))
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'status',
|
|
||||||
prompt: 'What is the status of the badge?',
|
|
||||||
type: 'string',
|
|
||||||
parse: status => encodeURIComponent(status.replaceAll('-', '--').replaceAll('_', '__'))
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'color',
|
|
||||||
prompt: 'What is the color of the badge?',
|
|
||||||
type: 'string',
|
|
||||||
default: 'brightgreen'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { subject, status, color }) {
|
|
||||||
try {
|
|
||||||
const { body } = await request.get(`https://img.shields.io/badge/${subject}-${status}-${color}.png`);
|
|
||||||
return msg.say({ files: [{ attachment: body, name: 'badge.png' }] });
|
|
||||||
} catch (err) {
|
|
||||||
if (err.status === 404) return msg.reply('Could not create the badge...');
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
const { createCanvas, loadImage } = require('canvas');
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
|
const { TwitterOpenApi } = require('twitter-openapi-typescript');
|
||||||
|
const api = new TwitterOpenApi();
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { base64, formatNumberK, randomRange } = require('../../util/Util');
|
const { formatNumberK, randomRange } = require('../../util/Util');
|
||||||
const { wrapText } = require('../../util/Canvas');
|
const { wrapText } = require('../../util/Canvas');
|
||||||
const { TWITTER_KEY, TWITTER_SECRET } = process.env;
|
|
||||||
|
|
||||||
module.exports = class TweetCommand extends Command {
|
module.exports = class TweetCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -50,12 +51,12 @@ module.exports = class TweetCommand extends Command {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
this.token = null;
|
this.guestClient = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { user, text }) {
|
async run(msg, { user, text }) {
|
||||||
try {
|
try {
|
||||||
if (!this.token) await this.fetchToken();
|
if (!this.guestClient) this.guestClient = await api.getGuestClient();
|
||||||
const userData = await this.fetchUser(msg, user);
|
const userData = await this.fetchUser(msg, user);
|
||||||
const avatar = await loadImage(userData.avatar);
|
const avatar = await loadImage(userData.avatar);
|
||||||
const base1 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-1.png'));
|
const base1 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-1.png'));
|
||||||
@@ -148,40 +149,17 @@ module.exports = class TweetCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchToken() {
|
|
||||||
const { body } = await request
|
|
||||||
.post('https://api.twitter.com/oauth2/token')
|
|
||||||
.set({
|
|
||||||
Authorization: `Basic ${base64(`${TWITTER_KEY}:${TWITTER_SECRET}`)}`,
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
||||||
})
|
|
||||||
.send('grant_type=client_credentials');
|
|
||||||
this.token = body.access_token;
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchUser(msg, user) {
|
async fetchUser(msg, user) {
|
||||||
if (user.toLowerCase() === 'realdonaldtrump') {
|
|
||||||
return {
|
|
||||||
screenName: 'realDonaldTrump',
|
|
||||||
name: 'Donald J. Trump',
|
|
||||||
avatar: path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'realdonaldtrump.jpg'),
|
|
||||||
verified: true,
|
|
||||||
followers: 88776124
|
|
||||||
};
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const { body } = await request
|
const { data } = await this.guestClient.getUserApi().getUserByScreenName({ screenName: user });
|
||||||
.get('https://api.twitter.com/1.1/users/show.json')
|
const body = data.user.legacy;
|
||||||
.set({ Authorization: `Bearer ${this.token}` })
|
const avatarRes = await request.get(body.profileImageUrlHttps);
|
||||||
.query({ screen_name: user });
|
|
||||||
const avatarRes = await request.get(body.profile_image_url_https.replace('_normal', '_bigger'));
|
|
||||||
return {
|
return {
|
||||||
screenName: body.screen_name,
|
screenName: body.screenName,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
avatar: avatarRes.body,
|
avatar: avatarRes.body,
|
||||||
verified: body.verified,
|
verified: data.user.isBlueVerified,
|
||||||
followers: body.followers_count
|
followers: body.followersCount
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
const avatarRes = await request.get(msg.author.displayAvatarURL({ format: 'png', size: 64 }));
|
const avatarRes = await request.get(msg.author.displayAvatarURL({ format: 'png', size: 64 }));
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
const Command = require('../../framework/Command');
|
|
||||||
const request = require('node-superfetch');
|
|
||||||
|
|
||||||
module.exports = class SnapcodeCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'snapcode',
|
|
||||||
group: 'edit-image',
|
|
||||||
memberName: 'snapcode',
|
|
||||||
description: 'Responds with the Snapcode of a Snapchat user.',
|
|
||||||
clientPermissions: ['ATTACH_FILES'],
|
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'Snapchat',
|
|
||||||
url: 'https://www.snapchat.com/',
|
|
||||||
reason: 'API'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'username',
|
|
||||||
prompt: 'What user do you want to get the Snapcode for?',
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { username }) {
|
|
||||||
try {
|
|
||||||
const { body } = await request
|
|
||||||
.get('https://feelinsonice.appspot.com/web/deeplink/snapcode')
|
|
||||||
.query({
|
|
||||||
username,
|
|
||||||
type: 'PNG',
|
|
||||||
size: 320
|
|
||||||
});
|
|
||||||
return msg.say({ files: [{ attachment: body, name: 'snapcode.png' }] });
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
const Command = require('../../framework/Command');
|
|
||||||
const request = require('node-superfetch');
|
|
||||||
const { stripIndents } = require('common-tags');
|
|
||||||
const { list } = require('../../util/Util');
|
|
||||||
const { styles, characters, badges } = require('../../assets/json/trainer-card');
|
|
||||||
|
|
||||||
module.exports = class TrainerCardCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'trainer-card',
|
|
||||||
aliases: [
|
|
||||||
'pkmn-trainer',
|
|
||||||
'pokemon-trainer',
|
|
||||||
'pokémon-trainer',
|
|
||||||
'pkmn-trainer-card',
|
|
||||||
'pokemon-trainer-card',
|
|
||||||
'pokémon-trainer-card',
|
|
||||||
'pkmn-tc',
|
|
||||||
'pokemon-tc',
|
|
||||||
'pokémon-tc',
|
|
||||||
'ptc'
|
|
||||||
],
|
|
||||||
group: 'edit-image',
|
|
||||||
memberName: 'trainer-card',
|
|
||||||
description: 'Creates a trainer card for a Pokémon trainer.',
|
|
||||||
details: stripIndents`
|
|
||||||
**Styles:** ${Object.keys(styles).join(', ')}
|
|
||||||
**Characters:** ${Object.keys(characters).join(', ')}
|
|
||||||
**Badges:** ${Object.keys(badges).join(', ')}
|
|
||||||
`,
|
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'Pokémon',
|
|
||||||
url: 'https://www.pokemon.com/us/',
|
|
||||||
reason: 'Images, Original Game'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'PokéAPI',
|
|
||||||
url: 'https://pokeapi.co/',
|
|
||||||
reason: 'API'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Pokécharms',
|
|
||||||
url: 'https://pokecharms.com/',
|
|
||||||
reason: 'Trainer Card API',
|
|
||||||
reasonURL: 'https://pokecharms.com/trainer-card-maker/'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'style',
|
|
||||||
prompt: `What style do you want to use? Either ${list(Object.keys(styles), 'or')}.`,
|
|
||||||
type: 'string',
|
|
||||||
oneOf: Object.keys(styles),
|
|
||||||
parse: style => styles[style.toLowerCase()]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'name',
|
|
||||||
prompt: 'What name do you want to use?',
|
|
||||||
type: 'string',
|
|
||||||
max: 12
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'character',
|
|
||||||
prompt: `What character do you want to use? Either ${list(Object.keys(characters), 'or')}.`,
|
|
||||||
type: 'string',
|
|
||||||
oneOf: Object.keys(characters),
|
|
||||||
parse: character => characters[character.toLowerCase()]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'badgeChoice',
|
|
||||||
label: 'badges',
|
|
||||||
prompt: `What badges do you want to use? Either ${list(Object.keys(badges), 'or')}.`,
|
|
||||||
type: 'string',
|
|
||||||
oneOf: Object.keys(badges),
|
|
||||||
parse: choice => badges[choice.toLowerCase()]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'pokemon',
|
|
||||||
label: 'Pokémon',
|
|
||||||
prompt: 'What Pokémon do you want to use? Please enter up to 6 (in seperate messages).',
|
|
||||||
type: 'pokemon',
|
|
||||||
infinite: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { style, name, character, badgeChoice, pokemon }) {
|
|
||||||
try {
|
|
||||||
const pokemonUsed = [];
|
|
||||||
for (const pkmn of pokemon) {
|
|
||||||
const id = await pkmn.fetchCardID();
|
|
||||||
pokemonUsed.push(id);
|
|
||||||
}
|
|
||||||
const card = await this.createCard(style, name, character, badgeChoice, pokemonUsed);
|
|
||||||
return msg.say({ files: [{ attachment: card, name: 'trainer-card.png' }] });
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createCard(style, name, character, badgeChoice, pokemon) {
|
|
||||||
const { body } = await request
|
|
||||||
.post('https://pokecharms.com/index.php?trainer-card-maker/render')
|
|
||||||
.attach('trainername', name)
|
|
||||||
.attach('background', style)
|
|
||||||
.attach('character', character)
|
|
||||||
.attach('badges', 8)
|
|
||||||
.attach('badgesUsed', badgeChoice.join(','))
|
|
||||||
.attach('pokemon', pokemon.length)
|
|
||||||
.attach('pokemonUsed', pokemon.join(','))
|
|
||||||
.attach('_xfResponseType', 'json');
|
|
||||||
return Buffer.from(body.trainerCard, 'base64');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -84,6 +84,7 @@
|
|||||||
"text-diff": "^1.0.1",
|
"text-diff": "^1.0.1",
|
||||||
"tictactoe-minimax-ai": "github:marianoheller/tic-tac-toe-minimax",
|
"tictactoe-minimax-ai": "github:marianoheller/tic-tac-toe-minimax",
|
||||||
"twemoji-parser": "^14.0.0",
|
"twemoji-parser": "^14.0.0",
|
||||||
|
"twitter-openapi-typescript": "^0.0.31",
|
||||||
"user-agents": "^1.1.148",
|
"user-agents": "^1.1.148",
|
||||||
"valid-url": "^1.0.9",
|
"valid-url": "^1.0.9",
|
||||||
"wavefile": "^11.0.0",
|
"wavefile": "^11.0.0",
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ module.exports = class Pokemon {
|
|||||||
this.weight = data.missingno ? data.weight : null;
|
this.weight = data.missingno ? data.weight : null;
|
||||||
this.moveSet = data.missingno ? data.moveSet : [];
|
this.moveSet = data.missingno ? data.moveSet : [];
|
||||||
this.moveSetVersion = data.missingno ? data.moveSetVersion : null;
|
this.moveSetVersion = data.missingno ? data.moveSetVersion : null;
|
||||||
this.trainerCardID = null;
|
|
||||||
this.gameDataCached = data.missingno || false;
|
this.gameDataCached = data.missingno || false;
|
||||||
this.gameDataFetching = data.missingno || false;
|
this.gameDataFetching = data.missingno || false;
|
||||||
this.missingno = data.missingno || false;
|
this.missingno = data.missingno || false;
|
||||||
@@ -168,18 +167,6 @@ module.exports = class Pokemon {
|
|||||||
return this.smogonTiers;
|
return this.smogonTiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchCardID() {
|
|
||||||
if (this.trainerCardID) return this.trainerCardID;
|
|
||||||
const { body } = await request
|
|
||||||
.post('https://pokecharms.com/trainer-card-maker/pokemon-panels')
|
|
||||||
.attach('number', this.id)
|
|
||||||
.attach('_xfResponseType', 'json');
|
|
||||||
const $ = cheerio.load(body.templateHtml);
|
|
||||||
const id = $('li[class="Panel"]').first().attr('data-id');
|
|
||||||
this.trainerCardID = id;
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchGameData() {
|
async fetchGameData() {
|
||||||
if (this.gameDataCached) return this;
|
if (this.gameDataCached) return this;
|
||||||
if (this.gameDataFetching) {
|
if (this.gameDataFetching) {
|
||||||
|
|||||||
Reference in New Issue
Block a user