mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add examples
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
};
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user