From b7bb4fdf2c5c382a86f501eea47728928491cd09 Mon Sep 17 00:00:00 2001 From: Wessel T Date: Sat, 23 Feb 2019 14:35:33 +0100 Subject: [PATCH] [refractor 1.3] Even more done! --- package.json | 2 +- src/assets/config/colors.yml | 4 +- src/commands/Discord/Core/locale.js | 4 +- src/commands/Discord/Core/prefix.js | 2 +- src/commands/Discord/Developer/eval.js | 2 +- src/commands/Discord/Developer/exec.js | 2 +- src/commands/Discord/Games/splatoon.js | 2 +- src/commands/Discord/Information/avatar.js | 2 +- src/commands/Discord/Information/commands.js | 2 +- src/commands/Discord/Information/commits.js | 2 +- src/commands/Discord/Information/guild.js | 2 +- src/commands/Discord/Information/user.js | 49 +++++------ src/commands/Discord/Tags/tag-add.js | 69 ++++++++-------- src/commands/Discord/Tags/tag-del.js | 51 +++++++----- src/commands/Discord/Tags/tag-info.js | 42 +++++----- src/commands/Discord/Tags/tag-source.js | 45 ++++++----- src/commands/Discord/Tags/tag.js | 36 +++++---- src/commands/Discord/Tags/tags.js | 85 +++++++++++--------- src/commands/Discord/Utility/math.js | 2 +- src/commands/Discord/Utility/snipe.js | 2 +- src/core/internal/Discord/Command.js | 2 +- src/core/internal/Discord/__baseCommand.js | 2 +- src/core/registry/Discord/Commands.js | 2 +- src/events/Discord/shardDisconnect.js | 2 +- src/events/Discord/shardReady.js | 2 +- src/events/Discord/shardResume.js | 2 +- yarn.lock | 8 +- 27 files changed, 236 insertions(+), 191 deletions(-) diff --git a/package.json b/package.json index cc56d43..b6c1fca 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "sharp": "^0.21.3", "table": "^5.2.3", "vm2": "^3.6.10", - "wumpfetch": "^0.0.8" + "wumpfetch": "^0.0.9" }, "devDependencies": { "eslint": "^5.6.0" diff --git a/src/assets/config/colors.yml b/src/assets/config/colors.yml index 2d51570..9cac6ae 100644 --- a/src/assets/config/colors.yml +++ b/src/assets/config/colors.yml @@ -24,7 +24,9 @@ info : multi : 0x34363C # Dark single: 0x34363C # Dark -tags: 0x7289DA # Blurple +tag : + list: 0x7289DA # Blurple + info: 0x7289DA # Blurple image : cat : 0x7289DA # Blurple diff --git a/src/commands/Discord/Core/locale.js b/src/commands/Discord/Core/locale.js index d53a52f..0a03d85 100644 --- a/src/commands/Discord/Core/locale.js +++ b/src/commands/Discord/Core/locale.js @@ -7,7 +7,7 @@ module.exports = class Locale extends DiscordCommand { syntax : 'locale <-u|-g>', aliases : [], argument : [ '', '-' ], - description : 'Change your locale', + description: 'Change your locale', hidden : false, enabled : true, @@ -61,7 +61,7 @@ module.exports = class Locale extends DiscordCommand { } } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; if (extData && extData.uLocale) msg = msg.replace(/\$\[uLocale:code]/g, extData.uLocale); diff --git a/src/commands/Discord/Core/prefix.js b/src/commands/Discord/Core/prefix.js index 9bb84e4..fd27017 100644 --- a/src/commands/Discord/Core/prefix.js +++ b/src/commands/Discord/Core/prefix.js @@ -83,7 +83,7 @@ module.exports = class Prefix extends DiscordCommand { } } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; // Optional replacements if (extData) { diff --git a/src/commands/Discord/Developer/eval.js b/src/commands/Discord/Developer/eval.js index 1aa15a1..efa7ecb 100644 --- a/src/commands/Discord/Developer/eval.js +++ b/src/commands/Discord/Developer/eval.js @@ -74,7 +74,7 @@ module.exports = class Eval extends DiscordCommand { } } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) return 'INVALID_STRING'; diff --git a/src/commands/Discord/Developer/exec.js b/src/commands/Discord/Developer/exec.js index 9d8048d..b3613e4 100644 --- a/src/commands/Discord/Developer/exec.js +++ b/src/commands/Discord/Developer/exec.js @@ -74,7 +74,7 @@ module.exports = class Exec extends DiscordCommand { } } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Games/splatoon.js b/src/commands/Discord/Games/splatoon.js index 7d44912..f78d813 100644 --- a/src/commands/Discord/Games/splatoon.js +++ b/src/commands/Discord/Games/splatoon.js @@ -40,7 +40,7 @@ module.exports = class Splatoon extends DiscordCommand { msg.channel.createMessage(this._localize(msg.author.locale.games.splatoon.join('\n'), res)); } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Information/avatar.js b/src/commands/Discord/Information/avatar.js index 704637e..5e461c0 100644 --- a/src/commands/Discord/Information/avatar.js +++ b/src/commands/Discord/Information/avatar.js @@ -146,7 +146,7 @@ module.exports = class Avatar extends DiscordCommand { }); } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Information/commands.js b/src/commands/Discord/Information/commands.js index 7b31525..39bc225 100644 --- a/src/commands/Discord/Information/commands.js +++ b/src/commands/Discord/Information/commands.js @@ -96,7 +96,7 @@ module.exports = class Commands extends DiscordCommand { } } - localize(msg, extData) { + localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Information/commits.js b/src/commands/Discord/Information/commits.js index 2206d0a..32d2f56 100644 --- a/src/commands/Discord/Information/commits.js +++ b/src/commands/Discord/Information/commits.js @@ -78,7 +78,7 @@ module.exports = class Stats extends DiscordCommand { } } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Information/guild.js b/src/commands/Discord/Information/guild.js index 4adf71b..31a1824 100644 --- a/src/commands/Discord/Information/guild.js +++ b/src/commands/Discord/Information/guild.js @@ -91,7 +91,7 @@ module.exports = class Guild extends DiscordCommand { }); } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Information/user.js b/src/commands/Discord/Information/user.js index 1f43329..03cd570 100644 --- a/src/commands/Discord/Information/user.js +++ b/src/commands/Discord/Information/user.js @@ -29,6 +29,9 @@ module.exports = class User extends DiscordCommand { 'offline' : `${this.bot.emote('info', 'user', '10')}offline` } }; + + Object.freeze(this); + Object.freeze(this.static); } async execute(msg, args) { @@ -84,44 +87,44 @@ module.exports = class User extends DiscordCommand { } } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; if (extData) { if (extData.user) { - const u = extData.user; - u.c = moment.preciseDiff(new Date(), new Date(u.createdAt), true); - u.cs = [ - u.c.years >= 1 ? `${u.c.years} years` : undefined, - u.c.months >= 1 ? `${u.c.months} months` : undefined, - u.c.days >= 1 ? `${u.c.days} days` : undefined, - u.c.days <= 0 && u.c.months <= 0 && u.c.years <= 0 ? 'Less than a day' : undefined + const { user } = extData; + user.c = moment.preciseDiff(new Date(), new Date(user.createdAt), true); + user.cs = [ + user.c.years >= 1 ? `${user.c.years} years` : undefined, + user.c.months >= 1 ? `${user.c.months} months` : undefined, + user.c.days >= 1 ? `${user.c.days} days` : undefined, + user.c.days <= 0 && user.c.months <= 0 && user.c.years <= 0 ? 'Less than a day' : undefined ].join(' '); msg = msg - .replace(/\$\[user:id]/g , u.id) - .replace(/\$\[user:tag]/g , `${u.username}#${u.discriminator}`) - .replace(/\$\[user:created@exact]/g, moment(u.createdAt).format('YYYY[/]MM[/]DD HH[:]mm')) - .replace(/\$\[user:created@precise]/g, u.cs) + .replace(/\$\[user:id]/g , user.id) + .replace(/\$\[user:tag]/g , `${user.username}#${user.discriminator}`) + .replace(/\$\[user:created@exact]/g, moment(user.createdAt).format('YYYY[/]MM[/]DD HH[:]mm')) + .replace(/\$\[user:created@precise]/g, user.cs) .replace(/\$\[user:status@full]/g, extData.member && this.static.status[extData.member.status] ? this.static.status[extData.member.status] : this.static.status['_unknown']); } if (extData.member) { - const m = extData.member; - m.c = moment.preciseDiff(new Date(), new Date(m.joinedAt), true); - m.cs = [ - m.c.years >= 1 ? `${m.c.years} years` : undefined, - m.c.months >= 1 ? `${m.c.months} months` : undefined, - m.c.days >= 1 ? `${m.c.days} days` : undefined, - m.c.days <= 0 && m.c.months <= 0 && m.c.years <= 0 ? 'Less than a day' : undefined + const { member } = extData; + member.c = moment.preciseDiff(new Date(), new Date(member.joinedAt), true); + member.cs = [ + member.c.years >= 1 ? `${member.c.years} years` : undefined, + member.c.months >= 1 ? `${member.c.months} months` : undefined, + member.c.days >= 1 ? `${member.c.days} days` : undefined, + member.c.days <= 0 && member.c.months <= 0 && member.c.years <= 0 ? 'Less than a day' : undefined ].join(' '); msg = msg - .replace(/\$\[member:nickname]/g, m && m.nick ? this.bot.util.escapeMarkdown(m.nick) : '*No nickname set*') - .replace(/\$\[member:roles]/g, m.roles.length >= 1 ? this._limit(m.roles.map((v) => `<@&${v}>`), 25).join(' **/** ') : 'none') - .replace(/\$\[member:created@exact]/g, moment(m.joinedAt).format('YYYY[/]MM[/]DD HH[:]mm')) - .replace(/\$\[member:created@precise]/g, m.cs); + .replace(/\$\[member:nickname]/g, member && member.nick ? this.bot.util.escapeMarkdown(member.nick) : '*No nickname set*') + .replace(/\$\[member:roles]/g, member.roles.length >= 1 ? this._limit(member.roles.map((v) => `<@&${v}>`), 25).join(' **/** ') : 'none') + .replace(/\$\[member:created@exact]/g, moment(member.joinedAt).format('YYYY[/]MM[/]DD HH[:]mm')) + .replace(/\$\[member:created@precise]/g, member.cs); } } diff --git a/src/commands/Discord/Tags/tag-add.js b/src/commands/Discord/Tags/tag-add.js index be58a8b..94e2451 100644 --- a/src/commands/Discord/Tags/tag-add.js +++ b/src/commands/Discord/Tags/tag-add.js @@ -1,29 +1,28 @@ +// @TODO: refractor const { DiscordCommand } = require('../../../core'); -const m = require('moment'); - module.exports = class TagAdd extends DiscordCommand { constructor(bot) { super(bot, { - name : 'tag-add', - syntax : 'tag-add <...name:str> | <..content:string>', - aliases : [ 'tagadd', 'addtag', 'createtag', 'tagcreate', 'maketag', 'make-tag', 'tag-create' ], - argument : [ '<...name:str>', '<..content:string>' ], - description : 'Create a tag', + name : 'tag-add', + syntax : 'tag-add <...name:str> | <..content:string>', + aliases : [ 'tagadd', 'addtag', 'createtag', 'tagcreate', 'maketag', 'make-tag', 'tag-create' ], + argument : [ '<...name:str>', '<..content:string>' ], + description: 'Create a tag', - hidden : false, - enabled : true, - cooldown : 1000, - category : 'Tags', - ownerOnly : false, - guildOnly : true, - permissions : [] + hidden : false, + enabled : true, + cooldown : 1000, + category : 'Tags', + ownerOnly : false, + guildOnly : true, + permissions: [] }); } async execute(msg, args) { - - let components = args.join(' ').split(/\|/g); + let components = args.join(' ').split(/\|/g).filter((v) => { return v.length >= 1 }); + let mess; let tag = { name : undefined, uses : 0, @@ -41,12 +40,6 @@ module.exports = class TagAdd extends DiscordCommand { } }; - // Delete all empty elements in `components` - components = components.filter((v) => { - return v.length >= 1; - }); - - let mess; if (!components[0]) { mess = await msg.channel.createMessage(this._localize(msg.author.locale.tags.add.name.join('\n'))); @@ -83,21 +76,27 @@ module.exports = class TagAdd extends DiscordCommand { entry = new this.bot.schema.tag(tag); await entry.save(); - msg.channel.createMessage(this._localize(msg.author.locale.tags.add.success, { name: this.bot.util.escapeMarkdown(tag.name) })); + msg.channel.createMessage(this._localize(msg.author.locale.tags.add.success, this.bot.util.escapeMarkdown(tag.name))); } - _localize(msg, extData) { - if (extData) { - msg = msg.replace(/\$\[tag:name]/g, extData.name); + _localize(msg, extData = {}) { + try { + if (!msg) throw 'INVALID_STRING'; + + if (extData) { + msg = msg.replace(/\$\[tag:name]/g, extData); + } + + return msg + .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'add', '0')) + .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'add', '1')) + .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'add', '2')) + .replace(/\$\[emoji#3]/g, this.bot.emote('tags', 'add', '3')) + .replace(/\$\[emoji#4]/g, this.bot.emote('tags', 'add', '4')) + .replace(/\$\[emoji#5]/g, this.bot.emote('tags', 'add', '5')) + .replace(/\$\[emoji#6]/g, this.bot.emote('tags', 'add', '6')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; } - - return msg - .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'add', '0')) - .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'add', '1')) - .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'add', '2')) - .replace(/\$\[emoji#3]/g, this.bot.emote('tags', 'add', '3')) - .replace(/\$\[emoji#4]/g, this.bot.emote('tags', 'add', '4')) - .replace(/\$\[emoji#5]/g, this.bot.emote('tags', 'add', '5')) - .replace(/\$\[emoji#6]/g, this.bot.emote('tags', 'add', '6')); } }; \ No newline at end of file diff --git a/src/commands/Discord/Tags/tag-del.js b/src/commands/Discord/Tags/tag-del.js index e251ddf..539650b 100644 --- a/src/commands/Discord/Tags/tag-del.js +++ b/src/commands/Discord/Tags/tag-del.js @@ -3,20 +3,23 @@ const { DiscordCommand } = require('../../../core'); module.exports = class TagDel extends DiscordCommand { constructor(bot) { super(bot, { - name : 'tag-del', - syntax : 'tag-del <...tag:str>', - aliases : [ 'tagdel', 'deltag', 'tagdelete', 'deletetag', 'del-tag', 'tag-delete', 'delete-tag' ], - argument : [ '<...tag:str>' ], - description : 'Delete a tag', + name : 'tag-del', + syntax : 'tag-del <...tag:str>', + aliases : [ 'tagdel', 'deltag', 'tagdelete', 'deletetag', 'del-tag', 'tag-delete', 'delete-tag' ], + argument : [ '<...tag:str>' ], + description: 'Delete a tag', - hidden : false, - enabled : true, - cooldown : 2500, - category : 'Tags', - ownerOnly : false, - guildOnly : true, - permissions : [] + hidden : false, + enabled : true, + cooldown : 2500, + category : 'Tags', + ownerOnly : false, + guildOnly : true, + permissions: [] }); + + Object.freeze(this); + Object.freeze(this.static); } async execute(msg, args) { @@ -31,17 +34,17 @@ module.exports = class TagDel extends DiscordCommand { return msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.perms)); } - const mess = await msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.confirm.join('\n'), { name: tag.name.replace(/`/g, '`\u200b') })); + const mess = await msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.confirm.join('\n'), tag.name.replace(/`/g, '`\u200b'))); const res = await this.bot.collector.awaitMessage(msg.channel.id, msg.author.id, 30e3); if (res && res.content.toLowerCase() === 'y' || res.content.toLowerCase() === 'ye' || res.content.toLowerCase() === 'yes') { - if (mess) mess.edit(this._localize(msg.author.locale.tags.delete.busy, { name: tag.name.replace(/`/g, '`\u200b') })); + if (mess) mess.edit(this._localize(msg.author.locale.tags.delete.busy, tag.name.replace(/`/g, '`\u200b'))); this.bot.m.connection.collection('dTags').deleteOne({ name: tag.name, 'author.guild': msg.channel.guild.id }); if (mess) { mess.delete().catch(() => { return; }); } - msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.done, { name: this.bot.util.escapeMarkdown(tag.name) })); + msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.done, this.bot.util.escapeMarkdown(tag.name))); } else { if (mess) { return mess.edit(this._localize(msg.author.locale.cancelled)); @@ -49,12 +52,17 @@ module.exports = class TagDel extends DiscordCommand { } } - _localize(msg, extData) { - if (extData) { - msg = msg.replace(/\$\[tag:name]/g, extData.name); - } + _localize(msg, extData = {}) { + try { + if (!msg) throw 'INVALID_STRING'; + - return msg + if (extData) { + msg = msg.replace(/\$\[tag:name]/g, extData); + } + + + return msg .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'del', '0')) .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'del', '1')) .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'del', '2')) @@ -62,5 +70,8 @@ module.exports = class TagDel extends DiscordCommand { .replace(/\$\[emoji#4]/g, this.bot.emote('tags', 'del', '4')) .replace(/\$\[emoji#5]/g, this.bot.emote('tags', 'del', '5')) .replace(/\$\[emoji#6]/g, this.bot.emote('tags', 'del', '6')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; + } } }; \ No newline at end of file diff --git a/src/commands/Discord/Tags/tag-info.js b/src/commands/Discord/Tags/tag-info.js index 840258a..6d4e0ce 100644 --- a/src/commands/Discord/Tags/tag-info.js +++ b/src/commands/Discord/Tags/tag-info.js @@ -9,7 +9,7 @@ module.exports = class TagInfo extends DiscordCommand { syntax : 'tag-info <...tag:str>', aliases : [], argument : [ '<...tag:str>' ], - description : 'Info about a tag', + description: 'Info about a tag', hidden : false, enabled : true, @@ -20,9 +20,12 @@ module.exports = class TagInfo extends DiscordCommand { permissions : [] }); - this.mutable = { + this.static = { MAX_INT32: 2147483647 }; + + Object.freeze(this); + Object.freeze(this.static); } async execute(msg, args) { @@ -33,31 +36,34 @@ module.exports = class TagInfo extends DiscordCommand { msg.channel.createMessage({ embed: { - description: this._localize(msg.author.locale.tags.info.join('\n'), { tag: tag }) + color: this.bot.col.tag.info, + description: this._localize(msg.author.locale.tags.info.join('\n'), tag) } }); } _localize(msg, extData = {}) { try { + if (!msg) throw 'INVALID_STRING'; + if (extData) { - if (extData.tag) { - msg = msg - .replace(/\$\[tag:name]/g, this.bot.util.escapeMarkdown(extData.tag.name)) - .replace(/\$\[tag:uses]/g, extData.tag.uses) - .replace(/\$\[tag:history]/g, extData.tag.history.splice(0, 10).join('\n')) - .replace(/\$\[tag:creation]/g, moment(new Date(extData.tag.creation)).format('DD[-]MM[-]YYYY HH[:]mm[:]ss')) - .replace(/\$\[tag:creator#tag]/g, this.bot.util.escapeMarkdown(`${extData.tag.author.name}#${extData.tag.author.discrim}`)); - } + msg = msg + .replace(/\$\[tag:name]/g, this.bot.util.escapeMarkdown(extData.name)) + .replace(/\$\[tag:uses]/g, extData.uses) + .replace(/\$\[tag:history]/g, extData.history.splice(0, 10).join('\n')) + .replace(/\$\[tag:creation]/g, moment(new Date(extData.creation)).format('DD[-]MM[-]YYYY HH[:]mm[:]ss')) + .replace(/\$\[tag:creator#tag]/g, this.bot.util.escapeMarkdown(`${extData.author.name}#${extData.author.discrim}`)); } return msg - .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'info', '0')) - .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'info', '1')) - .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'info', '2')) - .replace(/\$\[emoji#3]/g, this.bot.emote('tags', 'info', '3')) - .replace(/\$\[emoji#4]/g, this.bot.emote('tags', 'info', '4')) - .replace(/\$\[emoji#5]/g, this.bot.emote('tags', 'info', '5')); - } catch (ex) {} + .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'info', '0')) + .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'info', '1')) + .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'info', '2')) + .replace(/\$\[emoji#3]/g, this.bot.emote('tags', 'info', '3')) + .replace(/\$\[emoji#4]/g, this.bot.emote('tags', 'info', '4')) + .replace(/\$\[emoji#5]/g, this.bot.emote('tags', 'info', '5')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; + } } }; \ No newline at end of file diff --git a/src/commands/Discord/Tags/tag-source.js b/src/commands/Discord/Tags/tag-source.js index 714531d..33e3b8d 100644 --- a/src/commands/Discord/Tags/tag-source.js +++ b/src/commands/Discord/Tags/tag-source.js @@ -3,20 +3,23 @@ const { DiscordCommand } = require('../../../core'); module.exports = class TagSource extends DiscordCommand { constructor(bot) { super(bot, { - name : 'tag-source', - syntax : 'tag-source <...tag:str>', - aliases : [ 'tagsource', 'tagsrc', 'tag-src' ], - argument : [ '<...tag:str>' ], - description : 'Source of a tag', + name : 'tag-source', + syntax : 'tag-source <...tag:str>', + aliases : [ 'tagsource', 'tagsrc', 'tag-src' ], + argument : [ '<...tag:str>' ], + description: 'Source of a tag', - hidden : false, - enabled : true, - cooldown : 2500, - category : 'Tags', - ownerOnly : false, - guildOnly : true, - permissions : [] + hidden : false, + enabled : true, + cooldown : 2500, + category : 'Tags', + ownerOnly : false, + guildOnly : true, + permissions: [] }); + + Object.freeze(this); + Object.freeze(this.static); } async execute(msg, args) { @@ -25,16 +28,22 @@ module.exports = class TagSource extends DiscordCommand { return msg.channel.createMessage(this._localize(msg.author.locale.tags.exec)); } - msg.channel.createMessage(this.bot.util.shorten(this._localize(msg.author.locale.tags.source, tag), 1950)); + msg.channel.createMessage(this.bot.util.shorten(this._localize(msg.author.locale.tags.source, tag), 2000)); } - _localize(msg, extData) { - if (extData) { - msg = msg.replace(/\$\[tag:name]/g, extData.name.replace(/`/g, '`\u200b')).replace(/\$\[tag:content]/g, extData.content.replace(/`/g, '`\u200b')); - } + _localize(msg, extData = {}) { + try { + if (!msg) throw 'INVALID_STRING'; - return msg + if (extData) { + msg = msg.replace(/\$\[tag:name]/g, extData.name.replace(/`/g, '`\u200b')).replace(/\$\[tag:content]/g, extData.content.replace(/`/g, '`\u200b')); + } + + return msg .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'source', '0')) .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'source', '1')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; + } } }; \ No newline at end of file diff --git a/src/commands/Discord/Tags/tag.js b/src/commands/Discord/Tags/tag.js index 5a59b78..583b756 100644 --- a/src/commands/Discord/Tags/tag.js +++ b/src/commands/Discord/Tags/tag.js @@ -3,22 +3,22 @@ const { DiscordCommand } = require('../../../core'); module.exports = class Tag extends DiscordCommand { constructor(bot) { super(bot, { - name : 'tag', - syntax : 'tag <...tag:str>', - aliases : [ 'show-tag', 'disp-tag' ], - argument : [ '<...tag:str>' ], - description : 'Display a tag', + name : 'tag', + syntax : 'tag <...tag:str>', + aliases : [ 'show-tag', 'disp-tag' ], + argument : [ '<...tag:str>' ], + description: 'Display a tag', - hidden : false, - enabled : true, - cooldown : 2500, - category : 'Tags', - ownerOnly : false, - guildOnly : true, - permissions : [] + hidden : false, + enabled : true, + cooldown : 2500, + category : 'Tags', + ownerOnly : false, + guildOnly : true, + permissions: [] }); - this.mutable = { + this.static = { MAX_INT32: 2147483647 }; } @@ -30,10 +30,16 @@ module.exports = class Tag extends DiscordCommand { } msg.channel.createMessage(tag.content); - this.bot.m.connection.collection('dTags').findOneAndUpdate({ name: tag.name, 'author.guild': msg.channel.guild.id }, { $set: { uses: tag.uses < this.mutable.MAX_INT32 ? +1 : this.mutable.MAX_INT32 } }); + this.bot.m.connection.collection('dTags').findOneAndUpdate({ name: tag.name, 'author.guild': msg.channel.guild.id }, { $set: { uses: tag.uses < this.static.MAX_INT32 ? tag.uses + 1 : this.static.MAX_INT32 } }); } _localize(msg) { - return msg.replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'exec')); + try { + if (!msg) throw 'INVALID_STRING'; + + return msg.replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'exec')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; + } } }; \ No newline at end of file diff --git a/src/commands/Discord/Tags/tags.js b/src/commands/Discord/Tags/tags.js index 152b2d0..d588da9 100644 --- a/src/commands/Discord/Tags/tags.js +++ b/src/commands/Discord/Tags/tags.js @@ -6,23 +6,23 @@ const { table } = require('table'); module.exports = class Tags extends DiscordCommand { constructor(bot) { super(bot, { - name : 'tags', - syntax : 'tags', - aliases : [], - argument : [], - description : 'A list of all tags', + name : 'tags', + syntax : 'tags', + aliases : [], + argument : [], + description: 'A list of all tags', - hidden : false, - enabled : true, - cooldown : 2500, - category : 'Tags', - ownerOnly : false, - guildOnly : true, - permissions : [] + hidden : false, + enabled : true, + cooldown : 2500, + category : 'Tags', + ownerOnly : false, + guildOnly : true, + permissions: [] }); - this.mutable = { - LIMIT: 35, + this.static = { + limit: 35, BASE_URL: 'https://hastebin.com', TABLE_CONFIG: { border: { @@ -50,6 +50,9 @@ module.exports = class Tags extends DiscordCommand { } } }; + + Object.freeze(this); + Object.freeze(this.static); } async execute(msg) { @@ -61,46 +64,52 @@ module.exports = class Tags extends DiscordCommand { } const extData = { - tags: Array.list(tags.map((v) => `${this.bot.util.escapeMarkdown(v.name)} (\`${v.uses}\`)`).slice(0, this.mutable.LIMIT), '**,** ', '**and** '), + tags: Array.list(tags.map((v) => `${this.bot.util.escapeMarkdown(v.name)} (\`${v.uses}\`)`).slice(0, this.static.limit), '**,** ', '**and** '), guild: msg.channel.guild.name }; - if (tags.length > this.mutable.LIMIT) { + if (tags.length > this.static.limit) { tags.map((v) => data.push([ v.name, `${v.author.name}#${v.author.discrim}`, v.uses ])); - let res = await w(`${this.mutable.BASE_URL}/documents`, { method: 'POST', data: table(data, this.mutable.TABLE_CONFIG) }).send(); - res = res.json(); + const req = await w(`${this.mutable.BASE_URL}/documents`, { method: 'POST', data: table(data, this.mutable.TABLE_CONFIG) }).send(); + const res = req.json(); extData.tags += `\n${this._localize(msg.author.locale.tags.all.extend, { extend: `${this.mutable.BASE_URL}/raw/${res.key}.txt` })}`; } msg.channel.createMessage({ embed: { - color: this.bot.col['tags'], + color: this.bot.col.tag.list, description: this._localize(msg.author.locale.tags.all.list.join('\n'), extData) } }); } - _localize(msg, extData) { - if (extData) { - if (extData.guild) { - msg = msg.replace(/\$\[guild:name]/g, extData.guild); - } - if (extData.tags) { - msg = msg.replace(/\$\[tag:list]/g, extData.tags); - } - if (extData.extend) { - msg = msg.replace(/\$\[tag:full]/g, extData.extend); - } - if (extData.prefix) { - msg = msg.replace(/\$\[tag:cmd]/g, `${extData.prefix}${this.bot.cmds.get('tag-add').extData.syntax}`); - } - } + _localize(msg, extData = {}) { + try { + if (!msg) throw 'INVALID_STRING'; - return msg - .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'list', '0')) - .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'list', '1')) - .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'list', '2')); + if (extData) { + if (extData.guild) { + msg = msg.replace(/\$\[guild:name]/g, extData.guild); + } + if (extData.tags) { + msg = msg.replace(/\$\[tag:list]/g, extData.tags); + } + if (extData.extend) { + msg = msg.replace(/\$\[tag:full]/g, extData.extend); + } + if (extData.prefix) { + msg = msg.replace(/\$\[tag:cmd]/g, `${extData.prefix}${this.bot.cmds.get('tag-add').extData.syntax}`); + } + } + + return msg + .replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'list', '0')) + .replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'list', '1')) + .replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'list', '2')); + } catch (ex) { + return `LOCALIZE_ERROR:${ex}`; + } } }; \ No newline at end of file diff --git a/src/commands/Discord/Utility/math.js b/src/commands/Discord/Utility/math.js index d0c6c11..ff0b510 100644 --- a/src/commands/Discord/Utility/math.js +++ b/src/commands/Discord/Utility/math.js @@ -53,7 +53,7 @@ module.exports = class Math extends DiscordCommand { } } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/commands/Discord/Utility/snipe.js b/src/commands/Discord/Utility/snipe.js index d30186b..6bdb15a 100644 --- a/src/commands/Discord/Utility/snipe.js +++ b/src/commands/Discord/Utility/snipe.js @@ -91,7 +91,7 @@ module.exports = class Snipe extends DiscordCommand { this.bot.cache.delete(`${msg.channel.id}:SNIPE`); } - _localize(msg, extData) { + _localize(msg, extData = {}) { try { if (!msg) throw 'INVALID_STRING'; diff --git a/src/core/internal/Discord/Command.js b/src/core/internal/Discord/Command.js index 776acd7..5b6c98a 100644 --- a/src/core/internal/Discord/Command.js +++ b/src/core/internal/Discord/Command.js @@ -7,7 +7,7 @@ module.exports = class WumpCommand { syntax : null, // Command syntax ( optional ) aliases : [], // Command aliases ( optional ) argument : [], // Command arguments ( optional ) - description : null, // Command description ( optional ) + description: null, // Command description ( optional ) // Checks hidden : false, // Hidden from view ( true / false ) enabled : true, // Enabled or disabled ( true / false ) diff --git a/src/core/internal/Discord/__baseCommand.js b/src/core/internal/Discord/__baseCommand.js index bb6bd96..ecbacae 100644 --- a/src/core/internal/Discord/__baseCommand.js +++ b/src/core/internal/Discord/__baseCommand.js @@ -7,7 +7,7 @@ module.exports = class name extends DiscordCommand { syntax : '', aliases : [], argument : [], - description : '', + description: '', hidden : false, enabled : true, diff --git a/src/core/registry/Discord/Commands.js b/src/core/registry/Discord/Commands.js index fffffae..c0777d1 100644 --- a/src/core/registry/Discord/Commands.js +++ b/src/core/registry/Discord/Commands.js @@ -184,7 +184,7 @@ module.exports = class CommandRegistry { } else return false; } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; if (extData.err) msg = msg diff --git a/src/events/Discord/shardDisconnect.js b/src/events/Discord/shardDisconnect.js index fda8bdf..b4225c7 100644 --- a/src/events/Discord/shardDisconnect.js +++ b/src/events/Discord/shardDisconnect.js @@ -16,7 +16,7 @@ module.exports = class shardDisconnect extends DiscordEvent { this.bot.hook.send({ content: this.localize(this.strings['connection']['shard']['disconnect'], { shard: id }) }); } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; return msg .replace(/\$\[shard:id]/g, extData.shard) diff --git a/src/events/Discord/shardReady.js b/src/events/Discord/shardReady.js index 8deff7f..8174e4d 100644 --- a/src/events/Discord/shardReady.js +++ b/src/events/Discord/shardReady.js @@ -16,7 +16,7 @@ module.exports = class ShardReady extends DiscordEvent { this.bot.hook.send({ content: this.localize(this.strings['connection']['shard']['ready'], { shard: id }) }); } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; return msg .replace(/\$\[shard:id]/g, extData.shard) diff --git a/src/events/Discord/shardResume.js b/src/events/Discord/shardResume.js index dbd3e72..2fd1d00 100644 --- a/src/events/Discord/shardResume.js +++ b/src/events/Discord/shardResume.js @@ -16,7 +16,7 @@ module.exports = class ShardResume extends DiscordEvent { this.bot.hook.send({ content: this.localize(this.strings['connection']['shard']['resume'], { shard: id }) }); } - localize(msg, extData) { + localize(msg, extData = {}) { if (!msg) return ''; return msg .replace(/\$\[shard:id]/g, extData.shard) diff --git a/yarn.lock b/yarn.lock index 1b37c2d..ba39581 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1485,10 +1485,10 @@ ws@^6.0.0: dependencies: async-limiter "~1.0.0" -wumpfetch@^0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/wumpfetch/-/wumpfetch-0.0.8.tgz#4a3f86a7d966846f4ef68ffe98027b05e36cef56" - integrity sha512-RXwB+JwUTMYWHaKQ0n32CoCLwJVO8jU4BTPC2qqhhgmyKawIdu+Dq/m73aUW4y1AZvM8iBcDcMBELmVgT8bMJA== +wumpfetch@^0.0.9: + version "0.0.9" + resolved "https://registry.yarnpkg.com/wumpfetch/-/wumpfetch-0.0.9.tgz#450003f1dff92aafb4cfa173e81867aacfbe05cf" + integrity sha512-1n+zM5Ozpow0xF/wM+8TbIXoGvy9Co0UK9delRIZZdFY6r1kCVTbdygjGyRoZZ3d+WPJa7k70sfT/saLR/mEcA== xtend@^4.0.0: version "4.0.1"