| 1 |
############################################################################### |
|---|
| 2 |
## This trac.tcl requires Eggdrop1.6.0 or higher ## |
|---|
| 3 |
## (c) 2007 by mvanbaak ## |
|---|
| 4 |
## ## |
|---|
| 5 |
############################################################################### |
|---|
| 6 |
## ## |
|---|
| 7 |
## INSTALL: ## |
|---|
| 8 |
## ======== ## |
|---|
| 9 |
## 1- Copy trac.tcl in your dir scripts/ ## |
|---|
| 10 |
## 2- Add trac.tcl in your eggdrop.conf: ## |
|---|
| 11 |
## source scripts/trac.tcl ## |
|---|
| 12 |
## ## |
|---|
| 13 |
## For each channel you want users to use !trac cmd ## |
|---|
| 14 |
## Just type in partyline: .chanset #channel +trac ## |
|---|
| 15 |
## ## |
|---|
| 16 |
############################################################################### |
|---|
| 17 |
# COOKIES ARE : |
|---|
| 18 |
# ============= |
|---|
| 19 |
# TICKETNUMBER = %ticketnum | BOLD = %bold |
|---|
| 20 |
# STATUS = %status | UNDERLINE = %uline |
|---|
| 21 |
# PRIORITY = %priority | COLORS = %color#,# |
|---|
| 22 |
# SUMMARY = %summary | NEW LINE = \n |
|---|
| 23 |
# REPORTER = %reporter |----------------------------- |
|---|
| 24 |
# TICKETURL = %url | !! to reset color code !! |
|---|
| 25 |
# | !! use %color w/o args !! |
|---|
| 26 |
|
|---|
| 27 |
# example announce: |
|---|
| 28 |
set announce(TRACIRC) "\[%status\] %ticketnum %bold\[%priority\]%bold %summary reported by %reporter %url" |
|---|
| 29 |
|
|---|
| 30 |
#http connection timeout (milliseconds) |
|---|
| 31 |
set trac_timeout "25000" |
|---|
| 32 |
|
|---|
| 33 |
#flood-control |
|---|
| 34 |
set queue_enabled 1 |
|---|
| 35 |
#max requests |
|---|
| 36 |
set queue_size 5 |
|---|
| 37 |
#per ? seconds |
|---|
| 38 |
set queue_time 120 |
|---|
| 39 |
|
|---|
| 40 |
# for a channel !trac request |
|---|
| 41 |
# set to 1 = all results will be sent publicly to the channel |
|---|
| 42 |
# set to 0 = all results will be sent as private notice |
|---|
| 43 |
set pub_or_not 1 |
|---|
| 44 |
|
|---|
| 45 |
# use or not the trac debugger (1=enable debug 0=disable debug) |
|---|
| 46 |
set TRAC_DEBUG 1 |
|---|
| 47 |
|
|---|
| 48 |
# set TRAC_ALTERNATIVE 0 = use the internal tcl http 2.3 package |
|---|
| 49 |
# set TRAC_ALTERNATIVE 1 = use the external curl 6.0+ |
|---|
| 50 |
set TRAC_ALTERNATIVE 0 |
|---|
| 51 |
|
|---|
| 52 |
# set here the location path where find curl 6.0+ |
|---|
| 53 |
set binary(CURL) "" |
|---|
| 54 |
|
|---|
| 55 |
# set trac main url |
|---|
| 56 |
set tracurl "http://dev.mvblog.org" |
|---|
| 57 |
# set the url to the tickets |
|---|
| 58 |
set tracsearchurl "http://dev.mvblog.org/trac/ticket/" |
|---|
| 59 |
|
|---|
| 60 |
################################################################# |
|---|
| 61 |
# DO NOT MODIFY BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING! # |
|---|
| 62 |
################################################################# |
|---|
| 63 |
if { $TRAC_ALTERNATIVE == 0 } { package require http 2.3 } |
|---|
| 64 |
setudef flag trac |
|---|
| 65 |
|
|---|
| 66 |
bind pub -|- !trac trac_proc |
|---|
| 67 |
|
|---|
| 68 |
set instance 0 |
|---|
| 69 |
set warn_msg 0 |
|---|
| 70 |
|
|---|
| 71 |
proc htmlcodes {tempfile} { |
|---|
| 72 |
set mapfile [string map {" ' & & [ ( \ / ] ) { ( } ) £ £ ¨ š © © « « ­ ® ® } $tempfile] |
|---|
| 73 |
set mapfile [string map {´ Ž · · ¹ ¹ » » ¼ Œ ½ œ ¾ Ÿ À À Á Á   } $mapfile] |
|---|
| 74 |
set mapfile [string map {Ã Ã Ä Ä Å Å Æ Æ Ç Ç È È É É Ê Ê Ë Ë Ì Ì Í Í Î Î Ï Ï Ð Ð Ñ Ñ Ò Ò Ó Ó Ô Ô Õ Õ Ö Ö } $mapfile] |
|---|
| 75 |
set mapfile [string map {× × Ø Ø Ù Ù Ú Ú Û Û Ü Ü Ý Ý Þ Þ ß ß à à á á â â ã ã ä ä å å æ æ ç ç è è é é ê ê } $mapfile] |
|---|
| 76 |
set mapfile [string map {ë ë ì ì í í î î ï ï ð ð ñ ñ ò ò ó ó ô ô õ õ ö ö ÷ ÷ ø ø ù ù ú ú û û ü ü ý ý þ þ } $mapfile] |
|---|
| 77 |
set mapfile [string map { "" & "&"} $mapfile] |
|---|
| 78 |
return $mapfile |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
proc channel_check_trac { chan } { |
|---|
| 82 |
foreach setting [channel info $chan] { |
|---|
| 83 |
if {[regexp -- {^[\+-]} $setting]} { |
|---|
| 84 |
if {![string compare "+trac" $setting]} { |
|---|
| 85 |
set permission 1 |
|---|
| 86 |
break |
|---|
| 87 |
} else { |
|---|
| 88 |
set permission 0 |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
return $permission |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
proc replacevar {strin what withwhat} { |
|---|
| 96 |
set output $strin |
|---|
| 97 |
set replacement $withwhat |
|---|
| 98 |
set cutpos 0 |
|---|
| 99 |
while { [string first $what $output] != -1 } { |
|---|
| 100 |
set cutstart [expr [string first $what $output] - 1] |
|---|
| 101 |
set cutstop [expr $cutstart + [string length $what] + 1] |
|---|
| 102 |
set output [string range $output 0 $cutstart]$replacement[string range $output $cutstop end] |
|---|
| 103 |
} |
|---|
| 104 |
return $output |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
proc findnth {strin what count} { |
|---|
| 108 |
set ret 0 |
|---|
| 109 |
for {set x 0} {$x < $count} {incr x} { |
|---|
| 110 |
set ret [string first $what $strin [expr $ret + 1]] |
|---|
| 111 |
} |
|---|
| 112 |
return $ret |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
proc trac_proc { nick uhost handle chan arg } { |
|---|
| 116 |
global cast_linelimit instance queue_size queue_time queue_enabled trac_timeout TRAC_DEBUG pub_or_not announce random warn_msg binary TRAC_ALTERNATIVE tracurl tracsearchurl |
|---|
| 117 |
# channel_check permission |
|---|
| 118 |
set permission_result [channel_check_trac $chan] |
|---|
| 119 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG permission_result == $permission_result" } |
|---|
| 120 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG instance == $instance" } |
|---|
| 121 |
if { $permission_result == 0} { return } |
|---|
| 122 |
# public or private |
|---|
| 123 |
if {$pub_or_not == 1 } { set toput "PRIVMSG $chan" } else { set toput "NOTICE $nick" } |
|---|
| 124 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG toput_result == $toput" } |
|---|
| 125 |
# if no arg passed, show help |
|---|
| 126 |
if {$arg == ""} { |
|---|
| 127 |
if { $TRAC_ALTERNATIVE == 0 } { set using "Http 2.3+" } else { set using "Curl 6.0+" } |
|---|
| 128 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG no arg passed, show help" } |
|---|
| 129 |
puthelp "$toput :trac info script \002v0.0.1\002 by mvanbaak using \002$using\002" |
|---|
| 130 |
puthelp "$toput :\002Syntax: !trac <ticket number>\002 exemple: !trac 13" |
|---|
| 131 |
return |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
#flood-control |
|---|
| 135 |
if { $queue_enabled == 1 } { |
|---|
| 136 |
#flooded? |
|---|
| 137 |
if { $instance >= $queue_size } { |
|---|
| 138 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG flood detected" } |
|---|
| 139 |
if { $warn_msg == 0 } { |
|---|
| 140 |
set warn_msg 1 |
|---|
| 141 |
putquick "$toput :Flood-Control: Request for \"$arg\" from user \"$nick\" will not be answered." |
|---|
| 142 |
putquick "$toput :Flood-Control: Maximum of $queue_size requests every $queue_time seconds." |
|---|
| 143 |
utimer 120 wmsg |
|---|
| 144 |
} |
|---|
| 145 |
return |
|---|
| 146 |
} |
|---|
| 147 |
incr instance |
|---|
| 148 |
if { $TRAC_DEBUG == 1 } { putlog "TRAC_DEBUG new instance == $instance" } |
|---|
| 149 |
utimer [set queue_time] decr_inst |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
# initial search |
|---|
| 153 |
set searchString [string map {\ %20 & %26 , %2C . %20} $arg] |
|---|
| 154 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG searchString: \"$searchString\"" } |
|---|
| 155 |
if { $TRAC_ALTERNATIVE == 0 } { |
|---|
| 156 |
set page [::http::config -useragent "MSIE 6.0"] |
|---|
| 157 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG ${tracsearchurl}$searchString" } |
|---|
| 158 |
set page [::http::geturl ${tracsearchurl}$searchString -timeout $trac_timeout] |
|---|
| 159 |
if { [::http::status $page] == "timeout" } { |
|---|
| 160 |
puthelp "$toput :\002Connection to ${tracurl} timed out while doing initial search.\002" |
|---|
| 161 |
::http::Finish $page |
|---|
| 162 |
return |
|---|
| 163 |
} |
|---|
| 164 |
set html [::http::data $page] |
|---|
| 165 |
::http::Finish $page |
|---|
| 166 |
} else { |
|---|
| 167 |
catch { exec $binary(CURL) "${tracsearchurl}$searchString" } html |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
set output $announce(TRACIRC) |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
# collect output |
|---|
| 174 |
set ticketnum "N/A" ; set priority "N/A" ; set summary "N/A" |
|---|
| 175 |
set status "N/A" ; set name "N/A" |
|---|
| 176 |
|
|---|
| 177 |
## get ticetnum |
|---|
| 178 |
if [regexp {<h1>Ticket (.*?) <span} $html dummy ticketnum] { |
|---|
| 179 |
set pos [expr [string last > $ticketnum] + 1] |
|---|
| 180 |
set ticketnum [string range $ticketnum $pos end] |
|---|
| 181 |
set ticketnum [htmlcodes $ticketnum] |
|---|
| 182 |
} |
|---|
| 183 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG ticketnum == $ticketnum" } |
|---|
| 184 |
## get status |
|---|
| 185 |
if [regexp {<span class="status">(.*?)</span>} $html dummy status] { |
|---|
| 186 |
set pos [expr [string last > $status] + 1] |
|---|
| 187 |
set status [string range $status $pos end] |
|---|
| 188 |
set status [htmlcodes $status] |
|---|
| 189 |
set status [string map {( ""} $status] |
|---|
| 190 |
set status [string map {) ""} $status] |
|---|
| 191 |
} |
|---|
| 192 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG status == $status" } |
|---|
| 193 |
## get summary |
|---|
| 194 |
if [regexp {<h2 class="summary">(.*?)</h2>} $html dummy summary] { |
|---|
| 195 |
set pos [expr [string last > $summary] + 1] |
|---|
| 196 |
set summary [string range $summary $pos end] |
|---|
| 197 |
set summary [htmlcodes $summary] |
|---|
| 198 |
} |
|---|
| 199 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG summary == $summary" } |
|---|
| 200 |
## get priority |
|---|
| 201 |
if [regexp {<td headers="h_priority">(.*?)</td>} $html dummy priority] { |
|---|
| 202 |
set pos [expr [string last > $priority] +1 ] |
|---|
| 203 |
set priority [string range $priority $pos end] |
|---|
| 204 |
set priority [htmlcodes $priority] |
|---|
| 205 |
} |
|---|
| 206 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG priority == $priority" } |
|---|
| 207 |
## get reporter |
|---|
| 208 |
if [regexp {<td headers="h_reporter">(.*?)</td>} $html dummy reporter] { |
|---|
| 209 |
set pos [expr [string last > $reporter] +1 ] |
|---|
| 210 |
set reporter [string range $reporter $pos end] |
|---|
| 211 |
set reporter [htmlcodes $reporter] |
|---|
| 212 |
} |
|---|
| 213 |
if {$TRAC_DEBUG == 1} { putlog "TRAC_DEBUG reporter == $reporter" } |
|---|
| 214 |
|
|---|
| 215 |
## output results |
|---|
| 216 |
|
|---|
| 217 |
set output [replacevar $output "%bold" "\002"] |
|---|
| 218 |
set output [replacevar $output "%color" "\003"] |
|---|
| 219 |
set output [replacevar $output "%uline" "\037"] |
|---|
| 220 |
set output [replacevar $output "%ticketnum" $ticketnum] |
|---|
| 221 |
set output [replacevar $output "%status" $status] |
|---|
| 222 |
set output [replacevar $output "%summary" $summary] |
|---|
| 223 |
set output [replacevar $output "%priority" $priority] |
|---|
| 224 |
set output [replacevar $output "%reporter" $reporter] |
|---|
| 225 |
set output [replacevar $output "%url" ${tracsearchurl}$searchString] |
|---|
| 226 |
foreach line [split $output "\n"] { |
|---|
| 227 |
puthelp "$toput :$line" |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
proc decr_inst { } { |
|---|
| 233 |
global TRAC_DEBUG instance |
|---|
| 234 |
if { $instance > 0 } { incr instance -1 } |
|---|
| 235 |
if { $TRAC_DEBUG == 1 } { putlog "TRAC_DEBUG instance decreased by timer to: $instance" } |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
proc wmsg { } { |
|---|
| 239 |
global warn_msg |
|---|
| 240 |
set warn_msg 0 |
|---|
| 241 |
} |
|---|
| 242 |
putlog "TRAC info version 0.0.1 loaded" |
|---|