eliza icon indicating copy to clipboard operation
eliza copied to clipboard

way for bots to have cool down periods (dynamic tempature adjusts) & only direct reply setting

Open o-on-x opened this issue 1 year ago • 0 comments

to add for for .env

#DISCORD | only respond when @ | cooldown on reply in MS
DISCORD_DIRECT_ONLY=true #true
DISCORD_COOLDOWN=0 #default 1 min (only applies when not direct @)

to add for messages.ts discord

async handleMessage(message: DiscordMessage) {
        if (
            message.interaction ||
            message.author.id ===
                this.client.user?.id /* || message.author?.bot*/
        )
            return;
    //only respond too direct @ or replys
    const isDirectMention = message.mentions.has(this.client.user?.id);
    const isReplyToBot = message.reference?.messageId && (
        await message.channel.messages.fetch(message.reference.messageId)
    ).author.id === this.client.user?.id;
    const isDirectInteraction = isDirectMention || isReplyToBot;
    if (settings.DISCORD_DIRECT_ONLY && !isDirectInteraction) {
        console.log("Direct-only mode: ignoring non-mention message");
        return;
    }
        if (isReplyToBot) {
        console.log("Reply to bot detected");
    }

    // Only apply cooldown check for non-direct mentions
    if (!isDirectInteraction) {
        const timeSinceLastResponse = Date.now() - this.lastResponseTime;
        
        if (timeSinceLastResponse < this.COOLDOWN_MS) {
            console.log(`Cooling down for non-direct messages. Time remaining: ${(this.COOLDOWN_MS - timeSinceLastResponse)/1000}s`);
            return;
        }
        
    } else {
        console.log("Direct mention detected - bypassing cooldown");
    }

.....
                await this.runtime.processActions(
                    memory,
                    responseMessages,
                    state,
                    callback
                );
                this.lastResponseTime = Date.now(); 
                
            }

o-on-x avatar Nov 18 '24 12:11 o-on-x