Add examples

This commit is contained in:
Dragon Fire
2024-05-16 17:16:00 -04:00
parent 9d00180cb3
commit 986d5d90fb
28 changed files with 138 additions and 32 deletions
+3 -10
View File
@@ -44,24 +44,17 @@ module.exports = class EjectCommand extends Command {
key: 'user',
type: 'user',
default: msg => msg.author
},
{
key: 'imposter',
type: 'boolean',
default: ''
}
]
});
}
async run(msg, { user, imposter }) {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ extension: 'png', size: 128 });
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
if (imposter === '') {
const random = MersenneTwister19937.seed(user.id);
imposter = bool()(random);
}
const random = MersenneTwister19937.seed(user.id);
const imposter = bool()(random);
const text = `${user.username} was${imposter ? ' ' : ' not '}An Imposter.`;
const encoder = new GIFEncoder(320, 180);
const canvas = createCanvas(320, 180);
+1
View File
@@ -75,6 +75,7 @@ module.exports = class HelpCommand extends Command {
cmdHelpText += `**Flags:**\n${flags}\n`;
}
cmdHelpText += `**Format:** ${command.usage()}\n`;
cmdHelpText += `**Example:** ${command.example(msg)}\n`;
if (command.aliases.length) cmdHelpText += `**Aliases:** ${command.aliases.join(', ')}\n`;
cmdHelpText += `**Group:** ${command.group.name}\n`;
return msg.say(cmdHelpText);
+6
View File
@@ -15,6 +15,7 @@ module.exports = class Argument {
this.default = typeof options.default === 'undefined' ? null : options.default;
this.infinite = Boolean(options.infinite);
this.avatarSize = typeof options.avatarSize === 'undefined' ? 2048 : options.avatarSize;
this.examples = typeof options.examples === 'undefined' ? null : options.examples;
this.validator = typeof options.validate === 'undefined' ? null : options.validate;
this.parser = typeof options.parse === 'undefined' ? null : options.parse;
this.emptyChecker = typeof options.isEmpty === 'undefined' ? null : options.isEmpty;
@@ -40,6 +41,11 @@ module.exports = class Argument {
return this.type.isEmpty(val, msg, arg);
}
example(msg, arg) {
if (this.examples) return this.examples[Math.floor(Math.random() * this.examples.length)];
return this.type.example(msg, arg);
}
get invalidText() {
if (this.oneOf) {
return `It must be one of the following: ${list(this.oneOf, 'or')}`;
+4
View File
@@ -16,4 +16,8 @@ module.exports = class ArgumentType {
isEmpty(val) {
return !val;
}
example() {
return 'moo';
}
};
+11
View File
@@ -49,6 +49,17 @@ module.exports = class Command {
return `\`${this.client.commandPrefix}${this.name}${args}\` or \`@${this.client.user.tag} ${this.name}${args}\``;
}
example(msg) {
const args = this.args.map((arg, i) => {
const example = arg.example(msg, arg);
if (i !== args.length - 1 && example.includes(' ')) {
return `"${example}"`;
}
return example;
});
return `${this.client.commandPrefix}${this.name} ${args.join(' ')}`;
}
disable() {
this._enabled = false;
}
+4
View File
@@ -59,6 +59,7 @@ module.exports = class CommandDispatcher {
error: stripIndents`
The "${arg.label || arg.key}" argument is required.
${arg.invalidText}
Correct Usage Example: ${command.example(msg)}
`
};
}
@@ -75,6 +76,7 @@ module.exports = class CommandDispatcher {
error: stripIndents`
An invalid value was provided for one of the "${arg.label || arg.key}" arguments.
${arg.invalidText}
Correct Usage Example: ${command.example(msg)}
`
};
}
@@ -91,6 +93,7 @@ module.exports = class CommandDispatcher {
error: stripIndents`
The "${arg.label || arg.key}" argument is required.
${arg.invalidText}
Correct Usage Example: ${command.example(msg)}
`
};
} else {
@@ -107,6 +110,7 @@ module.exports = class CommandDispatcher {
error: stripIndents`
An invalid value was provided for the "${arg.label || arg.key}" argument.
${arg.invalidText}
Correct Usage Example: ${command.example(msg)}
`
};
}
-21
View File
@@ -1,21 +0,0 @@
const ArgumentType = require('../ArgumentType');
module.exports = class BooleanArgumentType extends ArgumentType {
constructor(client) {
super(client, 'boolean');
this.truthy = new Set(['true', 't', 'yes', 'y', 'on', 'enable', 'enabled', '1', '+']);
this.falsy = new Set(['false', 'f', 'no', 'n', 'off', 'disable', 'disabled', '0', '-']);
}
validate(val) {
const lc = val.toLowerCase();
return this.truthy.has(lc) || this.falsy.has(lc);
}
parse(val) {
const lc = val.toLowerCase();
if (this.truthy.has(lc)) return true;
if (this.falsy.has(lc)) return false;
throw new RangeError('Unknown boolean value.');
}
};
+4
View File
@@ -28,6 +28,10 @@ module.exports = class ChannelArgumentType extends ArgumentType {
if (exactChannels.size === 1) return exactChannels.first();
return null;
}
example() {
return '#general';
}
};
function nameFilterExact(search) {
+4
View File
@@ -14,4 +14,8 @@ module.exports = class CommandArgumentType extends ArgumentType {
parse(val) {
return this.client.registry.findCommands(val).first();
}
example() {
return this.client.registry.commands.random().name;
}
};
+5
View File
@@ -29,6 +29,11 @@ module.exports = class CustomEmojiArgumentType extends ArgumentType {
if (exactEmojis.size === 1) return exactEmojis.first();
return null;
}
example(msg) {
if (msg.guild && msg.guild.emojis.cache.size) return msg.guild.emojis.cache.random().toString();
return this.client.emojis.cache.random().toString();
}
};
function nameFilterExact(search) {
+5
View File
@@ -1,5 +1,6 @@
const ArgumentType = require('../ArgumentType');
const emojiRegex = require('emoji-regex')();
const examples = ['😄', '🏳️‍🌈', '🦑', '🦆'];
module.exports = class DefaultEmojiArgumentType extends ArgumentType {
constructor(client) {
@@ -14,4 +15,8 @@ module.exports = class DefaultEmojiArgumentType extends ArgumentType {
parse(value) {
return value.match(emojiRegex)[0];
}
example() {
return examples[Math.floor(Math.random() * examples.length)];
}
};
+8
View File
@@ -1,4 +1,5 @@
const ArgumentType = require('../ArgumentType');
const { randomRange } = require('../../util/Util');
module.exports = class FloatArgumentType extends ArgumentType {
constructor(client) {
@@ -17,4 +18,11 @@ module.exports = class FloatArgumentType extends ArgumentType {
parse(val) {
return Number.parseFloat(val);
}
example(msg, arg) {
if (arg.oneOf) return arg.oneOf[Math.floor(Math.random() * arg.oneOf.length)];
const min = arg.min || 0;
const max = arg.max || 1000;
return randomRange(min, max);
}
};
+4
View File
@@ -14,4 +14,8 @@ module.exports = class GroupArgumentType extends ArgumentType {
parse(val) {
return this.client.registry.findGroups(val).first();
}
example() {
return this.client.registry.groups.random().id;
}
};
+8
View File
@@ -1,4 +1,5 @@
const ArgumentType = require('../ArgumentType');
const { randomRange } = require('../../util/Util');
module.exports = class IntegerArgumentType extends ArgumentType {
constructor(client) {
@@ -17,4 +18,11 @@ module.exports = class IntegerArgumentType extends ArgumentType {
parse(val) {
return Number.parseInt(val, 10);
}
example(msg, arg) {
if (arg.oneOf) return arg.oneOf[Math.floor(Math.random() * arg.oneOf.length)];
const min = arg.min || 0;
const max = arg.max || 1000;
return randomRange(min, max);
}
};
+6
View File
@@ -36,6 +36,12 @@ module.exports = class MemberArgumentType extends ArgumentType {
if (exactMembers.size === 1) return exactMembers.first();
return null;
}
example(msg) {
if (msg.guild) return msg.guild.members.cache.random().tag;
const members = [this.client.user, msg.channel.recipient];
return members[Math.floor(Math.random() * members.length)].tag;
}
};
function memberFilterExact(search) {
+4
View File
@@ -13,4 +13,8 @@ module.exports = class MessageArgumentType extends ArgumentType {
parse(val, msg) {
return msg.channel.messages.cache.get(val);
}
example(msg) {
return msg.id;
}
};
+5
View File
@@ -28,6 +28,11 @@ module.exports = class RoleArgumentType extends ArgumentType {
if (exactRoles.size === 1) return exactRoles.first();
return null;
}
example(msg) {
if (!msg.guild) return 'Administrator';
return msg.guild.roles.cache.random().name;
}
};
function nameFilterExact(search) {
+12
View File
@@ -1,4 +1,5 @@
const ArgumentType = require('../ArgumentType');
const words = require('../../assets/json/word-list');
module.exports = class StringArgumentType extends ArgumentType {
constructor(client) {
@@ -15,4 +16,15 @@ module.exports = class StringArgumentType extends ArgumentType {
parse(val) {
return val;
}
example(msg, arg) {
if (arg.oneOf) return arg.oneOf[Math.floor(Math.random() * arg.oneOf.length)];
let sentence = '';
while (sentence.length <= (arg.min || 50) || sentence.length <= (arg.max || 100)) {
const valid = words.filter(word => sentence.length + word.length + 1 <= (arg.max || 100));
if (!valid.length) break;
sentence += ` ${valid[Math.floor(Math.random() * valid.length)]}`;
}
return sentence.trim();
}
};
+6
View File
@@ -38,6 +38,12 @@ module.exports = class UserArgumentType extends ArgumentType {
if (exactMembers.size === 1) return exactMembers.first().user;
return null;
}
example(msg) {
if (msg.guild) return msg.guild.members.cache.random().tag;
const members = [this.client.user, msg.channel.recipient];
return members[Math.floor(Math.random() * members.length)].tag;
}
};
function memberFilterExact(search) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "151.2.1",
"version": "151.3.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"private": true,
+4
View File
@@ -34,4 +34,8 @@ module.exports = class FontArgument extends Argument {
if (foundExact.size === 1) return foundExact.first();
return null;
}
example() {
return this.client.fonts.random().filenameNoExt;
}
};
+4
View File
@@ -22,4 +22,8 @@ module.exports = class ImageOrAvatarArgument extends Argument {
return this.client.registry.types.get('image').isEmpty(value, msg, arg)
&& this.client.registry.types.get('user').isEmpty(value, msg, arg);
}
example(msg, arg) {
return this.client.registry.types.get('user').example(msg, arg);
}
};
+6
View File
@@ -2,6 +2,8 @@ const Argument = require('../framework/ArgumentType');
const fileTypeRe = /\.(jpe?g|png|gif|jfif|bmp)(\?.+)?$/i;
const request = require('node-superfetch');
const validURL = require('valid-url');
const logos = require('../../assets/json/logos');
const logoKeys = Object.keys(logos);
module.exports = class ImageArgument extends Argument {
constructor(client) {
@@ -41,4 +43,8 @@ module.exports = class ImageArgument extends Argument {
if (msg.attachments.size) return false;
return !value;
}
example() {
return `<${logos[logoKeys[Math.floor(Math.random() * logoKeys.length)]]}>`;
}
};
+4
View File
@@ -21,4 +21,8 @@ module.exports = class MonthArgument extends Argument {
if (shorthand.includes(value.toLowerCase())) return shorthand.indexOf(value.toLowerCase()) + 1;
return null;
}
example() {
return months[Math.floor(Math.random() * months.length)];
}
};
+6
View File
@@ -1,4 +1,5 @@
const Argument = require('../framework/ArgumentType');
const examples = ['Pikachu', 'Bulbasaur', 'Victini', 'Flygon'];
module.exports = class PokemonArgument extends Argument {
constructor(client) {
@@ -14,4 +15,9 @@ module.exports = class PokemonArgument extends Argument {
parse(value) {
return this.client.pokemon.fetch(value);
}
example() {
if (this.client.pokemon.size) return this.client.pokemon.random().name;
return examples[Math.floor(Math.random() * examples.length)];
}
};
+4
View File
@@ -15,4 +15,8 @@ module.exports = class SherlockType extends Argument {
parse(value) {
return sherlock.parse(value);
}
example() {
return 'sleep 1 hour';
}
};
+5
View File
@@ -37,4 +37,9 @@ module.exports = class TimezoneType extends Argument {
}
return null;
}
example() {
const zones = moment.tz.names();
return zones[Math.floor(Math.random() * zones.length)];
}
};
+4
View File
@@ -15,4 +15,8 @@ module.exports = class UrlType extends Argument {
if (!validURL.isWebUri(value)) return new URL(`http://${value}`);
return new URL(value);
}
example() {
return '<https://discord.com>';
}
};