switched nedb to nedb-promises (#37)
* breaking change: switched to nedb-promises * Linting * some dev dependencies * more tests * updated package version * bug fixing * changed isNaN to isString * (fix) args[0]
This commit is contained in:
@ -1,9 +1,34 @@
|
||||
//const globals = require('../globals');
|
||||
const globals = require('../globals');
|
||||
const Discord = require('discord.js');
|
||||
const db = globals.db;
|
||||
const { findMessage } = require('@dsabot/findMessage');
|
||||
const { getChant } = require('@dsabot/getChant');
|
||||
const { isEmpty } = require('@dsabot/isEmpty');
|
||||
|
||||
const { db } = require('../globals');
|
||||
|
||||
const createChantList = (Character = {}) => {
|
||||
if (!Character || !Character.hasOwnProperty('chants')) return null;
|
||||
const ChantList = [];
|
||||
Character.chants.forEach(chant =>
|
||||
ChantList.push(getChant({ Character: Character, chant_name: chant.id }))
|
||||
);
|
||||
return ChantList.filter(value => value !== undefined);
|
||||
};
|
||||
|
||||
const ReplyChantList = (ChantList = []) => {
|
||||
if (!ChantList) return null;
|
||||
return `${ChantList.map(chant => `${chant.Name} ${chant.Level ? `(${chant.Level})` : ''}`).join(
|
||||
'\n'
|
||||
)}`;
|
||||
};
|
||||
|
||||
const ReplyChant = (Chant = {}) => {
|
||||
if (!Chant) return null;
|
||||
return `Deine Werte für ${Chant.Name} ${Chant.Level ? `(${Chant.Level})` : ''} sind:
|
||||
|
||||
${Chant.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
|
||||
`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
name: 'chants',
|
||||
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Magietalent (Götterwirken).',
|
||||
@ -12,50 +37,34 @@ module.exports = {
|
||||
needs_args: false,
|
||||
|
||||
async exec(message, args) {
|
||||
db.find({ user: message.author.tag }, (err, docs) => {
|
||||
if (docs.length === 0) {
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
const Character = docs[0].character;
|
||||
if (!Character.hasOwnProperty('chants')) return message.reply(findMessage('NO_CHANTS'));
|
||||
if (args.length === 0) {
|
||||
const Embed = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(findMessage('CHANTS_TITLE'))
|
||||
.setDescription(findMessage('CHANTS_DESCRIPTION'))
|
||||
.addField(ReplyChantList(createChantList(Character)), '\u200B', true);
|
||||
return message.reply(Embed);
|
||||
}
|
||||
const Chant = getChant({
|
||||
Character: Character,
|
||||
chant_name: args[0],
|
||||
db.findOne({ user: message.author.tag })
|
||||
.then(doc => {
|
||||
if (isEmpty(doc)) {
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
const Character = doc.character;
|
||||
if (!Character.hasOwnProperty('chants'))
|
||||
return message.reply(findMessage('NO_CHANTS'));
|
||||
if (args.length === 0) {
|
||||
const Embed = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(findMessage('CHANTS_TITLE'))
|
||||
.setDescription(findMessage('CHANTS_DESCRIPTION'))
|
||||
.addField(ReplyChantList(createChantList(Character)), '\u200B', true);
|
||||
return message.reply(Embed);
|
||||
}
|
||||
const Chant = getChant({
|
||||
Character: Character,
|
||||
chant_name: args[0],
|
||||
});
|
||||
if (!Chant) {
|
||||
return message.reply(findMessage('SPELL_UNKNOWN'));
|
||||
}
|
||||
return message.reply(ReplyChant(Chant));
|
||||
})
|
||||
.catch(err => {
|
||||
message.reply(findMessage('ERROR'));
|
||||
throw new Error(err);
|
||||
});
|
||||
if (!Chant) {
|
||||
return message.reply(findMessage('SPELL_UNKNOWN'));
|
||||
}
|
||||
return message.reply(ReplyChant(Chant));
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const createChantList = (Character = {}) => {
|
||||
if (!Character || !Character.hasOwnProperty('chants')) return;
|
||||
let ChantList = [];
|
||||
|
||||
// todo: send 'chant' to getChant() so we can filter out blessings.
|
||||
Character.chants.forEach(chant => ChantList.push(getChant({ Character: Character, chant_name: chant.id })));
|
||||
return ChantList.filter(value => value !== undefined);
|
||||
};
|
||||
|
||||
const ReplyChantList = (ChantList = []) => {
|
||||
if (!ChantList) return;
|
||||
return `${ChantList.map(chant => `${chant.Name} ${chant.Level ? `(${chant.Level})` : ''}`).join('\n')}`;
|
||||
};
|
||||
|
||||
const ReplyChant = (Chant = {}) => {
|
||||
if (!Chant) return;
|
||||
return `Deine Werte für ${Chant.Name} ${Chant.Level ? '(' + Chant.Level + ')' : ''} sind:
|
||||
|
||||
${Chant.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
|
||||
`;
|
||||
};
|
||||
|
Reference in New Issue
Block a user