mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 14:20:51 +02:00
Character Count, Nike Ad
This commit is contained in:
@@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
The bot is no longer available for invite. You can self-host the bot, or use her
|
||||
on the [home server](https://discord.gg/sbMe32W).
|
||||
|
||||
## Commands (304)
|
||||
## Commands (306)
|
||||
### Utility:
|
||||
|
||||
* **eval:** Executes JavaScript code.
|
||||
@@ -244,6 +244,7 @@ on the [home server](https://discord.gg/sbMe32W).
|
||||
* **illegal:** Makes President Trump make your text illegal.
|
||||
* **invert:** Draws an image or a user's avatar but inverted.
|
||||
* **minecraft-skin:** Sends the Minecraft skin for a user.
|
||||
* **nike-ad:** Sends a "Believe in Something" Nike Ad meme with the text of your choice.
|
||||
* **needs-more-jpeg:** Draws an image or a user's avatar as a low quality JPEG.
|
||||
* **osu-signature:** Creates a card based on an osu! user's stats.
|
||||
* **pixelize:** Draws an image or a user's avatar pixelized.
|
||||
@@ -332,6 +333,7 @@ on the [home server](https://discord.gg/sbMe32W).
|
||||
|
||||
### Number Manipulation:
|
||||
|
||||
* **character-count:** Responds with the character count of text.
|
||||
* **currency:** Converts money from one currency to another.
|
||||
* **final-grade-calculator:** Determines the grade you need to make on your final to get your desired course grade.
|
||||
* **gravity:** Determines weight on another planet.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,71 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage, registerFont } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const path = require('path');
|
||||
const { wrapText, greyscale, drawImageWithTint } = require('../../util/Canvas');
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
|
||||
|
||||
module.exports = class NikeAdCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'nike-ad',
|
||||
aliases: ['believe-in-something', 'believe-in'],
|
||||
group: 'image-edit',
|
||||
memberName: 'nike-ad',
|
||||
description: 'Sends a "Believe in Something" Nike Ad meme with the text of your choice.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'something',
|
||||
prompt: 'What should the something to believe in be?',
|
||||
type: 'string',
|
||||
max: 20,
|
||||
parse: something => something.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'sacrifice',
|
||||
prompt: 'What should believing result in (e.g. sacrificing everything)?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: sacrifice => sacrifice.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'What image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { image, something, sacrifice }) {
|
||||
try {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'nike-ad.png'));
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(data.width, data.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
|
||||
greyscale(ctx, 0, 0, data.width, data.height);
|
||||
ctx.drawImage(base, data.width / 2 - base.width / 2, base.height - data.height);
|
||||
ctx.font = `${Math.round(data.height / 25)}px Noto`;
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
const text = wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width);
|
||||
ctx.fillText(text.join('\n'), data.width / 2, data.height / 2);
|
||||
const attachment = canvas.toBuffer();
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'nike-ad.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class CharacterCountCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'character-count',
|
||||
aliases: ['characters', 'chars', 'length'],
|
||||
group: 'number-edit',
|
||||
memberName: 'character-count',
|
||||
description: 'Responds with the character count of text.',
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text would you like to get the character count of?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { text }) {
|
||||
return msg.reply(text.length);
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "91.0.3",
|
||||
"version": "91.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -95,4 +95,32 @@ module.exports = class CanvasUtil {
|
||||
}
|
||||
return shorten ? `${text}...` : text;
|
||||
}
|
||||
|
||||
static wrapText(ctx, text, maxWidth) {
|
||||
if (ctx.measureText(text).width < maxWidth) return [text];
|
||||
const words = text.split(' ');
|
||||
const lines = [];
|
||||
let line = '';
|
||||
while (words.length > 0) {
|
||||
let split = false;
|
||||
while (ctx.measureText(words[0]).width >= maxWidth) {
|
||||
const temp = words[0];
|
||||
words[0] = temp.slice(0, -1);
|
||||
if (split) {
|
||||
words[1] = `${temp.slice(-1)}${words[1]}`;
|
||||
} else {
|
||||
split = true;
|
||||
words.splice(1, 0, temp.slice(-1));
|
||||
}
|
||||
}
|
||||
if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) {
|
||||
line += `${words.shift()} `;
|
||||
} else {
|
||||
lines.push(line.trim());
|
||||
line = '';
|
||||
}
|
||||
if (words.length === 0) lines.push(line.trim());
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user