Search code examples
tclirceggdrop

Eggdrop TCL Artificial Intelligence in a limited time


I want Eggdrop to respond to users who have joined the channel in the last 30 minutes. All other users who have been on the channel for more than 30 minutes should be ignored.

set canalativo "#testes"

bind pubm - "*regist*canal*" pub:regchan

proc pub:regchan { nick uhost handle chan arg } {
global canalativo

if {[string match -nocase "$canalativo" $chan]} {

putserv "PRIVMSG $chan :$nick para registar um canal escreve o comando: /ChanServ register #CANAL DESCRICAO-DO-CANAL" } 
 }

Solution

  • You could hold an array containing the user and their join time. Something like (untested):

    set canalativo "#testes"
    array set joinedUsers {}
    
    bind pubm - "*regist*canal*" pub:regchan
    bind join - "*!*@*" pub:joinchan
    
    proc pub:regchan { nick uhost handle chan arg } {
        global canalativo joinedUsers
    
        # Check if - this is the correct channel
        #          - the user is in the array of joined users
        #          - the time the user joined is 1800 seconds ago or less
        if {
            [string match -nocase "$canalativo" $chan] && 
            [info exists joinedUsers($nick)] && 
            [clock seconds]-$joinedUsers($nick) <= 1800
        } {
            putserv "PRIVMSG $chan :$nick para registar um canal escreve o comando: /ChanServ register #CANAL DESCRICAO-DO-CANAL"
        }
    
        # Remove the user from the array if it is there
        catch {unset joinedUsers($nick)}
    }
    
    proc pub:joinchan { nick uhost handle chan } {
        global joinedUsers
    
        # Add the user and the time they joined to the array
        set joinedUsers($nick) [clock seconds]
    }
    

    This is just the basic. You might want to add checks for things like nick changes (maybe tell them about grouping their nicks under one account for example), or rejoins (due to disconnects/netsplits) among other things. Also you may not want the bot to tell them that if they are already registered.