mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 06:45:31 +02:00
fire, percentage, units
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const snekfetch = require('snekfetch');
|
||||
const path = require('path');
|
||||
const { drawImageWithTint } = require('../../util/Canvas');
|
||||
|
||||
module.exports = class FireCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'fire',
|
||||
aliases: ['flame'],
|
||||
group: 'avatar-edit',
|
||||
memberName: 'fire',
|
||||
description: 'Draws a fiery border over a user\'s avatar.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'user',
|
||||
prompt: 'Which user would you like to edit the avatar of?',
|
||||
type: 'user',
|
||||
default: msg => msg.author
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { user }) {
|
||||
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
|
||||
try {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire.png'));
|
||||
const { body } = await snekfetch.get(avatarURL);
|
||||
const avatar = await loadImage(body);
|
||||
const canvas = createCanvas(avatar.width, avatar.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
drawImageWithTint(ctx, avatar, '#fc671e', 0, 0, avatar.width, avatar.height);
|
||||
ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'fire.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -64,7 +64,7 @@ module.exports = class AkinatorCommand extends Command {
|
||||
|
||||
async createSession(channel) {
|
||||
const { body } = await snekfetch
|
||||
.get('http://api-us1.akinator.com/ws/new_session')
|
||||
.get('http://api-en1.akinator.com/ws/new_session')
|
||||
.query({
|
||||
partner: 1,
|
||||
player: 'xiaobot'
|
||||
@@ -83,7 +83,7 @@ module.exports = class AkinatorCommand extends Command {
|
||||
async progress(channel, answer) {
|
||||
const session = this.sessions.get(channel.id);
|
||||
const { body } = await snekfetch
|
||||
.get('http://api-us1.akinator.com/ws/answer')
|
||||
.get('http://api-en1.akinator.com/ws/answer')
|
||||
.query({
|
||||
session: session.id,
|
||||
signature: session.signature,
|
||||
@@ -104,7 +104,7 @@ module.exports = class AkinatorCommand extends Command {
|
||||
async finish(channel) {
|
||||
const session = this.sessions.get(channel.id);
|
||||
const { body } = await snekfetch
|
||||
.get('http://api-us1.akinator.com/ws/list')
|
||||
.get('http://api-en1.akinator.com/ws/list')
|
||||
.query({
|
||||
session: session.id,
|
||||
signature: session.signature,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
|
||||
module.exports = class PercentageCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'percentage',
|
||||
aliases: ['percent'],
|
||||
group: 'number-edit',
|
||||
memberName: 'percentage',
|
||||
description: 'Determines the percentage one number is of another.',
|
||||
args: [
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How much of the maximum value should be used?',
|
||||
type: 'float'
|
||||
},
|
||||
{
|
||||
key: 'maximum',
|
||||
prompt: 'What is the maximum value of the percentage?',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { amount, maximum }) {
|
||||
const percentage = (amount / maximum) * 100;
|
||||
return msg.say(`${amount} is ${percentage}% of ${maximum}.`);
|
||||
}
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { list } = require('../../util/Util');
|
||||
const units = ['celsius', 'fahrenheit', 'kelvin'];
|
||||
|
||||
module.exports = class TemperatureCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'temperature',
|
||||
aliases: ['temperature-convert', 'convert-temperature', 'temp-convert', 'convert-temp'],
|
||||
group: 'number-edit',
|
||||
memberName: 'temperature',
|
||||
description: `Converts temperatures to/from ${list(units, 'or')}.`,
|
||||
details: `**Units**: ${units.join(', ')}`,
|
||||
args: [
|
||||
{
|
||||
key: 'base',
|
||||
prompt: `What temperature unit do you want to use as the base? Either ${list(units, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: base => {
|
||||
if (units.includes(base.toLowerCase())) return true;
|
||||
return `Invalid base, please enter either ${list(units, 'or')}.`;
|
||||
},
|
||||
parse: base => base.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: `What temperature unit do you want to convert to? Either ${list(units, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: target => {
|
||||
if (units.includes(target.toLowerCase())) return true;
|
||||
return `Invalid target, please enter either ${list(units, 'or')}.`;
|
||||
},
|
||||
parse: target => target.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'What temperature should be converted?',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { base, target, amount }) { // eslint-disable-line consistent-return
|
||||
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
|
||||
if (base === 'celsius') {
|
||||
if (target === 'fahrenheit') return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`);
|
||||
if (target === 'kelvin') return msg.say(`${amount}°C is ${amount + 273.15}°K.`);
|
||||
}
|
||||
if (base === 'fahrenheit') {
|
||||
if (target === 'celsius') return msg.say(`${amount}°F is ${(amount - 32) / 1.8}°C.`);
|
||||
if (target === 'kelvin') return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`);
|
||||
}
|
||||
if (base === 'kelvin') {
|
||||
if (target === 'celsius') return msg.say(`${amount}°K is ${amount - 273.15}°C.`);
|
||||
if (target === 'fahrenheit') return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const math = require('mathjs');
|
||||
|
||||
module.exports = class UnitsCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'units',
|
||||
aliases: ['convert-units', 'unit-converter'],
|
||||
group: 'number-edit',
|
||||
memberName: 'units',
|
||||
description: 'Converts units to/from other units.',
|
||||
args: [
|
||||
{
|
||||
key: 'base',
|
||||
prompt: 'What unit type do you want to convert from?',
|
||||
type: 'string',
|
||||
parse: base => base.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: 'What unit type do you want to convert to?',
|
||||
type: 'string',
|
||||
parse: target => target.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How many units should be converted?',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { base, target, amount }) {
|
||||
try {
|
||||
const value = math.unit(amount, base).to(target).toString();
|
||||
return msg.say(value);
|
||||
} catch (err) {
|
||||
return msg.say('Either an invalid unit type was provided or the unit types do not match.');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user