I was thinking for a while and thought of a script idea, one that users can use to search a string with a command inside the bot's latest log file, and return the latest message with that, however it does not include the bot's text.
For example:
User: hello there
Tom: hiya, User!
User: !log hiya
Bot: User: <Tom> hiya, User! @ 3:00 AM 29/03/12
Tom: hmm
Tom: !log User
Bot: Tom: <User> !log hiya
Try my script. This is the early alpha version. But it can find last line with needed text. And it can ignore lines from bots.
Ive add some comments to code. If you have some suggestions, Ill be glad to read them.
# List of bots to ignore.
set ignorenicks "lamestbot quiz Info bionic"
bind pub n|n !ls ls
proc ls {nick uhost hand chan text} {
global ignorenicks
# We get the folder with channel logs
regexp {\#(.*?)$} $chan "" channel
#set channel "egghelp"
# String to search
set string $text
# All logfiles in channel log folder
set alllogs [glob -directory "logs/$channel" -types f -nocomplain "*"]
set mtimelist [list]
# We create new list with log filenames and modify time
foreach log $alllogs {
lappend mtimelist [list $log [file mtime $log]]
}
# We sort logs by modify time
set sortmtimelist [lsort -decreasing -index 1 "$mtimelist"]
# And create new list with ligfiles only. They sorted by modify time.
foreach sortlog $sortmtimelist {
lappend sortlogs [lindex $sortlog 0]
}
# We begin work with every logfile.
foreach logfile $sortlogs {
set file [open "$logfile" "r"]
# We reverse logfile because we need to get the latest result at first.
# I need to rewrite this part useing lreverse command.
set data [read -nonewline $file]
close $file
set lines [split $data "\n"]
set lines_ [list]
foreach line $lines {
set lines_ [linsert $lines_ 0 $line]
}
set file [open "reverselog" "w+"]
puts $file [join $lines_ "\n"]
close $file
# Here we collect all lines with needed string in searchedlines variable.
foreach line [split [read [open "reverselog" "r"]] "\n"] {
if {[regexp {\<.*?\>\ (.*?)$} $line "" line2]} {
if {[string match -nocase "*$string*" $line2]} {
lappend searchedlines $line
}
}
}
close $file
file delete -force "reverselog"
}
# we take our lines and push them to other proc.
if {[info exists searchedlines] && $searchedlines != ""} {
workwithlines $nick $uhost $hand $chan $searchedlines
} else {
putserv "PRIVMSG $chan :There is no \'$string\' in \#$channel logs."
return 0
}
}
# In this proc we delete lines from ignored bots. And send the firsh found line to channel.
proc workwithlines {nick uhost hand chan searchedlines} {
foreach searchedline $searchedlines {
regexp {\<(.*?)\>} $searchedline "" nickname
if {[checkignorenick $nickname] == "0"} {
lappend neededlines $searchedline
}
}
putserv "PRIVMSG $chan :[lindex $neededlines 0]"
putlog [llength $neededlines]
}
# Here we check the author of line.
proc checkignorenick {nick} {
global ignorenicks
foreach ignorenick $ignorenicks {
if {$ignorenick == $nick} {
return 1
}
}
return 0
}
putlog "Log Search by tvrsh v0.1 loaded ..."