Files
dsabot/functions/getSkill.js
TobenderZephyr c6cacdae5e 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]
2021-05-03 18:39:33 +02:00

28 lines
912 B
JavaScript

const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const { Talente } = require('../globals');
const getSkill = ({ Character: Character = [], args: args = [] } = {}) => {
const skillEntry =
Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
if (!skillEntry) {
return null;
}
let Level = 0; // This is the minimum attributes value.
const cSkill = Character.skills.find(skill => skill.id === skillEntry.id) || null;
if (cSkill) {
Level = cSkill.level || 0;
}
const Name = Talente.find(skill => skill.id === skillEntry.id).name;
const Attributes = getAttributeLevels(skillEntry.values, Character);
return {
Name: Name,
Level: Level,
Attributes: Attributes,
};
};
module.exports = { getSkill };