#!/usr/bin/tclsh # Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 # $Header: $ source secret_mysql.tcl # Load the mysqltcl library # mysqltcl install's is braindead so note to self get robbat2 to fix. set mysqltcl_version 2.14 set libmytcl /usr/lib/mysqltcl-${mysqltcl_version}/libmysqltcl${mysqltcl_version}.so load ${libmytcl} ## You can define nicks that should be ignored. set bad_nicks {GenBot p2 glbt} ########################################################################################### proc validbug {num} { if {$num == ""} { return 1 } if {[string trim $num #1234567890] == ""} {return 0} return 1 } proc bugzilla:init:mysql {} { global bugzilla if {[info commands mysqlconnect] == ""} { putlog "[info script] needs libmysqltcl.so - not installed!" return 0 } catch {mysqlclose $bugzilla(link)} if {[catch {set bugzilla(link) [mysqlconnect -port $bugzilla(port) -user $bugzilla(user) -password $bugzilla(pass) -host $bugzilla(host) ]}]} { putlog "[info script] can't connect to mysql server at $bugzilla(host)"; return 0 } if {[catch {mysqluse $bugzilla(link) $bugzilla(name)}]} { putlog "[info script] can't use database!" catch {mysqlclose $bugzilla(link)} return 0 } bind pub -|- !bug pub:bugzilla bind pub -|- !bugstats pub:bugzilla:dbstats bind pub -|- !bugsearch pub:bugzilla:dbsearch bind dcc -|- bugstats dcc:bugzilla:dbstats bind dcc -|- bugsearch dcc:bugzilla:dbsearch bind dcc -|- bug dcc:bugzilla bind pubm -|- *bug* pub:bugzilla:chanbug return 0 } # fetch bug info by bug number proc bugzilla:mysql:query {bugnum} { global bugzilla set bugnum [string trim $bugnum #] if {[string trim $bugnum 1234567890] != ""} {return ""} # try to help ensure the database is there for us. catch {mysqluse $bugzilla(link) $bugzilla(name)} set select "SELECT profiles.login_name,bug_id,short_desc,priority,resolution,rep_platform,bug_status,bug_severity,profilesb.login_name AS reporter FROM bugs LEFT JOIN profiles ON bugs.assigned_to = profiles.userid LEFT JOIN profiles AS profilesb ON bugs.reporter = profilesb.userid WHERE bug_id=${bugnum}" mysqlsel $bugzilla(link) ${select} mysqlmap $bugzilla(link) {login_name bug_id short_desc priority resolution rep_platform bug_status bug_severity reporter} { if {${resolution} == "" } { set resolution "pending" } return "http://bugs.gentoo.org/show_bug.cgi?id=$bug_id [string range ${bug_severity} 0 2], ${priority}, ${rep_platform}, ${reporter}->${login_name}, ${bug_status}, ${resolution}, ${short_desc}" } } proc bugzilla:mysql:count {} { global bugzilla set select "SELECT COUNT(bug_id) as count FROM $bugzilla(name).bugs" mysqlsel $bugzilla(link) ${select} mysqlmap $bugzilla(link) {count} {return $count} return 0 } proc bugzilla:mysql:count:type {type} { global bugzilla set select "SELECT count(bug_id) as count from $bugzilla(name).bugs WHERE bug_status='${type}'" mysqlsel $bugzilla(link) ${select} mysqlmap $bugzilla(link) {count} {return $count} return 0 } proc dcc:bugzilla {hand idx arg} { putidx $idx "Querying bugzilla database" putidx $idx "[bugzilla:mysql:query $arg]" } proc dcc:bugzilla:dbstats {hand idx arg} { putidx $idx "([bugzilla:mysql:count:type NEW] NEW, [bugzilla:mysql:count:type RESOLVED] RESOLVED, [bugzilla:mysql:count] total)" } proc bugzilla:dbsearch {arg} { global bugzilla set arg [string trim ${arg} "%;-\\"] if {$arg == ""} { return "Invalid Search String" } set select "SELECT profiles.login_name,bug_id,short_desc,priority,resolution,rep_platform,bug_status,bug_severity,profilesb.login_name AS reporter FROM bugs LEFT JOIN profiles ON bugs.assigned_to = profiles.userid LEFT JOIN profiles AS profilesb ON bugs.reporter = profilesb.userid WHERE bug_status='NEW' AND short_desc LIKE '%${arg}%' LIMIT 1" mysqlsel $bugzilla(link) ${select} mysqlmap $bugzilla(link) {login_name bug_id short_desc priority resolution rep_platform bug_status bug_severity reporter} { if {${resolution} == "" } { set resolution "pending" } return "http://bugs.gentoo.org/show_bug.cgi?id=$bug_id [string range ${bug_severity} 0 2], ${priority}, ${rep_platform}, ${reporter}->${login_name}, ${bug_status}, ${resolution}, ${short_desc}" } return "Zarro Boogs found." } proc dcc:bugzilla:dbsearch {hand idx arg} { set msg "[bugzilla:dbsearch ${arg} ]" putidx $idx "${msg}" } proc pub:bugzilla:dbsearch {nick uhost hand chan arg} { set msg "[bugzilla:dbsearch $arg]" if {$msg != "" } {putquick "PRIVMSG $chan :${nick}: ${msg}"} } proc pub:bugzilla {nick uhost hand chan arg} { set msg "[bugzilla:mysql:query $arg]" if {$msg != "" } {putquick "PRIVMSG $chan :${nick}: ${msg}"} } proc pub:bugzilla:dbstats {nick uhost hand chan arg} { putquick "PRIVMSG $chan :([bugzilla:mysql:count:type NEW] NEW, [bugzilla:mysql:count:type RESOLVED] RESOLVED, [bugzilla:mysql:count] total)" } proc pub:bugzilla:chanbug {nick uhost hand chan arg} { global botnick bad_nicks foreach u ${bad_nicks} { if {[string match [string tolower ${nick}] [string tolower ${u}]]} { return 0 } } # If Genbot is on the same channel as us lets shutup # about the bug unless we are asked directly if {[onchan GenBot $chan]} { if {[string range [lindex $arg 0] 0 [expr [string length $botnick] - 1]] != "$botnick" } { return 0 } } set bug [lindex ${arg} [expr [lsearch ${arg} bug] + 1]] if {[validbug ${bug}] == 0} { set msg [bugzilla:mysql:query ${bug}] if {$msg != ""} { putquick "PRIVMSG ${chan} :${nick}: $msg" } } } bugzilla:init:mysql unset bugzilla(pass)