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.

REQUEST: Search log file(s) for string

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
Scayett
Voice
Posts: 3
Joined: Tue Mar 27, 2012 7:58 pm

REQUEST: Search log file(s) for string

Post by Scayett »

Hi,

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
Is something like this do-able?

Thanks.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

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.

Code: Select all

# 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 ..."
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Post Reply