This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

A script for a bot support

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

A script for a bot support

Post by neoclust »

I have a bot to support it's role is to replace Bot1 & bot2 when they disconnect or they are not @, and he must deop when he sees that one of the two bots oped,
If you can help me solve this theory, thank you.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I have done a limited amount of checking on the following script and it seems fine:-

Code: Select all

# support.tcl

# if none of the preconfigured bots is op in a preconfigured channel then the bot ..
# .. that this script is loaded on will attempt to op itself in the channel ..
# .. through chanserv services (if it is not already op'd)

# if one or more of the preconfigured bots is op in a preconfigured channel then ..
# .. the bot that this script is loaded on will will attempt to deop itself in ..
# .. the channel through chanserv services (if it is not already deop'd)

# requires a restart (not rehash) due to use of init-server evnt bind

# reacts to join/part/quit/split/kick plus +o/-o mode changes and additionally has a ..
# .. preconfigured scheduled check for all the preconfigured channels

# for the op command to succeed, the bot that this script is loaded on must be on ..
# .. the channel access list

### ------------------------------------------------------------- ###
### ---------- CONFIGURATION ------------------------------------ ###

# set here a list of the channels to add support services to
set vSupportChannels {
    "#eggtcl"
    "#atlantis"
    "#tcl"
}

# set here a list of other bots that the script is supporting
set vSupportBots {
    "Baal"
    "McKay"
}

# set here the address of services to op or deop
set vSupportServices "chanserv@services.dal.net"

# set here the frequency of the additional checking in minutes
set vSupportTimerFrequency 2

### ------------------------------------------------------------- ###
### ---------- CODE --------------------------------------------- ###

set vSupportVersion 1.0

bind EVNT - init-server pSupportTimerStart

bind PART - * pSupportPartCode
bind SIGN - * pSupportSignCode
bind KICK - * pSupportKickCode
bind SPLT - * pSupportSpltCode
bind JOIN - * pSupportJoinCode

bind MODE - "#% +o" pSupportModeCode
bind MODE - "#% -o" pSupportModeCode

proc pSupportCheck {nick chan} {
    global vSupportBots vSupportChannels
    set botstolower [split [string tolower [join $vSupportBots]]]
    set chanstolower [split [string tolower [join $vSupportChannels]]]
    if {[lsearch -exact $botstolower [string tolower $nick]] != -1} {
        if {[lsearch -exact $chanstolower [string tolower $chan]] != -1} {
            return 1
        }
    }
    return 0
}

proc pSupportModeCode {nick uhost hand chan change target} {
    if {[pSupportCheck $target $chan]} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportJoinCode {nick uhost hand chan} {
    if {([pSupportCheck $nick $chan]) || ([isbotnick $nick])} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportSpltCode {nick uhost hand chan} {
    if {[pSupportCheck $nick $chan]} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportKickCode {nick uhost hand chan target reason} {
    if {[pSupportCheck $target $chan]} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportSignCode {nick uhost hand chan reason} {
    if {[pSupportCheck $nick $chan]} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportPartCode {nick uhost hand chan msg} {
    if {[pSupportCheck $nick $chan]} {
        utimer 10 [list pSupportOpCode $chan]
    }
    return 0
}

proc pSupportTimerStart {type} {
    global vSupportTimerFrequency
    if {[string is integer -strict $vSupportTimerFrequency]} {
        if {$vSupportTimerFrequency > 0} {
            pSupportTimerSchedule
        }
    }
    return 0
}

proc pSupportTimerSchedule {} {
    global vSupportTimerFrequency
    foreach schedule [binds TIME] {
        if {[string equal pSupportTimerCode [join [lindex $schedule 4]]]} {
            set minute [join [lindex [lindex $schedule 2] 0]]
            set hour [join [lindex [lindex $schedule 2] 1]]
            unbind TIME - "$minute $hour * * *" pSupportTimerCode
        }
    }
    set minute [strftime %M [expr {[unixtime] + ($vSupportTimerFrequency * 60)}]]
    set hour [strftime %H [expr {[unixtime] + ($vSupportTimerFrequency * 60)}]]
    bind TIME - "$minute $hour * * *" pSupportTimerCode
    return 0
}

proc pSupportTimerCode {minute hour day month year} {
    global vSupportBots vSupportChannels
    if {([llength $vSupportBots] != 0) && ([llength $vSupportChannels] != 0)} {
        pSupportOpCode 0
    }
    return 0
}

proc pSupportOpCode {chan} {
    global botnick vSupportBots vSupportChannels vSupportServices
    switch -- $chan {
        0 {
            foreach channel $vSupportChannels {
                set oped 0
                if {[validchan $channel]} {
                    if {[botonchan $channel]} {
                        foreach bot $vSupportBots {
                            if {[onchan $bot $channel]} {
                                if {[isop $bot $channel]} {
                                    incr oped
                                }
                            }
                        }
                        switch -- $oped {
                            0 {
                                if {![botisop $channel]} {
                                    putserv "PRIVMSG $vSupportServices :OP $channel $botnick"
                                }
                            }
                            default {
                                if {[botisop $channel]} {
                                    putserv "PRIVMSG $vSupportServices :DEOP $channel $botnick"
                                }
                            }
                        }
                    }
                }
            }
            pSupportTimerSchedule
        }
        default {
            set oped 0
            if {[validchan $chan]} {
                if {[botonchan $chan]} {
                    foreach bot $vSupportBots {
                        if {[onchan $bot $chan]} {
                            if {[isop $bot $chan]} {
                                incr oped
                            }
                        }
                    }
                }
            }
            switch -- $oped {
                0 {
                    if {![botisop $chan]} {
                        putserv "PRIVMSG $vSupportServices :OP $chan $botnick"
                    }
                }
                default {
                    if {[botisop $chan]} {
                        putserv "PRIVMSG $vSupportServices :DEOP $chan $botnick"
                    }
                }
            }
        }
    }
    return 0
}

putlog "support.tcl version $vSupportVersion by arfer loaded"

# eof
I must have had nothing to do
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

Thanks a lot man good script, and if i want change the nick to host of bots it will be effective since their addresses are fixed, Ex *!*@blah.com i replace the $nick of uhost and setting
set vSupportBots {
"*!*@blah.com"
}
right ?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I don't think you can reliably do that with the script as it stands.

Some binds return the nick/uhost of the user they effect and can be used directly. Other binds return the nick/uhost that did the action and seperately return the target of the action (but not the uhost of the target).

Hence you see some of my bind procs use nick whilst others use target.
I must have had nothing to do
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

I use this script on Undernet where nicknames does not register it so there's that someone else takes, is why i referred to the host that the script is much more reliable, I could get rid of BIND kick and MODE as they use target
Post Reply