(fix) Attributes command did not work after refactoring
This commit is contained in:
@ -1,10 +1,6 @@
|
|||||||
const globals = require('../globals');
|
const globals = require('../globals');
|
||||||
const {
|
const { CountOccurences } = require('@dsabot/CountOccurences');
|
||||||
CountOccurences
|
const { findMessage } = require('@dsabot/findMessage');
|
||||||
} = require('@dsabot/CountOccurences');
|
|
||||||
const {
|
|
||||||
findMessage
|
|
||||||
} = require('@dsabot/findMessage');
|
|
||||||
const Random = require('random');
|
const Random = require('random');
|
||||||
const db = globals.db;
|
const db = globals.db;
|
||||||
|
|
||||||
@ -16,18 +12,23 @@ module.exports = {
|
|||||||
needs_args: true,
|
needs_args: true,
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
try {
|
try {
|
||||||
let level = 8;
|
let Attribute;
|
||||||
let attributename;
|
let AttributeName;
|
||||||
|
let Level = 8;
|
||||||
await db.find({
|
await db.find({
|
||||||
user: message.author.tag,
|
user: message.author.tag,
|
||||||
}, async function (err, docs) {
|
}, async (err, docs) => {
|
||||||
|
|
||||||
// user calls with text. need to gather info from database
|
// user calls with text, let's look him up in the database.
|
||||||
if (isNaN(args[0])) {
|
if (isNaN(args[0])) {
|
||||||
HandleNamedAttributes();
|
Attribute = HandleNamedAttributes({
|
||||||
|
Character: docs[0].character,
|
||||||
|
args: args
|
||||||
|
});
|
||||||
|
AttributeName = Attribute.Name;
|
||||||
|
Level = Attribute.Level;
|
||||||
} else {
|
} else {
|
||||||
level = args[0];
|
Level = args[0];
|
||||||
}
|
}
|
||||||
Random.use(message.author.tag);
|
Random.use(message.author.tag);
|
||||||
|
|
||||||
@ -44,19 +45,19 @@ module.exports = {
|
|||||||
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
|
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((dice.length == 2 && dice[0] != 20 && dice[1] <= level) || (dice.length == 1 && dice[0] <= level)) {
|
if ((dice.length == 2 && dice[0] != 20 && dice[1] <= Level) || (dice.length == 1 && dice[0] <= Level)) {
|
||||||
if (attributename) {
|
if (AttributeName) {
|
||||||
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' +
|
message.reply('Du hast die Probe auf ' + AttributeName + ' (Stufe ' + Level + ') bestanden.\n' +
|
||||||
'Deine 🎲: ' + dice.join(', '));
|
'Deine 🎲: ' + dice.join(', '));
|
||||||
} else {
|
} else {
|
||||||
message.reply('Du hast die Probe (Stufe ' + level + ') bestanden.\n' +
|
message.reply('Du hast die Probe (Stufe ' + Level + ') bestanden.\n' +
|
||||||
'Deine 🎲: ' + dice.join(', '));
|
'Deine 🎲: ' + dice.join(', '));
|
||||||
}
|
}
|
||||||
} else if (attributename) {
|
} else if (AttributeName) {
|
||||||
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
message.reply('Du hast die Probe auf ' + AttributeName + ' (Stufe ' + Level + ') leider nicht bestanden 😢.\n' +
|
||||||
'Deine 🎲: ' + dice.join(', '));
|
'Deine 🎲: ' + dice.join(', '));
|
||||||
} else {
|
} else {
|
||||||
message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
message.reply('Du hast die Probe (Stufe ' + Level + ') leider nicht bestanden 😢.\n' +
|
||||||
'Deine 🎲: ' + dice.join(', '));
|
'Deine 🎲: ' + dice.join(', '));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -70,25 +71,26 @@ const HandleCrits = (dice) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const HandleNamedAttributes = () => {
|
const HandleNamedAttributes = ({Character: Character = [], args: args = []} = {}) => {
|
||||||
if (docs.length === 0) {
|
|
||||||
message.reply(findMessage('NOENTRY'));
|
let Attributes = globals.Werte;
|
||||||
return;
|
let Level = 8; // This is the minimum attributes value.
|
||||||
|
let AttributeName;
|
||||||
|
let AttributeId;
|
||||||
|
|
||||||
|
if (args[0].length == 2) {
|
||||||
|
AttributeId = Attributes.find(attribute => attribute.kuerzel === args[0].toUpperCase()).id;
|
||||||
} else {
|
} else {
|
||||||
// try to get id of short formatted attributes.
|
AttributeId = args[0].toLowerCase() ||
|
||||||
if (args[0].length == 2) {
|
Attributes.find(attribute => attribute.name.toLowerCase() === args[0].toLowerCase()).id;
|
||||||
for (const i in globals.Werte) {
|
|
||||||
if (globals.Werte[i].kuerzel == args[0].toUpperCase()) {
|
|
||||||
attributename = globals.Werte[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
attributename = args[0].toLowerCase();
|
|
||||||
}
|
|
||||||
for (const i in docs[0].character.attributes) {
|
|
||||||
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
//const docs = [];
|
Level = Character.attributes.find(attribute => attribute.id === AttributeId).level;
|
||||||
//console.log(HandleNamedAttributes())
|
AttributeName = Attributes.find(attribute => attribute.id === AttributeId).name;
|
||||||
|
|
||||||
|
return {
|
||||||
|
Name: AttributeName,
|
||||||
|
Level: Level
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
Reference in New Issue
Block a user