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

Commit

Permalink
Added help and re-enabled other commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Wykerd committed Jun 20, 2020
1 parent a8768b2 commit be05451
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
4 changes: 3 additions & 1 deletion BScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Variables can be assigned a value with an `=` operator, other operator support m

## Expressions

Everything in BScript is expressions.
Everything in BScript is expressions. Expressions are seperated by semi colons.

## Sequences

Expand Down Expand Up @@ -93,6 +93,8 @@ Escape characters available:

**Note** The current interpreter doen't suport defining negative numbers so to do this you must use this hack for now `0-2` to get negative number, in this case `-2`

**Note** Order of operations doesn't work currently! Please use brackets to indciate order of operations.

# Builtins

## Global variables
Expand Down
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ const bot = new DiscordBot(parser, client)

bot.use(['advanced', 'custom'], AdvancedHandler, ['string']);

// bot.use(['notif', 'notify'], TradeHandler, [amount => /\d[A-z]/.test(amount) ? convertNumber(amount) : parseFloat(amount)])
bot.use(['notif', 'notify'], TradeHandler, [amount => /\d[A-z]/.test(amount) ? convertNumber(amount) : parseFloat(amount)])

// bot.use(['advise', 'advice'], AdviseHandler, [amount => /\d[A-z]/.test(amount) ? convertNumber(amount) : parseFloat(amount)])
bot.use(['advise', 'advice'], AdviseHandler, [amount => /\d[A-z]/.test(amount) ? convertNumber(amount) : parseFloat(amount)])

// bot.use(['help', '?'], HelpHandler, [])
bot.use(['help', '?'], HelpHandler, [])

// bot.use(['license', 'about'], LicenseHandler, [])
bot.use(['license', 'about'], LicenseHandler, [])

// bot.use(['lookup', 'search', 'item'], LookupHandler, ['string']);
bot.use(['lookup', 'search', 'item'], LookupHandler, ['string']);

// bot.converse('bazcal.notif', TradeConverseAdapter);
bot.converse('bazcal.notif', TradeConverseAdapter);

bot.model(resolve(__dirname, './model.nlp'))

Expand Down
13 changes: 9 additions & 4 deletions src/handlers/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UserScript from '../models/scriptSchema';
import { Parser, InputStream, TokenStream, Environment } from "../../lib/index"

import { item_name, formatNumber, advise, get_user_channel, get_member, raw_advise, convertNumber } from '../utils'
import { AdvancedHelp, AdvancedPublicHelp } from './info';

/**
* Base handler for advanced messages
Expand Down Expand Up @@ -62,6 +63,8 @@ const handler = (message, args) => {
}
case 'public':
return advanced_public_commands(message, args);
case 'help':
return AdvancedHelp(message);
default:
return advanced_run_public(message, command.toLowerCase(), args);
break;
Expand All @@ -84,10 +87,10 @@ const advanced_public_commands = async (message, args) => {
case 'info':
{
if (args.length < 1) {
message.channel.send(`<@${message.author.id}>\nPublic script repository info:\n\nEstimated script count: **${await UserScript.estimatedDocumentCount()}**`);
await message.channel.send(`<@${message.author.id}>\nPublic script repository info:\n\nEstimated script count: **${await UserScript.estimatedDocumentCount()}**`);
} else {
const script_doc = await get_script();
message.channel.send(`<@${message.author.id}>\nUser id: **${script_doc.user_id}**\nScript name: **${script_doc.script_name}**\nPublic name: **${script_doc.script_public_name || 'Not available via public name'}**`);
await message.channel.send(`<@${message.author.id}>\nUser id: **${script_doc.user_id}**\nScript name: **${script_doc.script_name}**\nPublic name: **${script_doc.script_public_name || 'Not available via public name'}**`);
}
}
break;
Expand All @@ -102,9 +105,11 @@ const advanced_public_commands = async (message, args) => {
{
if (args.length < 1) throw new Error('Invalid arguments. Expected 3 or more arguments, got ' + (args.length + 1));
const script_doc = await get_script();
message.channel.send('```' + script_doc.script_raw + '```');
await message.channel.send('```' + script_doc.script_raw + '```');
}
break;
case 'help':
return AdvancedPublicHelp(message);
default:
throw new Error('Unknown command.');
break;
Expand Down Expand Up @@ -168,7 +173,7 @@ const advanced_parse = (script) => {

const advanced_parse_args = (args) => {
const args_str = args.join(" ").trim() // recreate the string of the arguments
if (args_str.indexOf('```') !== 0) throw new Error('Expected script as first argument!');
if (args_str.indexOf('```') !== 0) throw new Error('Expected \`\`\` to introduce script got ' + args_str.substr(0,3) + '!');
const [ _, script, new_args_str ] = args_str.split('```');
return [ script.trim(), new_args_str.trim().split(' ') ];
}
Expand Down
12 changes: 10 additions & 2 deletions src/handlers/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@
* @param {*} args
*/
export const HelpHandler = (message, args) => {
message.channel.send(`<@${message.author.id}> Bazcal - A Discord bot for bazaar trading.\n\nAll commands start with the \`!bz\` prefix.\n\n\`advise\` (aliasses: advice) Simple flipping command, Params: <amount> <timeframe>\n\n\`notif\` (aliasses: notify) Advanced bazaar trading. The bot tell you what to create buy orders for and notifies you when to create the sell orders for maximum profits. Params: <amount>\n\n\`license\` (aliasses: about) Sends more info regarding the bot\n\n\`lookup\` (aliasses: item, search) Returns info regarding a item. Params: <item_name>`);
return message.channel.send(`<@${message.author.id}> Bazcal - A Discord bot for bazaar trading.\n\nAll commands start with the \`!bz\` prefix.\n\n\`advise\` (aliasses: advice) Simple flipping command, Params: <amount> <timeframe>\n\n\`notif\` (aliasses: notify) Advanced bazaar trading. The bot tell you what to create buy orders for and notifies you when to create the sell orders for maximum profits. Params: <amount>\n\n\`license\` (aliasses: about) Sends more info regarding the bot\n\n\`lookup\` (aliasses: item, search) Returns info regarding a item. Params: <item_name>`);
}

export const LicenseHandler = (message, args) => {
message.channel.send(`<@${message.author.id}> Bazcal - A Discord bot for bazaar trading.\n\nCopyright Daniel Wykerd, Dirk Beukes 2020\n\n\`\`\`\nBazcal is free software: you can redistribute it and/or modify\nit under the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nBazcal is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with Bazcal. If not, see <https://www.gnu.org/licenses/>.\n\`\`\`\n**NOTE:** This software depends on other packages that may be licensed under different open source licenses.\n\nThe source is freely available on Github here: https://github.com/Wykerd/bazcal`);
return message.channel.send(`<@${message.author.id}> Bazcal - A Discord bot for bazaar trading.\n\nCopyright Daniel Wykerd, Dirk Beukes 2020\n\n\`\`\`\nBazcal is free software: you can redistribute it and/or modify\nit under the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nBazcal is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with Bazcal. If not, see <https://www.gnu.org/licenses/>.\n\`\`\`\n**NOTE:** This software depends on other packages that may be licensed under different open source licenses.\n\nThe source is freely available on Github here: https://github.com/Wykerd/bazcal`);
}

export const AdvancedHelp = (message) => {
return message.channel.send(`<@${message.author.id}> Advanced Command Help\n\n\`parse\` Check whether your code parses.\n\n\`export\` returns the parsed AST output returned by the parser [you're probably never gonna use this]\n\n\`eval\` Evaluate a script. How to use: !bz advanced eval \\\`\\\`\\\`# your script\\\`\\\`\\\` <arguments>\n\n\`delete\` Delete one of your saved scripts. Params: <script_name>\n\n\`save\` Save a script to the public repository. How to use: !bz advanced save <name> \\\`\\\`\\\`# your script\\\`\\\`\\\`\n\n\`run\` Run one of your saved scripts. Params: <name> <arguments>\n\n\`set_name\` Set a public name so that anyone can use your script easily. Params <script_name> <public_name>\n\n\`public\` Access the public repository. For more info run !bz advanced public help\n\nFor more information on how to write scripts using BScript visit: https://github.com/Wykerd/bazcal/blob/master/BScript.md`);
}

export const AdvancedPublicHelp = (message) => {
return message.channel.send(`<@${message.author.id}> Public Repo Commands Help\n\n\`info\` Get info of script. Params <?script_name>\n\n\`export\` returns the parsed AST output returned by the parser [you're probably never gonna use this]. Params: <script_name>\n\n\`source\` Get the source code for a script. Params: <script_name>\n\nRunning public commands: !bz advanced <public_script_name>`);
}

0 comments on commit be05451

Please sign in to comment.