rendered paste body# UrbanDictionary TCL by ceL (cel@hackno.org)
# Questions/Comments/Fixes via IRC @ (EFnet/#hackno)
# have fun kids.
#
# By the way you will need ruby installed on the box
# you use this with for the queries to work.
#
# Usage:
# !urbandict [number of results] <search terms>
# !urbanex [number of results] <search terms>
# DO NOT FORGET TO CHANGE THE SCRIPT PATH
# Note the lack of a trailing slash
set script_home "C:/Windrop_jpopsuki/scripts"
set urban_max_results 5
bind pub - !urbandict urbandict
bind pub - !urbanex urbanex
proc check_string {text} {
regsub -all ">" $text "" text
regsub -all "<" $text "" text
regsub -all "|" $text "" text
regsub -all "&" $text "" text
return $text
}
proc urban_escape {string} {
set newstring ""
foreach char [split $string ""] {
if {[regexp {\s} $char]} { append newstring "+" } \
elseif {[regexp {[\w\./]} $char]} { append newstring $char } \
else { append newstring [format "%%%02X" [scan $char "%c"]] }
}
return $newstring
}
proc urbandict {nick uhost handle chan arg} {
global script_home urban_max_results
set arg [subst -nocommands -novariables [check_string $arg]]
if {[llength $arg] < 1} {
putnotc $nick "!urbandict \[number of results\] <search terms> - urban definition of term."
return
}
set num_results 1
if {[string is integer [lindex $arg 0]]} {
set num_results [lindex $arg 0]
if {$num_results > $urban_max_results} {
set num_results $urban_max_results
}
set arg [lrange $arg 1 end]
}
set results [split [exec $script_home/urbandict.rb $num_results [urban_escape $arg]] "\n"]
foreach result $results {
putserv "PRIVMSG $chan :\002definition\002/$arg: $result";
}
}
proc urbanex {nick uhost handle chan arg} {
global script_home urban_max_results
set arg [subst -nocommands -novariables [check_string $arg]]
if {[llength $arg] < 1} {
putnotc $nick "!urbanex \[number of results\] <search terms> - urban example of term."
return
}
set num_results 1
if {[string is integer [lindex $arg 0]]} {
set num_results [lindex $arg 0]
if {$num_results > $urban_max_results} {
set num_results $urban_max_results
}
set arg [lrange $arg 1 end]
}
set results [split [exec $script_home/urbanex.rb $num_results [urban_escape $arg]] "\n"]
foreach result $results {
putserv "PRIVMSG $chan :\002example\002/$arg: $result";
}
}
putlog "urbandict.tcl by ceL (cel@hackno.org) or via IRC EFnet/#hackno loaded"