Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Actually add config :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wykerd committed Jul 8, 2020
1 parent 338feca commit 07e0835
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
50 changes: 47 additions & 3 deletions src/handlers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,60 @@ import { client } from '../client';
* @param {*} args
*/
export const ConfigHandler = async (message, args) => {
const config = message._server_doc;
if (!config) throw Error('\n**Bazcal Server Config Manager**\nNo existing config found.');
switch (args[0]) {
case 'delete':
const config = await Config.findOne({ server_id: message.guild.id });
if (!config) throw Error('\n**Bazcal Server Config Manager**\nNo existing config found.');
const channel = client.guilds.cache.get(config.server_id)?.channels?.cache?.get(config.category_id);
await channel?.delete();
await config.remove();
await message.channel.send('Deleted existing config.');
return;

case 'help':
await message.channel.send('**Bazcal Server Config Manager**\n\n\`fix\` recreate the _Bazcal_ category when getting \`parent_id doesnt exist\` error.\n\n\`advise\` Customize the default parameters for Bazcal\'s advise command. Params: <timeframe> <include_stability>\n\n\`bscript\` Configure BScript for your server (limited at the moment). Params: <allow_current_channel>\n\n\`results\` Set the amount of results to return when using `!bz notif\` or \`!bz advise\`. Params: <results>')
return;

case 'advise':
const [ _, timeframe, include_stability ] = args;
let tf = parseInt(timeframe ?? 15);
if (Number.isNaN(tf)) tf = 15;
const is = include_stability === 'true';
config.advice_defaults.timeframe = tf;
config.advice_defaults.include_stability = is;
await config.save();
await message.channel.send('**Bazcal Server Config Manager**\n\nUpdated config!');
return;

case 'fix':
const category = await message.guild.channels.create(`Bazcal`, {
type: 'category'
});
const category_id = category.id;
config.category_id = category_id;
await config.save();
await message.channel.send('**Bazcal Server Config Manager**\n\nDone!');
return;

case 'bscript':
config.bscipt.force_channel_messages = args[1] === 'true';
await config.save();
await message.channel.send('**Bazcal Server Config Manager**\n\nUpdated config!');
return;

case 'results':
const [ _2, results ] = args;
let res = parseInt(results ?? 6);
if (Number.isNaN(res)) res = 6;
await config.save();
if ((res < 1) || (res > 10)) {
throw new Error('\n\n**Bazcal Server Config Manager**\n\nResults returned must be between 1 and 10');
}
config.results = res;
await config.save();
await message.channel.send('**Bazcal Server Config Manager**\n\nUpdated config!');
return;

default:
break;
}
Expand All @@ -56,7 +100,7 @@ export const ConfigGenerator = async (message, args) => {
server_id: message.guild.id
});
await new_config.save();
await message.channel.send('**Bazcal Server Config Manager**\nGenerated default config. Use `!bz config help` for help on configuring the server\n```yaml\n'+YAML.stringify(new_config)+'```');
await message.channel.send('**Bazcal Server Config Manager**\nGenerated default config. Use `!bz config help` for help on configuring the server');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/notif.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function TradeConverseAdapter (message, entities, nlp_res) {

if (nums.length === 0) throw new Error('I couldn\'t find any balance referenced in your message...');

if (message.guild) message.channel.send(`<@${message.author.id}> ${nlp_res?.answer || 'Check your DMs'}`)
if (message.guild) message.channel.send(`<@${message.author.id}> ${nlp_res?.answer || 'Check your channel'}`)

return handler(message, nums.map(num => num.resolution?.value ?? 0));
}
Expand All @@ -174,7 +174,7 @@ function advice_message(sorted_input) {
final_message += `Invested: **${formatNumber(sorted_input[item].invested)}** _(${sorted_input[item].pinvested}%)_\n`
final_message += `Minimum Profit: **${formatNumber(sorted_input[item].eprofit.toFixed(2))}** _(${sorted_input[item].pprofit}%)_\n\n`
}
return final_message;
return final_message.trim();
}

export default handler
Expand Down
2 changes: 1 addition & 1 deletion src/models/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const configSchema = new mongoose.Schema({
},
instruction: {
type: String,
default: '{{user}} Check your DMs'
default: '{{user}} Check your channel'
},
pending: {
type: String,
Expand Down

0 comments on commit 07e0835

Please sign in to comment.