# XChat log to echelog format # # Copyright 2006, johndrinkwater.name # Distributed under the terms of the MIT License. # http://johndrinkwater.name/files/haiku/xchattosupy.awk # # Authors: # John Drinkwater, john@nextraweb.com # # Very naive script, it also requires you to edit variables in the BEGIN block # Known limitations: # Timezone offset is hard coded # Various channel modes are ignored # Haven't tested fully # # run as: awk -f xchattosupy.awk inputlogfile BEGIN { # field separator, defining because user could have overridden FS = " " channel = "#haiku" localuser = "[Beta]" currentyear = 2004 currentlog = "waffle" months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" maxdays = 0 # descriptive output header print "| \txchattosupy.awk, a script to convert xchat log files into supybot compatible ones\n" print "| from johndrinkwater.name" print "| Processing..." } # User has started logging, grab year /^\*\*\*\*/ { currentyear = $9 if ( maxdays < dayswodc ) maxdays = dayswodc dayswodc = 1 printf "|" } /^[[:alpha:]][[:alpha:]][[:alpha:]] [0-9][0-9] / { month = "0" ( index( months, $1 ) + 3) / 4 month = substr( month, length(month) - 1, 2 ) time = $3 gsub( ":", " ", time ) # We add 3600 because the source logs are in GMT, and I want CET timestamp = mktime( currentyear " " month " " $2 " " time " GMT" ) + 3600 day = strftime( "%Y-%m-%d", timestamp ) date = strftime( "[%d-%b-%Y %H:%M:%S]", timestamp ) if ( currentday != day ) { close( currentlog ) currentday = day # make new log file currentlog = channel "." day ".log" printf "." dayswodc++ } skip = "F" } #Autocomplete line, fix me... /^[[:alpha:]][[:alpha:]][[:alpha:]] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^*><-]/ { $0 = substr( substr( $0, 4 ), index( substr( $0, 4 ), $1 " " $2 ) ) } # Local user joined /[[:alpha:]][[:alpha:]][[:alpha:]].*-->.*You are now talking on #/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\tNow talking on #/ { print date " *** [Beta] has joined " channel > currentlog skip = "T" } # Local user quit /[[:alpha:]][[:alpha:]][[:alpha:]].*---.*Disconnected \(/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\tDisconnected \(/ { print date " *** [Beta] has quit IRC" > currentlog skip = "T" } # XChat waffle /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*Unknown command/ { skip = "T" } # Join line /^[[:alpha:]][[:alpha:]][[:alpha:]].*-->.*join/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*joined #/ { print date " *** " $5 " has joined " channel > currentlog skip = "T" } # Part line /^[[:alpha:]][[:alpha:]][[:alpha:]].*<--.*left/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*left #/ { print date " *** " $5 " has left " channel > currentlog skip = "T" } # DCC CHAT /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t DCC / { skip = "T" } # Nick change /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*is now known as/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*is now known as/ { print date " *** " substr( $0, index( $0, $5 ) ) > currentlog skip = "T" } # Kicked /^[[:alpha:]][[:alpha:]][[:alpha:]].*<--.*has kicked/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*has kicked/{ print date " *** " $8 " was kicked by " $5 " (" substr( $0, index( $0, $11 ) ) ")" > currentlog skip = "T" } # Quit line /^[[:alpha:]][[:alpha:]][[:alpha:]].*<--.*has quit/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*-->.*\] Quit/{ print date " *** " $5 " has quit IRC" > currentlog skip = "T" } # Mode line, operator /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*operator/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*operator/ { print date " *** " $5 " sets mode: +o " $11 > currentlog skip = "T" } # Topic change /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*has changed the topic to:/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*has changed the topic to:/ { print date " *** " $5 " changes topic to " substr( $0, index( $0, $11 ) ) > currentlog skip = "T" } # Ban, remove /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*removes ban on/ { print date " *** " $5 " sets mode: -b " $9 > currentlog skip = "T" } # Ban, add /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*sets ban/ || /^[[:alpha:]][[:alpha:]][[:alpha:]].*\*\t.*sets ban on/ { print date " *** " $5 " sets mode: +b " $9 > currentlog skip = "T" } # Emote line /^[[:alpha:]][[:alpha:]][[:alpha:]] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] \*\t/ && skip ~ /F/ { print date " * " substr( $0, index( $0, $5 ) ) > currentlog skip = "T" } # Misc mode /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*sets mode +.*#.*/ && skip ~ /F/ { print date " *** " substr( $0, index( $0, $5 ) ) > currentlog skip = "T" } # Message line /^[[:alpha:]][[:alpha:]][[:alpha:]] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] <[^--]/ { print date " " $4 " " substr( $0, index( $0, $5 ) ) > currentlog skip = "T" } ## To reduce debug output /^[[:alpha:]][[:alpha:]][[:alpha:]].*---.*Topic for #/ { skip = "T" } /^[[:alpha:]][[:alpha:]][[:alpha:]].*-.*\/Wallops-/ { skip = "T" } /^[[:alpha:]][[:alpha:]][[:alpha:]].*[>-]ChanServ|MemoServ|NickServ[<-]/ { skip = "T" } // && skip ~ /F/ { # print $0 } # We've processed the file, now output. END { print "\ndone." print "Maximum days without disconnect: " maxdays }