Posted by electronerd Thu 8th Mar 2007 22:02 - Syntax is TCL/iTCL - 129 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
#name prefix hseen means "handle seen"
-
package require mysqltcl 3.0
-
-
set hseen_db [::mysql::connect -host localhost -user $mysqluser -password $mysqlpass -db $mysqldb]
-
set hseen_channel #nerdstar-test
-
-
-
#a little test proc
-
bind PUB - !hseen hseen
-
proc hseen {nick uhost hand chan txt} {
-
global hseen_db
-
#make sure the connection is up
-
::mysql::ping $hseen_db
-
-
#escape what's gonna be put into an SQL statement from the outside
-
set txt [::mysql::escape $hseen_db $txt]
-
-
#fetch the data about the user
-
set result [::mysql::sel $hseen_db "SELECT jointime, quittime, quitmsg FROM ixc_users WHERE nickname = '$txt' LIMIT 1" -list]
-
::mysql::endquery $hseen_db
-
-
if {[llength $result] == 0} {
-
putmsg $chan "$txt: not found"
-
return
-
}
-
-
set data [lindex $result 0 ]
-
set jointime [lindex $data 0]
-
set quittime [lindex $data 1]
-
set quitmsg [lindex $data 2]
-
putmsg $chan "$txt: Last join: $jointime, Last quit: $quittime, Last quit message: $quitmsg"
-
}
-
-
bind JOIN - "$hseen_channel *" hseen:join
-
proc hseen:join {nick uhost hand chan} {
-
#we've got a separate bind for the bot joining the channel
-
global botnick
-
if { $nick == $botnick} return;
-
-
-
global hseen_db
-
#make sure the server is alive
-
::mysql::ping $hseen_db
-
-
#escape what we're shoving in the query
-
set hand [::mysql::escape $hseen_db $hand]
-
-
#update the join time
-
::mysql::exec $hseen_db "UPDATE ixc_users SET jointime = NOW() WHERE nickname = '$hand' LIMIT 1"
-
-
}
-
-
bind SIGN - "$hseen_channel *" hseen:sign
-
bind PART - "$hseen_channel *" hseen:part
-
bind KICK - "$hseen_channel *" hseen:kick
-
proc hseen:sign {nick uhost hand chan reason} {
-
hseen:leave $hand "Signed off: $reason"
-
}
-
proc hseen:part {nick uhost hand chan reason} {
-
hseen:leave $hand "Parted: $reason"
-
}
-
proc hseen:kick {nick uhost hand chan target reason} {
-
set khand [nick2hand $target]
-
hseen:leave $khand "Kicked by $nick ($hand): $reason"
-
}
-
-
proc hseen:leave {hand reason} {
-
#we don't care about non-registered users
-
if {$hand == "*"} {
-
return
-
}
-
-
global hseen_db
-
#make sure the connection is alive
-
::mysql::ping $hseen_db
-
-
#escape what's going into the SQL to avoid injection
-
set hand [::mysql::escape $hseen_db $hand]
-
set reason [::mysql::escape $hseen_db $reason]
-
-
#update the quit time. I subtract a second from the current time so
-
#that if the user rejoins within the same second, they'll still appear online
-
::mysql::exec $hseen_db "UPDATE ixc_users
-
SET quittime = NOW() - INTERVAL 1 second,
-
jointime = LEAST(jointime, NOW() - INTERVAL 1 second),
-
quitmsg = '$reason'
-
WHERE nickname = '$hand'"
-
-
}
-
-
-
bind JOIN - "$hseen_channel $botnick!*" hseen:botjoin
-
proc hseen:botjoin {nick uhost hand chan} {
-
#we have to put this on a timer because when this bind is called
-
#the bot hasn't seen the userlist yet
-
utimer 1 "hseen:finishbotjoin $chan"
-
}
-
-
proc hseen:finishbotjoin {chan} {
-
set nicks [chanlist $chan]
-
-
global hseen_db
-
::mysql::ping $hseen_db
-
-
#set everyone offline
-
::mysql::exec $hseen_db "UPDATE ixc_users
-
SET quittime = NOW() - INTERVAL 1 second,
-
jointime = LEAST(jointime, NOW() - INTERVAL 1 second),
-
quitmsg = 'Bot restarted'
-
WHERE jointime > quittime"
-
-
set hands {}
-
#see who's still online and logged in
-
foreach nick $nicks {
-
set hand [nick2hand $nick $chan]
-
if { $hand == "*" } {
-
#user is not registered/logged-in so we don't care
-
continue
-
}
-
set hand [::mysql::escape $hseen_db $hand]
-
lappend hands "'$hand'"
-
}
-
set hand_list [join $hands ", "]
-
-
#set the jointime on everyone still online
-
::mysql::exec $hseen_db "UPDATE ixc_users
-
SET jointime = NOW()
-
WHERE nickname IN ($hand_list)"
-
-
}
PermaLink to this entry https://pastebin.co.uk/11578
Posted by electronerd Thu 8th Mar 2007 22:02 - Syntax is TCL/iTCL - 129 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0