better error handling, added chant command

This commit is contained in:
Marcus Netz
2021-04-28 15:50:02 +02:00
parent f5c485fdcc
commit d29e04a103
11 changed files with 228 additions and 44 deletions

View File

@ -6,7 +6,7 @@ const { findMessage } = require('@dsabot/findMessage');
const { getSpell } = require('@dsabot/getSpell');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const { CompareResults } = require('@dsabot/CompareResults');
const { CreateResultTable } = require('@dsabot/CreateResultTable');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
module.exports = {
name: 'cast',
description:
@ -15,17 +15,17 @@ module.exports = {
' die Berechnung einbezogen.',
aliases: ['zaubern'],
usage: '<Zaubern> [<-Erschwernis> / <+Erleichterung>]',
needs_args: true,
needs_args: false,
async exec(message, args) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
if (!docs[0].character.hasOwnProperty('spells'))
return message.reply(findMessage('NO_SPELLS'));
if (!isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
console.log(args[0]);
const Spell = getSpell({ Character: docs[0].character, spell_name: args[0] });
if (!Spell) {
return message.reply(findMessage('SPELL_UNKNOWN'));
@ -44,11 +44,14 @@ module.exports = {
);
const Reply = new Discord.MessageEmbed();
Reply.addFields({
name: `Du würfelst auf das Talent **${Spell.Name}** (Stufe ${Spell.Level} + ${Bonus})`,
name: `Du würfelst auf das Talent **${Spell.Name}** ( Stufe ${Spell.Level} ${
Bonus ? `${f(Bonus)} ` : ''
})`,
value: CreateResultTable({
Attributes: Attributes,
Throws: DiceThrow,
PointsUsed: PointsUsed,
Bonus: Bonus,
}),
inline: false,
});
@ -69,15 +72,17 @@ module.exports = {
} else if (Passed < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`} erfolgreich. 😪`,
value: `${
Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`
} erfolgreich. 😪`,
inline: false,
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `Dein verbleibender Bonus: ${PointsRemaining}/${Spell.Level} (QS${CalculateQuality(
PointsRemaining
)})`,
value: `Dein verbleibender Bonus: ${PointsRemaining}/${
Spell.Level
} (QS${CalculateQuality(PointsRemaining)})`,
inline: false,
});
}

93
commands/Chant.js Normal file
View File

@ -0,0 +1,93 @@
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { roll } = require('@dsabot/Roll');
const { findMessage } = require('@dsabot/findMessage');
const { getChant } = require('@dsabot/getChant');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const { CompareResults } = require('@dsabot/CompareResults');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
module.exports = {
name: 'chant',
description:
' Du machst eine Fertigkeitsprobe auf Magietalente.\n' +
' Es werden drei Würfel auf deine Eigenschaftswerte geworfen. Deine Boni werden in' +
' die Berechnung einbezogen.',
aliases: [''],
usage: '<Liturgie/Zeremonie> [<-Erschwernis> / <+Erleichterung>]',
needs_args: false,
async exec(message, args) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
if (!docs[0].character.hasOwnProperty('chants'))
return message.reply(findMessage('NO_CHANTS'));
if (!isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
const Chant = getSpell({ Character: docs[0].character, chant_name: args[0] });
if (!Chant) {
return message.reply(findMessage('CHANT_UNKNOWN'));
}
if (!Chant.Level || !Chant.Attributes) {
return;
}
const Attributes = Chant.Attributes;
const DiceThrow = roll(3, 20, message.author.tag).dice;
const Bonus = parseInt(args[1]) || 0;
let { Passed, CriticalHit, Fumbles, PointsUsed, PointsRemaining } = CompareResults(
DiceThrow,
Attributes.map(attr => attr.Level),
Bonus,
Chant.Level
);
const Reply = new Discord.MessageEmbed();
Reply.addFields({
name: `Du würfelst auf das Talent **${Chant.Name}** ( Stufe ${Chant.Level} ${
Bonus ? `${f(Bonus)} ` : ''
})`,
value: CreateResultTable({
Attributes: Attributes,
Throws: DiceThrow,
PointsUsed: PointsUsed,
Bonus: Bonus,
}),
inline: false,
});
if (Fumbles >= 2) {
Reply.setColor('#900c3f');
Reply.addFields({
name: findMessage('TITLE_CRIT_FAILURE'),
value: findMessage('MSG_CRIT_FAILURE'),
inline: false,
});
} else if (CriticalHit >= 2) {
Reply.setColor('#1E8449');
Reply.addFields({
name: findMessage('TITLE_CRIT_SUCCESS'),
value: findMessage('MSG_CRIT_SUCCESS'),
inline: false,
});
} else if (Passed < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${
Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`
} erfolgreich. 😪`,
inline: false,
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `Dein verbleibender Bonus: ${PointsRemaining}/${
Chant.Level
} (QS${CalculateQuality(PointsRemaining)})`,
inline: false,
});
}
message.reply(Reply);
});
},
};

View File

@ -6,9 +6,9 @@ const { getChant } = require('@dsabot/getChant');
module.exports = {
name: 'chants',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Magietalent (Götterwirken).',
aliases: ['chant', 'segen', 'liturgie'],
usage: '<Zauber>',
needs_args: true,
aliases: ['segen', 'liturgie', 'liturgien', 'zeremonien'],
usage: '[<Liturgie / Zeremonie>]',
needs_args: false,
async exec(message, args) {
console.log(message.author.tag);
@ -17,6 +17,7 @@ module.exports = {
return message.reply(findMessage('NOENTRY'));
}
Character = docs[0].character;
if (!Character.hasOwnProperty('chants')) return message.reply(findMessage('NO_CHANTS'));
if (args.length === 0) {
return message.reply(ReplyChantList(createChantList(Character))); //?+
}
@ -37,18 +38,22 @@ const createChantList = (Character = {}) => {
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 })));
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')}`;
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:
return `Deine Werte für ${Chant.Name} ${Chant.Level ? '(' + Chant.Level + ')' : ''} sind:
${Chant.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
`;

View File

@ -16,6 +16,7 @@ module.exports = {
return message.reply(findMessage('NOENTRY'));
}
Character = docs[0].character;
if (!Character.hasOwnProperty('spells')) return message.reply(findMessage('NO_SPELLS'));
if (args.length === 0) {
return message.reply(ReplySpellList(createSpellList(Character)));
}
@ -45,7 +46,9 @@ const ReplySpell = (Spell = {}) => {
const createSpellList = (Character = {}) => {
if (!Character || !Character.hasOwnProperty('spells')) return;
let SpellList = [];
Character.spells.forEach(spell => SpellList.push(getSpell({ Character: Character, spell_name: spell.id })));
Character.spells.forEach(spell =>
SpellList.push(getSpell({ Character: Character, spell_name: spell.id }))
);
return SpellList.filter(value => value !== undefined); //?+
};
/*