Code: Select all
#Hadace messaging (uzeno.tcl v.1.3 2005.nov.02) (based on HAL9000's learn.tcl)
# hadace@dpg.hu http://hadace.homelinux.org
#
# Installing:
#
# Put your uzeno.tcl file in your eggdrop scripts dir
# In your bots config file add
# source scripts/uzeno.tcl
#
# DESCRIPTION:
#
# Leave a message for a nick with "!msg <nick> <message>" when the nick isn't on the channel, or is away.
# After the nick join or spoke something on any channel the Bot delivers the messages.
#
# Leave a message: !msg <nick> <message>
bind pub v|o "!msg" mess_do
#list of the recepients: !messages
bind pub o|o "!messages" mess_lista
bind pubm - * mess_join
bind time - "20 * * * *" mess_sort
set message_db "h_message.dat"
set message_whodid ""
proc mess_sort {a c d e f} {
global message_db
set t_count [clock clicks -milliseconds]
set filemuvelet [open $message_db r]
set osszesuzenet ""
while {![eof $filemuvelet]} {
set konkretuzenet [gets $filemuvelet]
if {[info exists konkretuzenet]&&$konkretuzenet!=""} {
lappend osszesuzenet [split $konkretuzenet " "]
}
}
close $filemuvelet
set osszesuzenet [lsort -index 1 $osszesuzenet]
set filemuvelet [open $message_db w]
foreach konkretuzenet $osszesuzenet {
puts $filemuvelet [join $konkretuzenet " "]
}
close $filemuvelet
putlog "!message Done with sorting of data on the database ($message_db)->[expr double([clock clicks -milliseconds]-$t_count)/1000]s"
}
proc mess_do {nick host hand chan args} {
set args [lindex $args 0]
set args [split $args " "]
if {[lindex $args 1] == ""} {
puthelp "NOTICE $nick :igy te alma: !msg <nick> <uzenet>"
} else {
mess_write $nick [lindex $args 0] [lrange $args 1 end]
puthelp "NOTICE $nick :[lindex $args 0] szamara uzenet eltarolva"
}
}
proc mess_write { nick cimzett uzenet } {
global message_db
set cimzett [string tolower $cimzett]
if {![file exists $message_db]} {
file mkdir [lindex [split $message_db /] 0]
set filemuvelet [open $message_db w+]
puts $filemuvelet "Hadace messaging adatbazisfile letrehozva"
} else {
set filemuvelet [open $message_db a]
}
set systemTime [clock seconds]
set ido [clock format $systemTime -format {%Y.%m.%d. %H.%M:}]
puts $filemuvelet "$nick $cimzett $ido [join $uzenet] "
close $filemuvelet
}
#####################
proc mess_join { nick uhost hand chan args } {
#puthelp "NOTICE HeyBaby : $nick $uhost $hand $chan $args"
global message_db message_whodid
if {![info exists message_whodid]} {
set message_whodid ""
}
set explain [string tolower $nick]
set nick [string tolower $nick]
set filemuvelet [open $message_db r]
set osszesuzenet ""
while {![eof $filemuvelet]} {
gets $filemuvelet konkretuzenet
set konkretuzenet [split $konkretuzenet " "]
if {[string equal -nocase [lindex $konkretuzenet 1] $explain]} {
lappend osszesuzenet [join $konkretuzenet " "]
}
}
close $filemuvelet
set count 0
if {[llength $osszesuzenet]==1} {
#puthelp "PRIVMSG $chan :${explain}: [join [lrange [split [lindex $osszesuzenet 0] " "] 2 end]]"
set uzente [split [lindex $osszesuzenet 0] " "]
puthelp "PRIVMSG $explain :[lindex $uzente 0] uzente [join [lrange [split [lindex $osszesuzenet 0] " "] 2 end]]"
#puthelp "NOTICE HeyBaby : [lindex $osszesuzenet 0] uzente: [join [lrange [split [lindex $osszesuzenet 0] " "] 2 end]]"
incr count
} else {
foreach konkretuzenet $osszesuzenet {
incr count
#puthelp "PRIVMSG $chan :\002\037${explain}\[\037\002${count}\002\037]:\037 \002[join [lrange [split $konkretuzenet " "] 2 end]]"
puthelp "PRIVMSG $explain :[lindex $konkretuzenet 0]\[${count}] uzenete [join [lrange [split $konkretuzenet " "] 2 end]]"
#puthelp "NOTICE HeyBaby :${explain} [lindex $konkretuzenet 0]\[${count}]: [join [lrange [split $konkretuzenet " "] 2 end]]"
}
}
if {$count == 0} {
#putlog "uzeno.tcl: nincs uzenet $nick szamara"
} else {
lappend message_whodid [list $explain [string tolower $chan]]
set explain [message_filterstr $explain] ;# Don't allow code to be executed
set chan [message_filterstr $chan] ;# ensure []s are properly handled...
#utimer 60 "message_flood \"$explain\" \"$chan\""
mess_delete $nick
#putlog "uzeno.tcl: uzenet atadva $nick szamara"
}
}
###############################################x
proc message_filterstr { data } {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}
proc mess_delete { cimzett {remnum "all"}} {
global message_db
set cimzett [string tolower $cimzett]
set filemuvelet [open $message_db r]
set osszesuzenet ""
set count 1
if {$remnum == "all"} {
while {![eof $filemuvelet]} {
gets $filemuvelet konkretuzenet
if {![string equal -nocase [lindex [split $konkretuzenet] 1] $cimzett]} {
lappend osszesuzenet $konkretuzenet
}
}
} else {
while {![eof $filemuvelet]} {
gets $filemuvelet konkretuzenet
if {![string equal -nocase [lindex [split $konkretuzenet] 1] $cimzett] || ($count != $remnum && $remnum != -2)} {
if {[info exists konkretuzenet]&&$konkretuzenet!=""} {
lappend osszesuzenet $konkretuzenet
}
if {[string equal -nocase [lindex [split $konkretuzenet] 1] $cimzett]} {
incr count
}
} else {
incr count
}
}
}
close $filemuvelet
set filemuvelet [open $message_db w]
foreach konkretuzenet $osszesuzenet {
puts $filemuvelet $konkretuzenet
}
close $filemuvelet
}
proc mess_lista {nick host hand chan args} {
global message_db
putserv "NOTICE $nick :\[ uzenetek cimzettjeinek listaja \]"
set lista ""
set filemuvelet [open $message_db r]
while {![eof $filemuvelet]} {
lappend lista [lindex [split [gets $filemuvelet] " "] 1]
}
close $filemuvelet
foreach {a b c d e f g} [lsort -unique $lista] {
putserv "NOTICE $nick :cimzettek: $a $b $c $d $e $f $g"
}
putserv "NOTICE $nick :\[ lista vege \]"
}
putlog "Hadace messaging (uzeno.tcl v.1.3 2005.nov.02) for #mfc.cs @ quakenet loaded"
thxs[/code]