diff --git a/assets/images/tweet/realdonaldtrump.jpg b/assets/images/tweet/realdonaldtrump.jpg deleted file mode 100644 index 7cdbcb54..00000000 Binary files a/assets/images/tweet/realdonaldtrump.jpg and /dev/null differ diff --git a/commands/edit-image-text/cool-text.js b/commands/edit-image-text/cool-text.js deleted file mode 100644 index 5fe21ed6..00000000 --- a/commands/edit-image-text/cool-text.js +++ /dev/null @@ -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!`); - } - } -}; diff --git a/commands/edit-image-text/newspaper.js b/commands/edit-image-text/newspaper.js deleted file mode 100644 index 109eeefa..00000000 --- a/commands/edit-image-text/newspaper.js +++ /dev/null @@ -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(/ 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!`); - } - } -}; diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js index a6d36dbc..98f6b073 100644 --- a/commands/edit-image-text/tweet.js +++ b/commands/edit-image-text/tweet.js @@ -1,11 +1,12 @@ const Command = require('../../framework/Command'); const { createCanvas, loadImage } = require('canvas'); +const { TwitterOpenApi } = require('twitter-openapi-typescript'); +const api = new TwitterOpenApi(); const moment = require('moment'); const request = require('node-superfetch'); const path = require('path'); -const { base64, formatNumberK, randomRange } = require('../../util/Util'); +const { formatNumberK, randomRange } = require('../../util/Util'); const { wrapText } = require('../../util/Canvas'); -const { TWITTER_KEY, TWITTER_SECRET } = process.env; module.exports = class TweetCommand extends Command { constructor(client) { @@ -50,12 +51,12 @@ module.exports = class TweetCommand extends Command { ] }); - this.token = null; + this.guestClient = null; } async run(msg, { user, text }) { try { - if (!this.token) await this.fetchToken(); + if (!this.guestClient) this.guestClient = await api.getGuestClient(); const userData = await this.fetchUser(msg, user); const avatar = await loadImage(userData.avatar); 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) { - 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 { - const { body } = await request - .get('https://api.twitter.com/1.1/users/show.json') - .set({ Authorization: `Bearer ${this.token}` }) - .query({ screen_name: user }); - const avatarRes = await request.get(body.profile_image_url_https.replace('_normal', '_bigger')); + const { data } = await this.guestClient.getUserApi().getUserByScreenName({ screenName: user }); + const body = data.user.legacy; + const avatarRes = await request.get(body.profileImageUrlHttps); return { - screenName: body.screen_name, + screenName: body.screenName, name: body.name, avatar: avatarRes.body, - verified: body.verified, - followers: body.followers_count + verified: data.user.isBlueVerified, + followers: body.followersCount }; } catch { const avatarRes = await request.get(msg.author.displayAvatarURL({ format: 'png', size: 64 })); diff --git a/commands/edit-image/snapcode.js b/commands/edit-image/snapcode.js deleted file mode 100644 index e7e11fda..00000000 --- a/commands/edit-image/snapcode.js +++ /dev/null @@ -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!`); - } - } -}; diff --git a/commands/edit-image/trainer-card.js b/commands/edit-image/trainer-card.js deleted file mode 100644 index 25f84fb2..00000000 --- a/commands/edit-image/trainer-card.js +++ /dev/null @@ -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'); - } -}; diff --git a/package.json b/package.json index 72b362b1..efd9293b 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "text-diff": "^1.0.1", "tictactoe-minimax-ai": "github:marianoheller/tic-tac-toe-minimax", "twemoji-parser": "^14.0.0", + "twitter-openapi-typescript": "^0.0.31", "user-agents": "^1.1.148", "valid-url": "^1.0.9", "wavefile": "^11.0.0", diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 6f9226da..4a66cb81 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -57,7 +57,6 @@ module.exports = class Pokemon { this.weight = data.missingno ? data.weight : null; this.moveSet = data.missingno ? data.moveSet : []; this.moveSetVersion = data.missingno ? data.moveSetVersion : null; - this.trainerCardID = null; this.gameDataCached = data.missingno || false; this.gameDataFetching = data.missingno || false; this.missingno = data.missingno || false; @@ -168,18 +167,6 @@ module.exports = class Pokemon { 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() { if (this.gameDataCached) return this; if (this.gameDataFetching) {