Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

src: make piece serializer better and add aliases #541

Merged
merged 3 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/inhibitors/disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = class extends Inhibitor {

run(message, command) {
if (!command.enabled) throw message.language.get('INHIBITOR_DISABLED_GLOBAL');
if (message.guildSettings.disabledCommands.includes(command.name)) throw message.language.get('INHIBITOR_DISABLED_GUILD');
if (message.guildSettings.get('disabledCommands').includes(command.name)) throw message.language.get('INHIBITOR_DISABLED_GUILD');
}

};
1 change: 1 addition & 0 deletions src/languages/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = class extends Language {
RESOLVER_INVALID_MEMBER: (name) => `${name} must be a mention or valid user id.`,
RESOLVER_INVALID_MESSAGE: (name) => `${name} must be a valid message id.`,
RESOLVER_INVALID_PIECE: (name, piece) => `${name} must be a valid ${piece} name.`,
RESOLVER_INVALID_STORE: (store) => `${store} must be a valid store name that is located in client.pieceStores`,
RESOLVER_INVALID_REGEX_MATCH: (name, pattern) => `${name} must follow this regex pattern \`${pattern}\`.`,
RESOLVER_INVALID_ROLE: (name) => `${name} must be a role mention or role id.`,
RESOLVER_INVALID_STRING: (name) => `${name} must be a valid string.`,
Expand Down
15 changes: 13 additions & 2 deletions src/serializers/piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ const { Serializer } = require('klasa');
module.exports = class extends Serializer {

constructor(...args) {
super(...args, { aliases: ['command', 'language'] });
super(...args);

// Adds all pieces, custom or not, to this serialize piece for use in schemas
this.aliases = [...this.client.pieceStores.keys()].map(type => type.slice(0, -1));
}

async deserialize(data, piece, language) {
const store = this.client[`${piece.type}s`];
if (piece.type === 'piece') {
for (const store of this.client.pieceStores.values()) {
const pce = store.get(data);
if (pce) return pce;
}
throw language.get('RESOLVER_INVALID_PIECE', piece.key, piece.type);
}
const store = this.client.pieceStores.get(`${piece.type}s`);
if (!store) throw language.get('RESOLVER_INVALID_STORE', piece.type);
const parsed = typeof data === 'string' ? store.get(data) : data;
if (parsed && parsed instanceof store.holds) return parsed;
throw language.get('RESOLVER_INVALID_PIECE', piece.key, piece.type);
Expand Down