Open abraxas86 opened 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:
Packages.tv.phantombot.[..].say(message);
One line added "/me" to the start. I created a new Boolean variable to check whether we should send the message, and replaced the one line to set message
to 'me ' + message
Added an integer parameter called "Delay" that is the time (in ms) that it should wait to send the line into the Twitch chat. If no delay
value is given, it will default to 0 (the typical instant response).
I (attempted) to change the commented help above the function to include the 2nd param, but I'm not sure if I did that part correctly.
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.
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: