(writefile) usable in chat



  • Hello,
    I’m attempting to create a currency redemption system in Phantombot and need (writefile) to be usable in chat. I’ve modified customCommand.js from:

    if (message.match(/\(writefile .+\)/)) {
                if (message.match(/\(writefile (.+), (.+), (.+)\)/)) {
                    var file = message.match(/\(writefile (.+), (.+), (.+)\)/)[1],
                        append = (message.match(/\(writefile (.+), (.+), (.+)\)/)[2] == 'true' ? true : false),
                        string = message.match(/\(writefile (.+), (.+), (.+)\)/)[3];
                    $.writeToFile(string, './addons/' + file, append);
                }
                return null;
            }
    

    to:

    if (message.match(/\(writefile .+\)/)) {
                if (message.match(/\(writefile (.+), (.+), (.+)\)/)) {
                    var file = message.match(/\(writefile (.+), (.+), (.+)\)/)[1],
                        append = (message.match(/\(writefile (.+), (.+), (.+)\)/)[2] == 'true' ? true : false),
                        string = message.match(/\(writefile (.+), (.+), (.+)\)/)[3];
                    $.writeToFile(string, './addons/' + file, append);
                }
                message = $.replace(message, message.match(/\(writefile .+\)/)[0], '');
            }
    

    Everything appears to be working as intended BUT I am not a coder and wanted to ask here if I’m missing anything or would be creating any issues with this line change.

    Thanks for all help/pointers and thanks for the wonderful Phantombot!


  • Bot Developer

    @Iron_Pipe Hey, I would take a look at the main repo, I already implemented this for our next release. ;)

    https://github.com/PhantomBot/PhantomBot/blob/master/javascript-source/commands/customCommands.js#L328



  • Thanks! Now I know how to do it in a robust way. I’ll be sure to check github first the next time.


Log in to reply
 

Looks like your connection to PhantomBot Community Forums was lost, please wait while we try to reconnect.