Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.on('message', pMessage => {
- if (executable(pMessage.content) == true) {
- execute(pMessage.content, pMessage.channel).then(sResult => { pMessage.channel.send(sResult) });
- }
- });
- async function execute(sMessage, pChannel = null) {
- // strip off the initial ! that marks the message as a command; whatever comes immediately afterwards is the command
- let args = sMessage.substring(1).trim().split(/ +/g);
- let cmd = args[0];
- // don't include the command itself among the rest of the arguments passed to it
- args = args.splice(1);
- // resolve nested commands first if they exist
- let sInnerCom = ""; // nested command input
- let sInnerComResult = ""; // nested command output
- if ((args.includes("[") == true) && (args.includes("]") == true)) { // consider anything in [ ] a nested command
- let iStart = args.indexOf("[");
- let iEnd = args.lastIndexOf("]");
- sInnerCom = args.slice(iStart+1,iEnd).join(" ");
- if (executable(sInnerCom) == true) {
- let pInnerPromise = await execute(sInnerCom, pChannel);
- pInnerPromise.then(result => { sInnerComResult = result });
- }
- // take all the elements of args that were used to encode the nested command
- // and replace them with the output we just got from that command
- // so any subsequent commands drawing from args will use it as an input string
- let throwaway = args.splice(iStart, iEnd-iStart+1, sInnerComResult);
- }
- let sComResult = "";
- switch(cmd){
- ...
- case "aut":
- if (args.length < 1) {
- // input string that should be in args actually isn't, so grab the content of the 2nd most recent message instead
- pMessages = await pChannel.fetchMessages({ limit: 2 });
- sComResult = com_aut([pMessages.last().content]);
- });
- } else {
- // input string is present in args, so just use that
- sComResult = com_aut(args);
- }
- break;
- }
- return sComResult;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement