mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Framework Rewrite
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const codeblock = /```(?:(\S+)\n)?\s*([^]+?)\s*```/i;
|
||||
|
||||
module.exports = class CodeArgumentType extends ArgumentType {
|
||||
module.exports = class CodeArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'code');
|
||||
}
|
||||
|
||||
+4
-8
@@ -1,14 +1,13 @@
|
||||
const { ArgumentType, util: { disambiguation } } = require('discord.js-commando');
|
||||
const { escapeMarkdown } = require('discord.js');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
|
||||
module.exports = class FontArgumentType extends ArgumentType {
|
||||
module.exports = class FontArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'font');
|
||||
}
|
||||
|
||||
validate(value) {
|
||||
const choice = value.toLowerCase();
|
||||
let found = this.client.fonts.filter(font => {
|
||||
const found = this.client.fonts.filter(font => {
|
||||
if (font.isFallback) return false;
|
||||
if (font.name.toLowerCase().includes(choice)) return true;
|
||||
if (font.filenameNoExt.toLowerCase().includes(choice)) return true;
|
||||
@@ -22,10 +21,7 @@ module.exports = class FontArgumentType extends ArgumentType {
|
||||
return false;
|
||||
});
|
||||
if (foundExact.size === 1) return true;
|
||||
if (foundExact.size > 0) found = foundExact;
|
||||
return found.size <= 15
|
||||
? `${disambiguation(found.map(font => escapeMarkdown(font.filenameNoExt)), 'fonts', null)}\n`
|
||||
: 'Multiple fonts found. Please be more specific.';
|
||||
return false;
|
||||
}
|
||||
|
||||
parse(value) {
|
||||
|
||||
+12
-12
@@ -1,25 +1,25 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
|
||||
module.exports = class ImageOrAvatarArgumentType extends ArgumentType {
|
||||
module.exports = class ImageOrAvatarArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'image-or-avatar');
|
||||
}
|
||||
|
||||
async validate(value, msg, arg, currentMsg) {
|
||||
const image = await this.client.registry.types.get('image').validate(value, msg, arg, currentMsg);
|
||||
async validate(value, msg, arg) {
|
||||
const image = await this.client.registry.types.get('image').validate(value, msg, arg);
|
||||
if (image) return image;
|
||||
return this.client.registry.types.get('user').validate(value, msg, arg, currentMsg);
|
||||
return this.client.registry.types.get('user').validate(value, msg, arg);
|
||||
}
|
||||
|
||||
async parse(value, msg, arg, currentMsg) {
|
||||
const image = this.client.registry.types.get('image').parse(value, msg, arg, currentMsg);
|
||||
async parse(value, msg, arg) {
|
||||
const image = this.client.registry.types.get('image').parse(value, msg, arg);
|
||||
if (image) return image;
|
||||
const user = await this.client.registry.types.get('user').parse(value, msg, arg, currentMsg);
|
||||
return user.displayAvatarURL({ format: 'png', size: 512 });
|
||||
const user = await this.client.registry.types.get('user').parse(value, msg, arg);
|
||||
return user.displayAvatarURL({ format: 'png', size: arg.avatarSize || 512 });
|
||||
}
|
||||
|
||||
isEmpty(value, msg, arg, currentMsg) {
|
||||
return this.client.registry.types.get('image').isEmpty(value, msg, arg, currentMsg)
|
||||
&& this.client.registry.types.get('user').isEmpty(value, msg, arg, currentMsg);
|
||||
isEmpty(value, msg, arg) {
|
||||
return this.client.registry.types.get('image').isEmpty(value, msg, arg)
|
||||
&& this.client.registry.types.get('user').isEmpty(value, msg, arg);
|
||||
}
|
||||
};
|
||||
|
||||
+10
-10
@@ -1,18 +1,18 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const fileTypeRe = /\.(jpe?g|png|gif|jfif|bmp)(\?.+)?$/i;
|
||||
const request = require('node-superfetch');
|
||||
const validURL = require('valid-url');
|
||||
|
||||
module.exports = class ImageArgumentType extends ArgumentType {
|
||||
module.exports = class ImageArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'image');
|
||||
}
|
||||
|
||||
async validate(value, msg, arg, currentMsg) {
|
||||
const attachment = currentMsg.attachments.first();
|
||||
async validate(value, msg) {
|
||||
const attachment = msg.attachments.first();
|
||||
if (attachment) {
|
||||
if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.';
|
||||
if (!fileTypeRe.test(attachment.name)) return 'Please only send PNG, JPG, BMP, or GIF format images.';
|
||||
if (attachment.size > 8e+6) return false;
|
||||
if (!fileTypeRe.test(attachment.name)) return false;
|
||||
return true;
|
||||
}
|
||||
if (fileTypeRe.test(value.toLowerCase())) {
|
||||
@@ -27,15 +27,15 @@ module.exports = class ImageArgumentType extends ArgumentType {
|
||||
return false;
|
||||
}
|
||||
|
||||
parse(value, msg, arg, currentMsg) {
|
||||
const attachment = currentMsg.attachments.first();
|
||||
parse(value, msg) {
|
||||
const attachment = msg.attachments.first();
|
||||
if (attachment) return attachment.url;
|
||||
if (fileTypeRe.test(value.toLowerCase())) return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
isEmpty(value, msg, arg, currentMsg) {
|
||||
if (currentMsg.attachments.size) return false;
|
||||
isEmpty(value, msg) {
|
||||
if (msg.attachments.size) return false;
|
||||
return !value;
|
||||
}
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const { months, shorthand } = require('../assets/json/month');
|
||||
|
||||
module.exports = class MonthArgumentType extends ArgumentType {
|
||||
module.exports = class MonthArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'month');
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
|
||||
module.exports = class PokemonArgumentType extends ArgumentType {
|
||||
module.exports = class PokemonArgument extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'pokemon');
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const sherlock = require('sherlockjs');
|
||||
|
||||
module.exports = class SherlockType extends ArgumentType {
|
||||
module.exports = class SherlockType extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'sherlock');
|
||||
}
|
||||
|
||||
validate(value) {
|
||||
const time = sherlock.parse(value);
|
||||
if (!time.startDate) return 'Please provide a valid starting time.';
|
||||
if (!time.startDate) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const cityTimezones = require('city-timezones');
|
||||
const { ZipToTz } = require('zip-to-timezone');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
module.exports = class TimezoneType extends ArgumentType {
|
||||
module.exports = class TimezoneType extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'timezone');
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const Argument = require('../framework/ArgumentType');
|
||||
const { URL } = require('url');
|
||||
const validURL = require('valid-url');
|
||||
|
||||
module.exports = class UrlType extends ArgumentType {
|
||||
module.exports = class UrlType extends Argument {
|
||||
constructor(client) {
|
||||
super(client, 'url');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user