merge dev branch (more tests) (#47)

* more tests and bugfixes on spells

* linting
This commit is contained in:
2021-05-06 21:35:58 +02:00
committed by GitHub
parent 25ad8ad160
commit ba63be64dd
12 changed files with 219 additions and 45 deletions

View File

@ -1,5 +1,3 @@
const Capitalize = (Word = 'none') => {
return Word[0].toUpperCase() + Word.substring(1);
};
const Capitalize = (Word = 'none') => `${Word[0].toUpperCase() + Word.substring(1)}`;
module.exports = { Capitalize };

View File

@ -1,5 +1,3 @@
const CountOccurences = (arr, value) => {
return arr.filter(v => v === value).length;
};
const CountOccurences = (arr, value) => arr.filter(v => v === value).length;
module.exports = { CountOccurences };

View File

@ -7,22 +7,20 @@ const CreateResultTable = ({
Throws: Throws,
PointsUsed: PointsUsed,
Bonus: Bonus = 0,
}) => {
return `
}) => `
\`\`\`
${''.padEnd(15)} ${Attributes.map(attr => `${attr.Name}`.padStart(6)).join('\t|\t')}\t|
${'Dein Wert'.padEnd(15)} ${Attributes.map(attr =>
`${attr.Level}${Bonus ? `(${f(Bonus)})` : ``}`.padStart(6)
).join('\t|\t')}\t|
`${attr.Level}${Bonus ? `(${f(Bonus)})` : ``}`.padStart(6)
).join('\t|\t')}\t|
${'Dein Wurf'.padEnd(15)} ${Throws.map(Throw => `${Throw}`.padStart(6)).join('\t|\t')}\t|
${'Abzüge'.padEnd(15)} ${PointsUsed.map(Points => `${Points}`.replace(0, '--').padStart(6)).join(
'\t|\t'
)}\t|
'\t|\t'
)}\t|
${'Gesamt'.padEnd(15)} ${PointsUsed.reduce((acc, cur) => acc + cur)
.toString()
.padStart(6)}
.toString()
.padStart(6)}
\`\`\`
`;
};
module.exports = { CreateResultTable, f };

View File

@ -1,7 +1,5 @@
const { Replies } = require('../globals');
const findMessage = value => {
return Replies.find(r => r.id === value).string;
};
const findMessage = value => Replies.find(r => r.id === value).string;
module.exports = { findMessage };

View File

@ -1,30 +1,21 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Spells = require('@Lib/Spells.json');
const { isEmpty } = require('@dsabot/isEmpty');
const getSpell = ({ Character: Character = [], spell_name: spellName = '' } = {}) => {
if (!Character.hasOwnProperty('spells')) return null;
const spellEntry =
Spells.find(spell => spell.id.toLowerCase() === spellName.toLowerCase()) ||
Spells.find(spell => spell.name.toLowerCase() === spellName.toLowerCase());
if (!spellEntry) {
console.log(`getSpell() did not find entry for ${spellName}`);
return null;
}
if (isEmpty(spellEntry)) return null;
const Spell = Character.spells.find(spell => spell.id === spellEntry.id); //?+
const Level = Spell.hasOwnProperty('level') ? Spell.level : 0;
let Level = 0; // This is the minimum attributes value.
if (!Character.hasOwnProperty('spells')) return null;
const Spell = Character.spells.find(spell => spell.id === spellEntry.id) || null; //?+
if (Spell && Spell.hasOwnProperty('level')) {
Level = Spell.level || 0;
}
const ModifiedBy = spellEntry.modified_by;
const Attributes = getAttributeLevels(spellEntry.attributes, Character);
return {
Name: spellEntry.name,
Level: Level,
Attributes: Attributes,
ModifiedBy: ModifiedBy,
};
return { Name: spellEntry.name, Level: Level, Attributes: Attributes, ModifiedBy: ModifiedBy };
};
module.exports = { getSpell };