- Code: Select all
setudef flag mysqllog
setudef flag mysqllogsearch
load /usr/lib/mysqltcl-3.02/libmysqltcl3.02.so
set db_handle [mysql::connect -host localhost -user [b]user[/b] -password [b]password[/b] -db [b]database[/b]]
proc log:add {channel nick uhost type arg} {
global db_handle;
set channel [string tolower $channel]
set channel [mysql::escape $db_handle $channel]
set nick [mysql::escape $db_handle $nick]
set uhost [mysql::escape $db_handle $uhost]
set arg [mysql::escape $db_handle $arg]
set result [mysql::exec $db_handle "INSERT INTO log (created,channel,nick,uhost,type,arg) VALUES (NOW(),'$channel','$nick','$uhost','$type','$arg')"]
if {$result != 1} {
putlog "Couldn't execute $sql on the server!"
}
}
proc log:pubmsg {n u h c t} {
if {[channel get $c mysqllog]} {
if {![string match "!*" $t] && ![string match ".*" $t] && ![string match "\$*" $t]} {
log:add $c $n $u "MESSAGE" $t
}
}
}
bind pubm - * log:pubmsg;
proc log:pubnotc {n u h t c} {
if {$c ne $::botnick} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "NOTICE" $t
}
}
}
bind notc - * log:pubnotc;
proc log:join {n u h c} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "JOIN" ""
}
}
bind join - * log:join;
proc log:part {n u h c t} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "PART" $t
}
}
bind part - * log:part;
proc log:topic {n u h c t} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "TOPIC" $t
}
}
bind topc - * log:topic;
proc log:kick {n u h c v msg} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "KICK" "$v $msg"
}
}
bind kick - * log:kick;
proc log:quit {n u h c t} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "QUIT" $t
}
}
bind sign - * log:quit;
proc log:nick {n u h c t} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "NICK" $t
}
}
bind nick - * log:nick;
proc log:mode {n u h c m v} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "MODE" "$m $v"
}
}
bind mode - * log:mode;
proc log:ctcp {n u h c k t} {
if {$c ne $::botnick} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "CTCP" "$k: $t"
}
}
}
bind ctcp - * log:ctcp;
proc log:ctcpreply {n u h c k t} {
if {$c ne $::botnick} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "CTCP-REPLY" "$k: $t"
}
}
}
bind ctcr - * log:ctcpreply;
proc log:split {n u h c } {
if {[channel get $c mysqllog]} {
log:add $c $n $u "SPLIT" ""
}
}
bind splt - * log:split;
proc log:rejoin {n u h c} {
if {[channel get $c mysqllog]} {
log:add $c $n $u "REJOIN" ""
}
}
bind rejn - * log:rejoin;
bind pub o !logsearch log:search
proc log:search {n u h c in} {
if {[channel get $c mysqllogsearch]} {
set a $in
set mode " "
set chan $c;
foreach txt $in {
if {$txt eq "-today"} {
set matchdate " date(created) = curdate() AND"
set a [lrange $a 1 end]
} else {
set matchdate ""
}
if {$txt eq "-bool"} {
set mode " IN BOOLEAN MODE"
set a [lrange $a 1 end]
}
if {$txt eq "-exp"} {
set mode " WITH QUERY EXPANSION"
set a [lrange $a 1 end]
}
if {$txt eq "-chan"} {
set chan [lindex $a 1]
set a [lrange $a 2 end]
}
}
set result [mysql::sel $::db_handle "SELECT id,date_format(created,'%Y-%m-%d %H:%i') created,channel,nick,uhost,type,arg,MATCH(`arg`,`nick`) AGAINST('[mysql::escape $::db_handle $a]'$mode) `match` FROM `log` WHERE$matchdate channel = '[mysql::escape $chan]' HAVING `match` > 0 ORDER BY `match` DESC LIMIT 3" -list]
if {[llength $result] > 0} {
putserv "PRIVMSG $c :I have some results for you $n";
#id created channel nick uhost type arg
foreach res $result {
switch [string tolower [lindex $res 5]] {
message {
putserv "PRIVMSG $c :[lindex $res 1] <[lindex $res 3]> [lindex $res 6]";
}
topic {
putserv "PRIVMSG $c :[lindex $res 1] * [lindex $res 3] set channel topic to '[lindex $res 6]'";
}
notice {
putserv "PRIVMSG $c :[lindex $res 1] -[lindex $res 3]@[lindex $res 2]- [lindex $res 6]";
}
kick {
putserv "PRIVMSG $c :[lindex $res 1] * [lindex [lindex $res 6] 0] was kicked out of the channel by [lindex $res 3] ([lrange [lindex $res 6] 1 end])";
}
quit {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] quit irc ([lindex $res 6])";
}
part {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] left the channel ([lindex $res 6])";
}
join {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] joined the channel";
}
mode {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] sets mode: [lindex $res 6]";
}
ctcp {
putserv "PRIVMSG $c :[lindex $res 1] \[[lindex $res 3]\] [lindex $res 6]";
}
ctcr {
putserv "PRIVMSG $c :[lindex $res 1] \[[lindex $res 3] reply\] [lindex $res 6]";
}
split {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] left the channel in a netsplit";
}
rejoin {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] rejoined the channel after a netsplit";
}
nick {
putserv "PRIVMSG $c :[lindex $res 1] [lindex $res 3] changed nick to [lindex $res 6]";
}
}
}
} else {
putserv "PRIVMSG $c :Didn't find anything, $n";
}
}
}
######################## Credit for the rest of the script goes to Sumsar website: http://www.sp00fed.dk /forum
bind PUB m !log log:public
proc log:public {nick uhost hand chan arg} {
set s [lindex $arg 0]
switch $s {
on {
if {[channel get $chan mysqllog]} {
putserv "PRIVMSG $chan :Logging is already \002active\002 for $chan"
} else {
channel set $chan +mysqllog
putserv "PRIVMSG $chan :Logging is now \002active\002 for $chan"
}
}
off {
channel set $chan -mysqllog
putserv "PRIVMSG $chan :Logging is \002no longer active\002 for $chan"
}
default {
if {[channel get $chan mysqllog]} {
putserv "PRIVMSG $chan :Logging is \002active\002 for $chan"
} else {
putserv "PRIVMSG $chan :Logging is \002not active\002 for $chan"
}
}
}
}
Mysql Table:
- Code: Select all
DROP TABLE IF EXISTS `log`;
CREATE TABLE `log` (
`id` int(11) NOT NULL auto_increment,
`created` datetime default NULL,
`channel` varchar(255) default NULL,
`nick` varchar(20) default NULL,
`uhost` varchar(255) default NULL,
`type` varchar(20) default NULL,
`arg` varchar(255) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Requires mysqltcl 3.02 (maybe less?)
Features:
Logs every event to an mysql table.
Searching in logs from IRC (!logsearch requires global op)
Turning logging on and off (!log on/off requires global master)
For !logsearch the channel must have set +mysqllogsearch, and to enable logging the channel must have +mysqllog (!log on/off)
Examples on using !logsearch:
!logsearch <parameters> <search words>
Parameters are:
-chan #channel : search in the given channel
-bool : search using boolean mode you can include and exclude words by +/-
-exp : query expansion, searches and extra time in the table for more expanded results
-today : only search for events today.
eg.
!logsearch -chan #takeover -today -bool +Sumsar -elite
!logsearch -today Dandy owns
!logsearch -exp -chan #Dandy Takes search to the next level