Skip to content

Instantly share code, notes, and snippets.

@Ttech
Created December 30, 2010 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ttech/759367 to your computer and use it in GitHub Desktop.
Save Ttech/759367 to your computer and use it in GitHub Desktop.
Magic Log IRC Log Parser for Supybot [Version2 Final]
<?php
// List of 216 Colors (Ideally I'd like to eventually make a random color generator
$colors_list = array(
'FFFCCC',
'CCC999',
'999666',
'666333',
'333000',
'000FFC',
'C00FF9',
'900FF6',
'600FF3',
'300F33',
'99C0C6',
'C00CC9',
'900FFC',
'C33FFC',
'C66FF9',
'966FF6',
'633CC3',
'300CC0',
'033696',
'CCF996',
'F00CCF',
'F33333',
'300666',
'600999',
'900CCC',
'C00FFF',
'F00CC9',
'933CC6',
'633330',
'000660',
'000990',
'000CC0',
'000FF0',
'000FF3',
'366FF0',
'033333',
'99F3C0',
'F00CCF',
'F6699C',
'C33666',
'633999',
'933CCC',
'C33FFF',
'F33996',
'600993',
'300663',
'333993',
'333CC3',
'333FF3',
'333CC3',
'366FF6',
'699FF0',
'066333',
'66FF33',
'F0099F',
'F6666C',
'C33669',
'900999',
'966CCC',
'C66FFF',
'F66996',
'633663',
'300996',
'666CC6',
'666FF6',
'666990',
'033CC3',
'399FF6',
'6CCFF0',
'099333',
'33F333',
'F0066F',
'F33339',
'90066C',
'C0099F',
'F33CCC',
'C99FFF',
'F99CC9',
'966CC6',
'600CC9',
'999FF9',
'999FF3',
'399CC0',
'066990',
'066FF3',
'3CCFF0',
'0CCFF3',
'00CFFF',
'C0033C',
'C00336',
'600669',
'93399C',
'C66CCF',
'F99FFF',
'FCCFFC',
'C99FF9',
'933FFC',
'CCCFF9',
'9CCCC6',
'699993',
'366660',
'033CC0',
'099330',
'033CCC',
'33CCCC',
'C3366C',
'C6600F',
'F0033F',
'F3366F',
'F6699F',
'F99CCF',
'FCCCC9',
'9CC996',
'699993',
'399990',
'099663',
'366660',
'066CCC',
'006CCC',
'600336',
'633009',
'900339',
'933669',
'96699C',
'C99FFC',
'CFFFF9',
'9FFFF6',
'6FFFF3',
'3FFFF0',
'0FFCC6',
'6CCCC3',
'3CCFFF',
'003FFF',
'30000C',
'C33006',
'633339',
'96666C',
'C9999F',
'FCCCCF',
'FFF339',
'9FF99C',
'CFFCCC',
'CFFCC9',
'9FF996',
'6CC663',
'399330',
'066990',
'0CCCC0',
'0CC993',
'00F933',
'F3333F',
'F66009',
'93300C',
'C6633F',
'F9999F',
'FFF99C',
'CCC006',
'6CC669',
'9CC999',
'9FF999',
'9CC993',
'3FF660',
'0CC660',
'099CC3',
'3FFCC0',
'0FF333',
'00F333',
'F6666F',
'F9933C',
'C66009',
'96666F',
'FFF66C',
'CCC669',
'999003',
'366336',
'699666',
'6FF666',
'6CC666',
'699330',
'099993',
'3CCCC6',
'6FF990',
'0FF000',
'00F000',
'F9966F',
'FCC33C',
'C9933F',
'FFF33C',
'CCC339',
'999336',
'666006',
'699003',
'399333',
'3FF333',
'3CC333',
'399333',
'366663',
'3CC996',
'6FF660',
'0FFCC0',
'00FF99',
'FCC33F',
'FCC00F',
'FFF00C',
'CCC009',
'999006',
'666003',
'333339',
'9CC336',
'6CC000',
'0FF000',
'0CC000',
'099000',
'066000',
'033663',
'3FF330',
'0FFFFF',
'00CCO3',
'C990FE',
'9CC33C',
'CFF66C',
'CFF669',
'9FF336',
'6FF003',
'3CC330',
'0CCFF0',
'00CFF0',
'CFF009',
'9FF006',
'6FF003',
'3FF0F0'
);
function get_random_color_old(){
global $colors_list;
if(is_array($colors_list)){
$numeral = intval(count($colors_list));
} else {
print "failure";
}
$randpick = mt_rand(0,$numeral);
$picked_color = $colors_list[$randpick];
unset($colors_list[$picked_color]);
return $picked_color;
}
function get_random_color(){
$color = "rgb(";
for($colors = 1; $colors <= 3; $colors++){
$color .= mt_rand(0,255).",";
}
$color .= ")";
return str_replace(",)",")",$color);
}
?>
<?php
/*
HTML IRC Log Generator Version 2 (20101229-r2)
Important functions
Don't change these
*/
function get_channel_name(){
global $channel;
echo $channel;
}
function make_date_list(){
if(isset($_GET['channel'])){
$channel = stripslashes(htmlentities($_GET['channel']));
}
//$line = "\t\t<div class=\"dates\"><p>";
$line = "";
$dates = array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
foreach($dates as $date){
echo " / <a href=\"?month=$date\">$date</a> /";
}
//$line .= "</p></div>";
}
function make_display_stats(){
global $actual_lines,$actions,$messages;
$actual = (round($messages/2)+$actions);
$stats_line = "There was a total of ".$actual." lines. With $actions being actions and ".round($messages/2)." being messages.";
print $stats_line;
}
function get_last_updated(){
// Why the heck is filemtime not workign here?!
global $month,$day,$year;
print "$month $day $year";
// print date("F d H:i:s.");
}
function is_even($number){
return(!($number & 1));
}
function make_users_list($users){
echo "\t\t<ul>\n";
foreach($users as $user => $color){
if(!stristr($user,"*")){
echo "\t\t\t<li style=\"color: $color\">$user</li>\n";
}
}
echo "\t\t</ul>";
}
?>
Some helpful tips if your going to use this:
* You need php! This was developed in php 5.3 and will probably only work in php 5.3 (sadly)
* This is not the best version, the good one, got formatted when I thought I backed up my work
* This should work but I provide no support, nor am I responsible for anything that happens
while using this.
* this processes supybot-git logs (Supybot 0.83.4.1), older bots might work but I'm not sure
I will try to keep this updated as much as possible.
* You will need to change a few things quite possibly (see below)
-----------------------------------------------------------------------------------------------
line 16
$path must be set to the full or relative path of your logs for me that is
/home/user/supybot/logs/ChannelLogger
line 142
This is the way the bot controls months, it does not search logs for month, however it could be easy
to implement.
If you don't have all these things change accordingly, for example:
change
$filename = "$path/$network/#$channel/$month/#$channel.log";
to
$filename = "$path/$channel.log";
line 113-115
Basically if you want the bot to find channels with more then one #, you need to change this.
change
if(@isset($_GET['channel']) OR @stristr($_GET['channel'],"##")){
$channel = str_replace(array("#","##"),"",stripslashes(strval(urldecode($_GET['channel']))));
}
to
if(@isset($_GET['channel']){
$channel = stripslashes(strval(urldecode($_GET['channel'])));
}
<!DOCTYPE html>
<!-- HTML IRC Log Generator Version 2 (20101229-r2) -->
<!-- Developed by Ttech <http://mostlynothing.info -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>IRC Logs <?php get_channel_name(); ?></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div>
<div id="header">
<h3>Logs for channel: <em>#<?php get_channel_name(); ?></em></h3>
<div class="date_selector"><?php //make_date_list($channel); ?></div>
</div>
<div id="wrapper">
<?php
/*
Copyright 2010 - Joe (Ttech)
MAGIC LOG - VERSION 2
this is the final version of magic log, there will be only minor bug fixes
from now on, furth releases if any. Will not use this code and instead be
written in python and use a seperate bot to log and process. This is will
provide better support and better readability and features.
Enjoy. Support is very limited.
Come by at irc.freenode.net #botters
*/
include("colors.php");
$path = "./ChannelLogger";
$excludes = array(
"alright sparky",
"spam"
);
// We need to set these
$actual_lines = 1;
$actions=0;
$messages=0;
// Everything else
$line_change = array(
"sets",
"has",
"kicked"
);
$users = array();
$channel = "transcendence";
include("functions.php");
function process_line($line_num,$line,$null){
global $excludes,$actual_lines,$colors_list,$users,$actions,$messages;
$date = "";
if(is_even($line_num)){
$line_type = "line_even";
} else {
$line_type = "line_odd";
}
$line = htmlentities($line);
// We need to create the line correctly, purge anything possibly not usefull to us.
// We need a better line thing here but I can't remember what I was saying.
$message_parts = explode(" ",$line);
if(preg_match("/(.*T.*) (\*\*\* (.*?) .*(has (joined|quit)|sets|was kicked) (.*))/",htmlspecialchars_decode($line),$matches_result)){
$date = $matches_result[1];
$user = $matches_result[3];
/*if(!$user == $message_parts[3]){
$user = $message_parts[3];
echo "True $user\n";
}*/
$user = str_replace(array("<",">","&gt;","&lt;"),"",$message_parts[3]);
/*if(in_array($user,$users)){
$line = str_replace("*** $user","*** <span class=\"nick\">$user</span>",$line);
}*/
$line = "<span class=\"action\">".$matches_result[2]."</span>\n";
$actual_lines++;
$actions++;
} elseif(stristr($line,"***") OR stristr($line,"* ")){
$date = $message_parts[0];
$user = $message_parts[3];
$user = str_replace(array("<",">","&gt;","&lt;"),"",$message_parts[3]);
$line = "<span class=\"action\">".$line."</span>\n";
$actual_lines++;
$actions++;
} else {
foreach($excludes as $exclude){
//if(!stristr($line,$exclude) OR !stristr($line,"***")){
if(preg_match("/([0-9+\$\/_.-]*?T[0-9+\$\:\/_.-]*) .*(\<(.*?)\> .*)/",htmlspecialchars_decode($line),$matches_result)){
$date = $matches_result[1];
$nick = $matches_result[3];
$user = $matches_result[3];
$user = str_replace(array("<",">","&gt;","&lt;"),"",$message_parts[2]);
//echo "A: ".$message_parts[2]."\tB: $user\n";
if(!stristr($line,$exclude)){
if(!fnmatch("*\*\*\* $nick &lt;*!~*\@*\&gt; ", $line) OR !fnmatch("*\*\*\* $nick <*!~*\@*> ", $line)){
/*if(stristr($user,"!")){
$user = explode("!",$user);
$user = $user[0];
}*/
if(array_key_exists($user,$users)){
$line = str_replace(array("&lt;$user&gt;","<$user>"),"<span class=\"nick\"><span style=\"color: ".$users[$user]."\">$user</span></span>",$line);
$messages++;
$actual_lines++; // Increment all lines that are real...
} else {
$users[$user] = get_random_color();
}
}
}
} // end regex line match
} // End Foreach
} // End IF / Else
// Make a nice date format whoa hworth hw ot wrthp st
//var_dump($users);
$line = str_replace($date,"",$line);
// Massive hack goes here... Fix later
//$date = str_replace(array(" ","T"),array("","\t"),$date);
$date_parts = explode("T", $date);
$date = "<span class=\"prefix\"><span class=\"date\">".$date_parts[0];
if(isset($date[1])){
@$date .= "<span class=\"time\">".str_replace(" ","",$date_parts[1])."</span>";
}
$date .= "</span></span>";
// End hack
$proc_line = str_replace(array("\n","\t","\r"," "," "),"",$line);
echo "\t\t\t<div class=\"$line_type\"><span class=\"linenumbers\">$line_num</span>$date<span class=\"content\">".$proc_line."</span></div>\n";
}
if(@isset($_GET['channel']) OR @stristr($_GET['channel'],"##")){
$channel = str_replace(array("#","##"),"",stripslashes(strval(urldecode($_GET['channel']))));
}
if(isset($_GET['month'])){
$month = stripslashes(strval(urldecode($_GET['month'])));
} else {
$month = date("F");
}
if(isset($_GET['day'])){
$day = stripslashes(strval(urldecode($_GET['day'])));
} else {
$day = date('d');
}
$day = sprintf('%02d',$day);
/* Debug Mode */
if(isset($_GET['network'])){
$network = stripslashes(strval(urldecode($_GET['network'])));
} else {
$network = "freenode";
}
if(isset($_GET['year'])){
$year = stripslashes(strval(urldecode($_GET['year'])));
} else {
$year = date('Y');
}
include "header.php";
$filename = "$path/$network/#$channel/$month/#$channel.log";
$date_string = date("Y-m-d", strtotime("$month $day $year"));
if(file_exists($filename)){
echo "\t\t<div id=\"messages\">\n";
$lines = file($filename, FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line_num => $line) {
if((stristr($line,$date_string)) OR (@$_GET['display_all']=='on')) {
process_line($line_num,$line,$users);
}
}
echo "\t\t</div>\n\t </div>\n\t<div id=\"userbar\">\n";
make_users_list($users);
echo "\t</div>";
} else {
echo "\t\t<div id=\"messages\"><p>Sorry no channel exists by that name perhaps you should remove the forward # from the name and try again?</p></div>";
}
include "footer.php";
?>
html, body, div, span, ul, li {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
background: #111;
color: #eee;
/* Suggested by Scott
font-family:"DejaVu Sans Mono","Bitstream Vera Sans Mono","Liberation Mono",Monaco,"Lucida Console","Courier New",monospace;
*/
}
#header {
border-bottom: 1px solid #333;
}
#wrapper {
width: 100%;
float: left;
margin-right: -170px;
}
#messages {
margin-right: 170px;
background: #222;
border-right: 1px solid #333;
font-size: 14px;
line-height: 16px;
}
#messages .line_even {
background-color: #222222;
}
#messages .line_odd {
background-color: #282828;
}
#messages .line_even a, .line_odd a {
underline:none;
text-decoration: none;
}
#messages .linenumbers {
display: none;
}
#messages .date {
font-family: monospace;
color: #555;
margin-right: 10px;
}
#messages .date:before {
content: "[";
}
#messages .date:after {
content: "]";
}
#messages .date .time {
margin-left: 8px;
color: #777;
}
#messages .nick {
color: #888;
}
#messages .nick:before {
content: "<";
margin-right: -2px;
}
#messages .nick:after {
content: ">";
}
#messages .nick span {
font-weight: bold;
}
#messages .content .action {
font-style: italic;
color: #aaa;
}
#userbar {
float: right;
overflow: hidden;
}
#userbar ul {
position: fixed;
margin-left: -160px;
margin-top: 10px;
height:100%;
width: 100%;
overflow: scroll;
}
#userbar ul li {
list-style: none;
line-height: 20px;
}
#footer {
clear: both;
margin-top: 5px;
padding: 4px;
background: #222;
border: 1px solid #333;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment