PhantomBot / PhantomBot

PhantomBot is an actively developed open source interactive Twitch bot with a vibrant community that provides entertainment and moderation for your channel, allowing you to focus on what matters the most to you - your game and your viewers.
https://phantombot.dev
GNU General Public License v3.0
784 stars 339 forks source link

[Feature Request] $.delaySay([message],[delay]); to create more natural responses to chat #3144

Open abraxas86 opened 1 year ago

abraxas86 commented 1 year ago

This one isn't super important. The idea is to delay a response back to a user/bot to make it feel a bit more like natural conversation.

My use case is for when I have my bot (intentionally) make requests from another bot that don't exist, then have it clap back and make fun of the other bot (or me) for not having what it requests. I'm sure other people could have use cases for something like this as well.

I have it in my script as its own function, but I think for the sake of flow, it would look more natural if it had its own $. style to use.

Here's how I have it in my code:

    function delaySay(message, delay)
    {
        // if command is triggered w/o delay, set delay to 1 second
        if (delay === undefined) { delay = 1000; } 
        var timedSay = function() {$.say(message);}
        setTimeout(timedSay, delay);
    }
abraxas86 commented 1 year ago

I have no idea how to submit this stuff properly, sorry.

I was wondering if the ./scripts/core/misc.js file's function say(message) could be updated to the following:

    /**
     * @function say
     * @export $
     * @param {string} message, {integer} delay
     */
    function say(message,delay) {

        var sendMessage = false;

        if (message === undefined || message === null) {
            return;
        }
        //delay function
        if (delay === undefined || delay === null){
            delay = 0;
        }
        message = $.jsString(message);
        if (message.trim().length === 0 || reg.test(message)) {
            return;
        }

        if (respond && !action) {
            sendMessage = true;
        } else {
            if (respond && action) {
                // If the message is a Twitch command, remove the /me.
                if (message.startsWith('.') || message.startsWith('/')) {
                    sendMessage = true;
                } else {
                    sendMessage = true;
                    message = '/me' + message;
                }
            }
            if (!respond) {
                $.consoleLn('[MUTED] ' + message);
                $.log.file('chat', '[MUTED] ' + $.botName.toLowerCase() + ': ' + message);
                return;
            }
        }

        if (sendMessage === true){
            var sendMsg = function() { Packages.tv.phantombot.PhantomBot.instance().getSession().say(message); }
            setTimeout(sendMsg,delay);
        }

        $.log.file('chat', '' + $.botName.toLowerCase() + ': ' + message);
    }

Changes:

I have updated my own file with the above code, and gave it some testing... it seems to be working exactly as planned... just needs a better set of eyes to make sure the code is okay, and the overall approval from the team to roll it in I guess.