TIA
Code: Select all
###############################################################################################
#namespace Solobot
#Checks for availability of bot's user's (on bot userlist with with appropriate channel flags
#set) in IRC channels
#scans channels for user availability using "WHOIS" command, adds '+A' flag to user attr if away
#If all users in chan's list are away, bot is solo in channel and adds '+S' flag to channel
#If channel is +S bot is to explain no live help currently available and offer limited help to
#guests joining channel i.e. access to bot's #help files, links to help sites etc.
# TODO add binds and handlers for channel join events
################################################################################################
#system setup for namespace
bind dcc - "startsolo" Solobot::Execute
bind dcc - "stopsolo" Solobot::Stop
bind dcc - "nosolo" Solobot::Destroy
bind raw - "301" Solobot::Whoisreply
bind raw - "318" Solobot::Whoisreply
setudef flag A
setudef flag S
namespace eval Solobot {
namespace export Execute Stop Destroy
variable bypass 0
variable timerid
variable firstpass 1
#####################################################################################
#scan channels list
#check for available users in each channel
#set timer to rescan
#####################################################################################
proc Execute {args} {
variable firstpass
variable timerid
#first pass through channels
if {$firstpass} {
variable firstpass 0
foreach chan [::channels] {
putlog "$::botnick beginning watch $chan [strftime "\[%H:%M:%S\]\(%a.\)%D"]"
}
}
#scan channels
foreach chan [::channels] {
putlog "$chan"
#scan channel user list
foreach user [::chanlist $chan n|m|l ] {
putquick "Whois $user"
}
#check for availability
Chkaides $chan
}
#kill timer if it exists
if { [set timr [timerexists timerid]] != "" } {
putlog "$timerid killed"
killutimer $timerid
}
# set new timer to rescan
set timerid [utimer 20 Solobot::Execute]
return 0
}
#####################################################################################
#stop channel scan
#####################################################################################
proc Stop {args} {
variable timerid
#kill timer if it exists
if { [set timr [timerexists timerid]] != "" } {
putlog "$timerid killed"
killutimer $timerid
}
killutimer $timerid
#notify operator that scanning has stopped
putlog "$::botnick ending watch for all channels [strftime "\[%H:%M:%S\]\(%a.\)%D"]"
}
#####################################################################################
#Remove namespace
#####################################################################################
proc Destroy {args} {
Stop
putlog "removing Solobot"
unbind dcc - "startsolo" Solobot::Execute
unbind dcc - "stopsolo" Solobot::Stop
unbind dcc - "nosolo" Solobot::Destroy
unbind raw - "301" Solobot::Whoisreply
unbind raw - "318" Solobot::Whoisreply
deludef flag A
deludef flag S
namespace delete ::Solobot
}
#####################################################################################
#process whois replies
#####################################################################################
proc Whoisreply {serv raw text} {
variable bypass
#parse reply
set tmp [split $text : ]
set tmp1 [split [lindex $tmp 0] ]
set aide [lindex $tmp1 1]
#if user away (301) set user 'A' flag and
#set bypass flag to catch trailing code 318
#then return
if { $raw eq "301" } {
set bucket [chattr $aide +A]
set bypass 1
return 0
#catch trailing code 318, unset bypass flag
#then return
} elseif {$bypass == 1} {
set bypass 0
return 0
#318 flag only (no leading 301) - indicates user is not away
#unset 'A' flag and return
} else {
set bucket [chattr $aide -A]
return 0
}
}
#####################################################################################
#check for bots 'solo' status
#####################################################################################
proc Chkaides {chan} {
set users 0
set away 0
#count users on chan list with appropriate flags
foreach user [::chanlist $chan m|n|l ] {
incr users
#if the user is also flagged away add them to user away count
if {[regexp -- {A} [chattr $user] ]} {
incr away
}
}
#if all the users are 'away' set the chan +S
if { $users == $away } {
channel set $chan +S
putlog "$::botnick solo in $chan"
} else {
#if any users not flagged 'away' set channel -S
channel set $chan -S
putlog "$::botnick has help in $chan"
}
}
#########################################################################################
########################### end namespace ###############################
#########################################################################################
}