From: <bi...@us...> - 2009-06-26 13:20:39
|
Revision: 11276 http://amsn.svn.sourceforge.net/amsn/?rev=11276&view=rev Author: billiob Date: 2009-06-26 13:20:31 +0000 (Fri, 26 Jun 2009) Log Message: ----------- update jake plugin by alexandernst Modified Paths: -------------- trunk/amsn-extras/plugins/jake/jake.tcl trunk/amsn-extras/plugins/jake/lang/langen trunk/amsn-extras/plugins/jake/lang/langes trunk/amsn-extras/plugins/jake/lang/langfi trunk/amsn-extras/plugins/jake/plugininfo.xml Modified: trunk/amsn-extras/plugins/jake/jake.tcl =================================================================== --- trunk/amsn-extras/plugins/jake/jake.tcl 2009-06-25 16:43:03 UTC (rev 11275) +++ trunk/amsn-extras/plugins/jake/jake.tcl 2009-06-26 13:20:31 UTC (rev 11276) @@ -2,11 +2,21 @@ global mydir +global birthday +global starttime + proc jakeStart { dir } { global mydir set mydir $dir + global birthday + global starttime + global ntotalsearches + + set birthday [clock scan 05/02/2009/12/00 -format %d/%m/%Y/%H/%M] + set starttime [clock seconds] + ::plugins::RegisterPlugin jake ::plugins::RegisterEvent jake chat_msg_received answer ::plugins::RegisterEvent jake ChangeMyState online @@ -17,20 +27,68 @@ load_lang $lang $langdir array set ::jake::config { - botname {jake} - mystate {1} - helptxt {I'm $botname, an AI bot.} - nresults {5} + botname {jake} + helptxt {I'm jake, an AI bot.} + nresults {5} } set ::jake::configlist [list \ - [list bool "[trans state]" mystate] \ [list str "[trans name]" botname] \ [list str "[trans helptext]" helptxt] \ [list str "[trans nresults]" nresults] \ ] } +proc alterString {phrase z} { + if {$z < [string length $phrase]} { + if {[string is alpha [string range $phrase $z $z]]} { + if {[string is lower [string range $phrase $z $z]]} { + set phrase [string toupper $phrase $z $z] + return $phrase + } elseif {[string is upper [string range $phrase $z $z]]} { + set phrase [string tolower $phrase $z $z] + return $phrase + } else { + return + } + } else { + return + } + } else { + return -1 + } +} + +proc howlongsince {secs {fmt "%H:%M:%S"}} { + + #I'm too lazy to do leap years =P + #I'm also too lazy to do the rigth number of days in months (28/29, 30, 31 days) + + set days [expr {$secs/86400}] ; set Days [string range "0$days" end-1 end] + set hours [expr {($secs%86400)/3600}] ; set Hours [string range "0$hours" end-1 end] + set minutes [expr {(($secs%86400)%3600)/60}] ; set Minutes [string range "0$minutes" end-1 end] + set seconds [expr {(($secs%86400)%3600)%60}] ; set Seconds [string range "0$seconds" end-2 end] + + if { [expr $days > 365]} { + set months [expr {$days/30}] ; set Months [string range "0$months" end-1 end] + set days [expr $days-($months*30)] ; set Days [string range "0$days" end-1 end] + if { [expr $months > 12]} { + set years [expr {$months/12}] ; set Years [string range "0$years" end-1 end] + set months [expr $months-($years*12)] ; set Months [string range "0$months" end-1 end] + } else { + set years 0 ; set Years [string range "0$years" end-1 end] + } + } else { + set years 0 ; set Years [string range "0$years" end-1 end] + set months [expr {$days/30}] ; set Months [string range "0$months" end-1 end] + set days [expr {$days-($months*30)}] ; set Days [string range "0$days" end-1 end] + } + + set p "%% % %s $seconds %S $Seconds %m $minutes %M $Minutes %h $hours %H $Hours %d $days %D $Days %n $months %N $Months %y $years %Y $Years" + set str [string map $p $fmt] + return $str +} + proc stringDistance {a b} { set n [string length $a] set m [string length $b] @@ -69,19 +127,349 @@ } proc getPage {url} { - package require http - ::http::config -useragent "Monkey cmdline tool (OpenBSD; en)" - if {[catch {set token [::http::geturl $url]} msg]} { - return "Error: $msg" - } else { - set data [::http::data $token] - } - return $data + package require http + ::http::config -useragent "Monkey cmdline tool (OpenBSD; en)" + if {[catch {set token [::http::geturl $url]} msg]} { + return "Error: $msg" + } else { + set data [::http::data $token] + } + ::http::cleanup $token + return $data } +proc html2text {str} { + regsub -all {<em>} $str "" str + regsub -all {</em>} $str "" str + regsub -all {<b>} $str "" str + regsub -all {</b>} $str "" str + regsub -all {"} $str "\"" str + regsub -all {>} $str ">" str + regsub -all {<} $str "<" str + regsub -all {ñ} $str "ñ" str + regsub -all {Ñ} $str "Ñ" str + regsub -all {&} $str "\\&" str + regsub -all {´} $str "'" str + regsub -all {á} $str "á" str + regsub -all {Á} $str "Á" str + regsub -all {à} $str "à" str + regsub -all {À} $str "À" str + regsub -all {â} $str "â" str + regsub -all {Â} $str "Â" str + regsub -all {ä} $str "ä" str + regsub -all {Ä} $str "Ä" str + regsub -all {Ã} $str "Ã" str + regsub -all {ã} $str "ã" str + regsub -all {ç} $str "ç" str + regsub -all {€} $str "€" str + regsub -all {è} $str "è" str + regsub -all {È} $str "È" str + regsub -all {ê} $str "ê" str + regsub -all {Ê} $str "Ê" str + regsub -all {ë} $str "ë" str + regsub -all {Ë} $str "Ë" str + regsub -all {Õ} $str "Õ" str + regsub -all {Ç} $str "Ç" str + regsub -all {¥} $str "¥" str + regsub -all {ˆ} $str "ˆ" str + regsub -all {ì} $str "ì" str + regsub -all {Ì} $str "Ì" str + regsub -all {î} $str "î" str + regsub -all {Î} $str "Î" str + regsub -all {Ï} $str "Ï" str + regsub -all {©} $str "©" str + regsub -all {£} $str "£" str + regsub -all {ò} $str "ò" str + regsub -all {Ò} $str "Ò" str + regsub -all {Ô} $str "Ô" str + regsub -all {ô} $str "ô" str + regsub -all {ö} $str "ö" str + regsub -all {Ö} $str "Ö" str + regsub -all {å} $str "å" str + regsub -all {Å} $str "Å" str + regsub -all {®} $str "®" str + regsub -all {¢} $str "¢" str + regsub -all {ù} $str "ù" str + regsub -all {Ù} $str "Ù" str + regsub -all {û} $str "û" str + regsub -all {Û} $str "Û" str + regsub -all {ü} $str "ü" str + regsub -all {Ü} $str "Ü" str + regsub -all {ø} $str "ø" str + regsub -all {Ø} $str "Ø" str + regsub -all {™} $str "™" str + regsub -all {°} $str "°" str + regsub -all {ý} $str "ý" str + regsub -all {ÿ} $str "ÿ" str + regsub -all {Ÿ} $str "Ÿ" str + regsub -all {š} $str "š" str + regsub -all {Š} $str "Š" str + regsub -all {é} $str "é" str + regsub -all {É} $str "É" str + regsub -all {í} $str "í" str + regsub -all {Í} $str "Í" str + regsub -all {ó} $str "ó" str + regsub -all {Ó} $str "Ó" str + regsub -all {ú} $str "ú" str + regsub -all {Ú} $str "Ú" str + regsub -all {ü} $str "ü" str + regsub -all {Ü} $str "Ü" str + regsub -all {¤} $str "¤" str + + return $str +} + +proc searchInGoogle {str} { + set botname $::jake::config(botname) + set nresults $::jake::config(nresults) + set language [::config::getGlobalKey language] + set link "http://www.google.com/search?hl=" + append link $language&num=$nresults&q=$str + set salida [ getPage $link ] + if { [string first "Error: " $salida] != 0 } { + set matches [regexp -all -inline {(<li class=g>.*<a [^>]*>.*</a>)+?} $salida] + set count 0 + set bool 0 + foreach m $matches { + regexp {href="([^"]*)[^>]*>(.*)</a>} $m => url title + regsub -all {/url\?q=} $url "" url + set url [html2text $url] + set title [html2text $title] + if { $bool == 0 && $count < $nresults } { + incr count + append final $count.\ $title " - " $url \n\n + set bool 1 + } else { + set bool 0 + } + } + set output "$botname: \n\n$final" + } else { + set output "$botname: Error: $salida" + } + return $output +} + +proc searchInMegaupload {str} { + set botname $::jake::config(botname) + set nresults $::jake::config(nresults) + set link "http://4megaupload.com/index.php?q=" + append link $str + set salida [ getPage $link ] + if { [string first "Error: " $salida] != 0 } { + set matches [regexp -all -inline {(<td bgcolor="#ECF7FF" rowspan="4".*</font>)+?} $salida] + set count 0 + set bool 0 + foreach m $matches { + regexp {href="([^"]*).*title='([^']*).*>(.*)</font>} $m => url title size + regsub -all {/url\?q=} $url "" url + regsub -all { +} $url "" url + set title [html2text $title] + if { $bool == 0 && $count < $nresults } { + incr count + append final $count.\ $title " - [string trim $size] - http://4megaupload.com/" $url \n\n + set bool 1 + } else { + set bool 0 + } + } + set output "$botname: \n\n$final" + } else { + set output "$botname: Error: $salida" + } + return $output +} + +proc searchInYoutube {str} { + set botname $::jake::config(botname) + set nresults $::jake::config(nresults) + set link "http://www.youtube.com/results?search_type=&search_query=" + append link $str + set salida [ getPage $link ] + if { [string first "Error: " $salida] != 0 } { + set matches [regexp -all -inline {(<div class="v120WrapperInner">.* src)+?} $salida] + set count 0 + set bool 0 + foreach m $matches { + regexp {href="([^"]*).*title="([^"]*)} $m => url title + regsub -all {/url\?q=} $url "" url + set title [html2text $title] + if { $bool == 0 && $count < $nresults } { + incr count + append final $count.\ $title " - www.youtube.com" $url \n\n + set bool 1 + } else { + set bool 0 + } + } + set output "$botname: \n\n$final" + } else { + set output "$botname: Error: $salida" + } + return $output +} + +proc defineInGoogle {str} { + set botname $::jake::config(botname) + set nresults $::jake::config(nresults) + set language [::config::getGlobalKey language] + set link "http://www.google.com/search?hl=" + append link $language&q=define:$str + set salida [ getPage $link ] + if { [string first "Error: " $salida] != 0 } { + set matches [regexp -all -inline {(<li>.*<br><a href=.*><font)+?} $salida] + set count 0 + set bool 0 + foreach m $matches { + regexp {<li>([^<]*)(.*)><font} $m => title url + regsub -all {<br>.*q=} $url "" url + regsub -all {\"} $url "" url + set title [html2text $title] + if { $bool == 0 && $count < $nresults } { + incr count + append final $count.\ $title " - " $url \n\n + set bool 1 + } else { + set bool 0 + } + } + set output "$botname: \n\n$final" + } else { + set output "$botname: Error: $salida" + } + return $output +} + +proc searchInGoear {str} { + set botname $::jake::config(botname) + set nresults $::jake::config(nresults) + set link "http://www.goear.com/search.php?q=" + append link $str + set salida [ getPage $link ] + if { [string first "Error: " $salida] != 0 } { + set matches [regexp -all -inline {(<strong>.*class="escuchar">)+?} $salida] + set count 0 + set bool 0 + foreach m $matches { + regexp {<strong><a title="([^"]*).*href="([^"]*)} $m => title url + regsub -all {<br>.*q=} $url "" url + regsub -all {\"} $url "" url + set title [html2text $title] + if { $bool == 0 && $count < $nresults } { + incr count + set goearLink "http://www.goear.com/" + append goearLink $url + regexp {listen/(.*?)/} $goearLink -> id + set output [ getPage "http://www.goear.com/files/xmlfiles/[string index $id 0]/secm$id.xml" ] + regexp {path=\"(.*?)\"} $output -> downloadlink + append final $count.\ $title " - " $downloadlink "\n\n" + set bool 1 + } else { + set bool 0 + } + } + set output "$botname: \n\n$final" + } else { + set output "$botname: Error: $salida" + } + return $output +} + +proc translateWithGoogle {lng txt} { + set botname $::jake::config(botname) + set languages([trans lngalbanian]) sq + set languages([trans lngarabic]) ar + set languages([trans lngarmenian]) hy + set languages([trans lngbasque]) eu + set languages([trans lngbelarusian]) be + set languages([trans lngbengali]) bn + set languages([trans lngbosnian]) bs + set languages([trans lngbreton]) br + set languages([trans lngbulgarian]) bg + set languages([trans lngcatalan]) ca + set languages([trans lngchinese-simplified]) zh-CN + set languages([trans lngchinese-traditional]) zh-TW + set languages([trans lngcroatian]) hr + set languages([trans lngczech]) cs + set languages([trans lngdanish]) da + set languages([trans lngdutch]) nl + set languages([trans lngenglish]) en + set languages([trans lngesperanto]) eo + set languages([trans lngfilipino]) tl + set languages([trans lngfinnish]) fi + set languages([trans lngfrench]) fr + set languages([trans lnggalician]) gl + set languages([trans lnggerman]) de + set languages([trans lnggreek]) el + set languages([trans lnghebrew]) iw + set languages([trans lnghungarian]) hu + set languages([trans lngirish]) ga + set languages([trans lngitalian]) it + set languages([trans lngjapanese]) ja + set languages([trans lngkorean]) ko + set languages([trans lnglatin]) la + set languages([trans lnglithuanian]) lt + set languages([trans lngmacedonian]) mk + set languages([trans lngmongolian]) mn + set languages([trans lngnorwegian]) no + set languages([trans lngpersian]) fa + set languages([trans lngpolish]) pl + set languages([trans lngportuguese-brazil]) pt-BR + set languages([trans lngportuguese-portugal]) pt-PT + set languages([trans lngromanian]) ro + set languages([trans lngrussian]) ru + set languages([trans lngscots]) gd + set languages([trans lngserbian]) sr + set languages([trans lngserbo-croatian]) sh + set languages([trans lngslovak]) sk + set languages([trans lngslovenian]) sl + set languages([trans lngspanish]) es + set languages([trans lngswedish]) sv + set languages([trans lngturkish]) tr + set languages([trans lngukrainian]) uk + set languages([trans lngvietnamese]) vi + set languages([trans lngwelsh]) cy + if { [info exists languages($lng)] } { + + set query [http::formatQuery q $txt v 1.0] + set token [::http::geturl http://www.google.com/uds/GlangDetect?$query -query] + set data [::http::data $token] + regexp {\"language\":\"(.*?)\",\"} $data -> from + + set query [::http::formatQuery v 1.0 q $txt langpair $from|$languages($lng)] + set token [::http::geturl http://ajax.googleapis.com/ajax/services/language/translate?$query -query] + set data [::http::data $token] + regexp {\"translatedText\":\"(.*?)\"\}} $data -> str + + set output "$botname: \n\n$str" + } else { + set output "$botname: \n\n[trans errlng] $lng." + } + return $output +} + +proc isuseroff {chatid} { + set i 0 + set in [open [file join $::HOME "jake" "off.conf"] r] + while { [gets $in line] >= 0 } { + if { [string match $chatid $line] == 1 } { + set i 1 + } + } + close $in + if { $i == 0 } { + return 0 + } else { + return 1 + } +} + proc answer {event epvar} { global mydir + global birthday + global starttime + upvar 2 $epvar args upvar 2 $args(msg) msg upvar 2 $args(chatid) chatid @@ -89,26 +477,75 @@ set me [::abook::getPersonal login] set window [::ChatWindow::For $chatid] set botname $::jake::config(botname) - set mystate $::jake::config(mystate) set nresults $::jake::config(nresults) set language [::config::getGlobalKey language] - if { $user==$me && $msg == "![trans cmdon]" } { - set ::jake::config(mystate) 1 + if { $msg == "![trans cmdon]" } { + if { [isuseroff $chatid] == 1 } { + set in [open [file join $::HOME "jake" "off.conf"] r] + set out [open [file join $::HOME "jake" "off.conf.tmp"] w] + while { [gets $in line] >= 0 } { + if { [string match $chatid $line] == 0 } { + puts $out $line + } + } + close $in + close $out + file delete -force [file join $::HOME "jake" "off.conf"] + file rename -force [file join $::HOME "jake" "off.conf.tmp"] [file join $::HOME "jake" "off.conf"] + } plugins_log jake "Plugin Jake activado!" - #set first 1 ::amsn::MessageSend $window 0 "$botname: [trans msgon]" - } elseif { $user==$me && $msg == "![trans cmdoff]" } { - set ::jake::config(mystate) 0 + } elseif { $msg == "![trans cmdoff]" } { + set in [open [file join $::HOME "jake" "off.conf"] a+] + if { ![isuseroff $chatid] } { + puts $in $chatid + } + close $in plugins_log jake "Plugin Jake desactivado" ::amsn::MessageSend $window 0 "$botname: [trans msgoff]" - } elseif { $user!=$me && ($msg == "![trans cmdoff]" || $msg == "![trans cmdon]") } { - ::amsn::MessageSend $window 0 "$botname: [trans msgonoff]" } elseif { $msg == "![trans cmdstate]" } { - if { $mystate == 0 } { - ::amsn::MessageSend $window 0 "$botname: [trans msgoff]" + set format "" + append format {%y } + append format [trans txtyears] + append format {, %n } + append format [trans txtmonths] + append format {, %d } + append format [trans txtdays] + append format {, %h } + append format [trans txthours] + append format {, %m } + append format [trans txtminutes] + append format {, %s } + append format [trans txtseconds] + + set now [clock seconds] + #uptime + set diffuptime [expr {$now-$starttime}] + set howlonguptime [howlongsince $diffuptime $format] + set uptime [trans txtuptime] + append uptime " " $howlonguptime + #lifetime + set diffalive [expr {$now-$birthday}] + set howlongalive [howlongsince $diffalive $format] + set lifetime [trans txtlifetime] + append lifetime " " $howlongalive + #version info + set version [trans txtversion] + append version "0.8 BETA" + #dictionary size info + if { [array exists dictionary] == 0 } { + source [file join $::HOME "jake" "dictionary.dic"] + } + set dictionarysize [trans txtdictionarysize] + append dictionarysize [array size dictionary] + append dictionarysize " [trans txtreg]" + if { [isuseroff $chatid] } { + set state "[trans msgoff]" + ::amsn::MessageSend $window 0 "$botname: \n\n$state\n$version\n$dictionarysize\n$uptime\n$lifetime" } else { - ::amsn::MessageSend $window 0 "$botname: [trans msgon]" + set state "[trans msgon]" + ::amsn::MessageSend $window 0 "$botname: \n\n$state\n$version\n$dictionarysize\n$uptime\n$lifetime" } } elseif { $msg == "![trans cmdhelp]" } { ::amsn::MessageSend $window 0 "$botname: $::jake::config(helptxt)\n\ @@ -125,169 +562,101 @@ ![trans cmdforget] [trans cmdargsforget] - [trans txtforget] $botname\n\ ![trans cmdyoutube] [trans cmdargsyoutube] - [trans txtyoutube]\n\ ![trans cmdexpr] [trans cmdargsexpr] - [trans txtexpr]\n\ - ![trans cmdmegaupload] [trans cmdargsmegaupload] - [trans txtmegaupload]" + ![trans cmdmegaupload] [trans cmdargsmegaupload] - [trans txtmegaupload]\n\ + ![trans cmdmp3] [trans cmdargsmp3] - [trans txtmp3]\n\ + ![trans cmdtranslate] [trans cmdargstranslate] - [trans txttranslate]" } elseif { $msg == "![trans cmdhour]" } { ::amsn::MessageSend $window 0 "$botname: [trans rsphour] [clock format [clock seconds] -format {%H:%M:%S}]" } elseif { $msg == "![trans cmddate]" } { ::amsn::MessageSend $window 0 "$botname: [trans rspdate] [clock format [clock seconds] -format {%d/%m/%Y}]" - } elseif { [string first "![trans cmdgoogle] " $msg] == 0 } { - regsub -all { +} [string range $msg [expr [string length [trans cmdgoogle]] + 2] end] "+" msg - set link "http://www.google.com/search?hl=" - append link $language&num=$nresults&q=$msg - set salida [ getPage $link ] - if { [string first "Error: " $salida] != 0 } { - set matches [regexp -all -inline {(<li class=g>.*<a [^>]*>.*</a>)+?} $salida] - set count 0 - set bool 0 - foreach m $matches { - regexp {href="([^"]*)[^>]*>(.*)</a>} $m => url title - regsub -all {/url\?q=} $url "" url - regsub -all {<em>} $title "" title - regsub -all {</em>} $title "" title - regsub -all {<b>} $title "" title - regsub -all {</b>} $title "" title - regsub -all {"} $title "" title - regsub -all {>} $title "" title - if { $bool == 0 && $count < $nresults } { - incr count - append final $count.\ $title " - " $url \n\n - set bool 1 - } else { - set bool 0 - } - } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" - } else { - ::amns::MessageSend $window 0 "$botname: Error: $salida" - } + } elseif { [string first "![trans cmdgoogle] " $msg] == 0 } { + set commandLength [expr [string length [trans cmdgoogle]] + 2] + set strWithoutCommand [string range $msg $commandLength end] + regsub -all { +} $strWithoutCommand "+" str + set output [searchInGoogle $str] + ::amsn::MessageSend $window 0 $output } elseif { [string first "![trans cmdmegaupload] " $msg] == 0 } { - regsub -all { +} [string range $msg [expr [string length [trans cmdmegaupload]] + 2] end] "+" msg - set link "http://4megaupload.com/index.php?q=" - append link $msg - set salida [ getPage $link ] - if { [string first "Error: " $salida] != 0 } { - set matches [regexp -all -inline {(<td bgcolor="#ECF7FF" rowspan="4".*</font>)+?} $salida] - set count 0 - set bool 0 - foreach m $matches { - regexp {href="([^"]*).*title='([^']*).*>(.*)</font>} $m => url title size - regsub -all {/url\?q=} $url "" url - regsub -all { +} $url "" url - regsub -all {<em>} $title "" title - regsub -all {</em>} $title "" title - regsub -all {<b>} $title "" title - regsub -all {</b>} $title "" title - regsub -all {"} $title "" title - regsub -all {>} $title "" title - if { $bool == 0 && $count < $nresults } { - incr count - append final $count.\ $title " - [string trim $size] - http://4megaupload.com/" $url \n\n - set bool 1 - } else { - set bool 0 - } - } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" - } else { - ::amns::MessageSend $window 0 "$botname: Error: $salida" - } + set commandLength [expr [string length [trans cmdmegaupload]] + 2] + set strWithoutCommand [string range $msg $commandLength end] + regsub -all { +} $strWithoutCommand "+" str + set output [searchInMegaupload $str] + ::amsn::MessageSend $window 0 $output } elseif { [string first "![trans cmdyoutube] " $msg] == 0 } { - regsub -all { +} [string range $msg [expr [string length [trans cmdyoutube]] + 2] end] "+" msg - set link "http://www.youtube.com/results?search_type=&search_query=" - append link $msg - set salida [ getPage $link ] - if { [string first "Error: " $salida] != 0 } { - set matches [regexp -all -inline {(<div class="v120WrapperInner">.* src)+?} $salida] - set count 0 - set bool 0 - foreach m $matches { - regexp {href="([^"]*).*title="([^"]*)} $m => url title - regsub -all {/url\?q=} $url "" url - regsub -all {<em>} $title "" title - regsub -all {</em>} $title "" title - regsub -all {<b>} $title "" title - regsub -all {</b>} $title "" title - regsub -all {"} $title "" title - regsub -all {>} $title "" title - if { $bool == 0 && $count < $nresults } { - incr count - append final $count.\ $title " - www.youtube.com" $url \n\n - set bool 1 - } else { - set bool 0 - } - } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" - } else { - ::amns::MessageSend $window 0 "$botname: Error: $salida" + set commandLength [expr [string length [trans cmdyoutube]] + 2] + set strWithoutCommand [string range $msg $commandLength end] + regsub -all { +} $strWithoutCommand "+" str + set output [searchInYoutube $str] + ::amsn::MessageSend $window 0 $output + } elseif { [string first "![trans cmddefine] " $msg] == 0 } { + set commandLength [expr [string length [trans cmddefine]] + 2] + set strWithoutCommand [string range $msg $commandLength end] + regsub -all { +} $strWithoutCommand "+" str + set output [defineInGoogle $str] + ::amsn::MessageSend $window 0 $output + } elseif { [string first "![trans cmdlearn] " $msg] == 0 } { + if { [array exists dictionary] == 0 } { + source [file join $::HOME "jake" "dictionary.dic"] } - } elseif { [string first "![trans cmddefine] " $msg] == 0 } { - regsub -all { +} [string range $msg [expr [string length [trans cmddefine]] + 2] end] "+" msg - set link "http://www.google.com/search?hl=" - append link $language&q=define:$msg - set salida [ getPage $link ] - if { [string first "Error: " $salida] != 0 } { - set matches [regexp -all -inline {(<li>.*<br><a href=.*><font)+?} $salida] - set count 0 - set bool 0 - foreach m $matches { - regexp {<li>([^<]*)(.*)><font} $m => title url - regsub -all {<br>.*q=} $url "" url - regsub -all {\"} $url "" url - regsub -all {<em>} $title "" title - regsub -all {</em>} $title "" title - regsub -all {<b>} $title "" title - regsub -all {</b>} $title "" title - regsub -all {"} $title "" title - if { $bool == 0 && $count < $nresults } { - incr count - append final $count.\ $title " - " $url \n\n - set bool 1 + set commandLength [expr [string length [trans cmdlearn]] + 2] + set msg [string range $msg $commandLength end] + if { [regexp -- {^"[^"]*" "[^"]*"$} $msg] } { + + set originalMsg $msg + regexp {\"(.*?)\" \"} $msg -> originalPhrase + regsub -all {\"} $originalPhrase "\\\"" phrase + + set x 0 + set z 0 + while {$x<1} { + if {[info exists dictionary($phrase)] == 1} { + set phrase [alterString $phrase $z] + if {[string equal $phrase "-1"]} { + ::amsn::MessageSend $window 0 "$botname: [trans erradd]" + return + } else { + incr z + } } else { - set bool 0 + set msg [string map "$originalPhrase $phrase" $originalMsg] + set msg [string range $msg 1 end] + regsub -all {\" \"} $msg ")\" \"" msg + set fileId [open [file join $::HOME "jake" "dictionary.dic"] "a+"] + puts $fileId "set \"dictionary($msg" + close $fileId + source [file join $::HOME "jake" "dictionary.dic"] + ::amsn::MessageSend $window 0 "$botname: [trans txtregadd] [array size dictionary] [trans txtreg]" + incr x } } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" + } else { - ::amns::MessageSend $window 0 "$botname: Error: $salida" - } - } elseif { [string first "![trans cmdlearn] " $msg] == 0 } { - set msg [string range $msg [expr [string length [trans cmdlearn]] + 2] end] - if { [regexp -- {^"[^"]*" "[^"]*"$} $msg] } { - set msg [string range $msg 1 end] - regsub -all {\" \"} $msg ")\" \"" msg - set fileId [open [file join $::HOME "diccionario.dic"] "a+"] - puts $fileId "set \"diccionario($msg" - close $fileId - source [file join $::HOME diccionario.dic] - ::amsn::MessageSend $window 0 "$botname: [trans txtregadd] [array size diccionario] [trans txtreg]" - } else { ::amsn::MessageSend $window 0 "$botname: [trans cmderror]\n\ [trans txthelplearn] ![trans cmdlearn] [trans cmdargslearn]" } } elseif { [string first "![trans cmdforget] " $msg] == 0 } { - set msg [string range $msg [expr [string length [trans cmdforget]] + 2] end] + set commandLength [expr [string length [trans cmdforget]] + 2] + set msg [string range $msg $commandLength end] if { [regexp -- {^".*"$} $msg] } { - if { [array exists diccionario] == 0 } { - source [file join $::HOME diccionario.dic] + if { [array exists dictionary] == 0 } { + source [file join $::HOME "jake" "dictionary.dic"] } regsub -all {\"} $msg "" msg - set in [open [file join $::HOME diccionario.dic] r] - set out [open [file join $::HOME diccionario.dic.tmp] w] + set in [open [file join $::HOME "jake" "dictionary.dic"] r] + set out [open [file join $::HOME "jake" "dictionary.dic.tmp"] w] set i 0 while { [gets $in line] >= 0 } { incr i - if { [string match "set \"diccionario($msg)\"*" $line] == 0 } { + if { [string match "set \"dictionary($msg)\"*" $line] == 0 } { puts $out $line } } close $in close $out - file delete -force [file join $::HOME diccionario.dic] - file rename -force [file join $::HOME diccionario.dic.tmp] [file join $::HOME diccionario.dic] - array unset diccionario - source [file join $::HOME diccionario.dic] - set in [open [file join $::HOME diccionario.dic] r] + file delete -force [file join $::HOME "jake" "dictionary.dic"] + file rename -force [file join $::HOME "jake" "dictionary.dic.tmp"] [file join $::HOME "jake" "dictionary.dic"] + array unset dictionary + source [file join $::HOME "jake" "dictionary.dic"] + set in [open [file join $::HOME "jake" "dictionary.dic"] r] set j 0 while { [gets $in line] >= 0 } { incr j @@ -297,33 +666,49 @@ ::amsn::MessageSend $window 0 "$botname: [trans cmderror]\n\ [trans txthelpforget] ![trans cmdforget] [trans cmdargsforget]" } - } elseif { [string first "![trans cmdexpr ]" $msg] == 0 } { - set msg [string range $msg [expr [string length [trans cmdexpr]] + 2] end] + } elseif { [string first "![trans cmdexpr] " $msg] == 0 } { + set commandLength [expr [string length [trans cmdexpr]] + 2] + set msg [string range $msg $commandLength end] if { [string first "[trans cmdhelp]" $msg] == 0 } { ::amsn::MessageSend $window 0 "$botname: \n\n\ [trans txtexprhelp]" } else { - ::amsn::MessageSend $window 0 "$botname: [trans txtsolution] [expr $msg]" + ::amsn::MessageSend $window 0 "$botname: [trans txtsolution] [expr [string map {/ *1./} $msg]]" } - } elseif { $mystate == 1 } { - if { $user != $me } { - if { [array exists diccionario] == 0 } { - source [file join $::HOME diccionario.dic] + } elseif { [string first "![trans cmdmp3] " $msg] == 0 } { + set commandLength [expr [string length [trans cmdmp3]] + 2] + set strWithoutCommand [string range $msg $commandLength end] + regsub -all { +} $strWithoutCommand "+" str + set output [searchInGoear $str] + append output "[trans txthelpdownload]" + ::amsn::MessageSend $window 0 $output + } elseif { [string first "![trans cmdtranslate] " $msg] == 0 } { + set commandLength [expr [string length [trans cmdtranslate]] + 2] + set str [string range $msg $commandLength end] + set lngstartpos [string first " " $str] + set lng [string range $str 0 [expr $lngstartpos - 1]] + set txt [string range $str [expr $lngstartpos + 1] end] + set output [translateWithGoogle $lng $txt] + ::amsn::MessageSend $window 0 $output + } elseif { [string first "!envia " $msg] == 0 } { + #test + } elseif { $user != $me && [isuseroff $chatid] == 0} { + if { [array exists dictionary] == 0 } { + source [file join $::HOME "jake" "dictionary.dic"] + } + set i 1 + foreach index [array names dictionary] { + if { [expr ([stringSimilarity $msg $index ]) > 0.6] } { + set respuesta($i) $dictionary($index) + incr i } - set i 1 - foreach index [array names diccionario] { - if { [expr ([stringSimilarity $msg $index ]) > 0.6] } { - set respuesta($i) $diccionario($index) - incr i - } + } + if { $i > 1 } { + ::amsn::MessageSend $window 0 "$botname: $respuesta([rand [array size respuesta] 1])" + } else { + if { [rand 5 1] == 1 } { + ::amsn::MessageSend $window 0 "$botname: [trans txtneedhelp]" } - if { $i > 1 } { - ::amsn::MessageSend $window 0 "$botname: $respuesta([rand [array size respuesta] 1])" - } else { - if { [rand 5 1] == 1 } { - ::amsn::MessageSend $window 0 "$botname: [trans txtneedhelp]" - } - } } } } @@ -342,6 +727,4 @@ } } -} - - +} \ No newline at end of file Modified: trunk/amsn-extras/plugins/jake/lang/langen =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langen 2009-06-25 16:43:03 UTC (rev 11275) +++ trunk/amsn-extras/plugins/jake/lang/langen 2009-06-26 13:20:31 UTC (rev 11276) @@ -10,7 +10,6 @@ msgon I'm on. msgoff I'm off. -msgonoff Only mi creator can turn me on or off. cmdstate state cmdhelp help @@ -26,6 +25,9 @@ cmderror Syntaxis error. cmdexpr expr cmdmegaupload megaupload +cmdmp3 song +cmddownloadyoutube download youtube +cmdtranslate translate to cmdargsdefine word/s cmdargsgoogle word/s @@ -34,6 +36,8 @@ cmdargsyoutube word/s cmdargsexpr Any math expression. cmdargsmegaupload file/s +cmdargsmp3 Artist and/or title. +cmdargstranslate language text txtcommands Available commands: txthelp Shows this message. @@ -61,6 +65,76 @@ txtsolution The solution is: txtexprhelp abs( x ) - Absolute value (negate if negative.)\n acos( x ) - Inverse cosine (result in radians.)\n asin( x ) - Inverse sine (result in radians.)\n atan( x ) - Inverse tangent (result in radians.)\n atan2( y , x ) - Inverse tangent (result in radians.)\n ceil( x ) - Ceiling (defined over floating point numbers.)\n cos( x ) - Cosine (input in radians.)\n cosh( x ) - Hyperbolic cosine.\n double( x ) - Convert number to floating point.\n exp( x ) - Exponential function.\n floor( x ) - Floor (defined over floating point numbers.)\n fmod( x ) - Floating point remainder.\n hypot( x , y ) - Hypotenuse calculator.\n int( x ) - Convert number to integer by truncation.\n log( x ) - Natural logarithm.\n log10( x ) - Logarithm with respect to base 10.\n pow( x , y ) - Power function.\n rand( ) - Random number. Uses uniform distribution over the range [0,1].\n round( x ) - Round to nearest whole number.\n sin( x ) - Sine (input in radians.)\n sinh( x ) - Hyperbolic sine.\n sqrt( x ) - Square root.\n srand( x ) - Seeds the random number generator with the given value.\n tan( x ) - Tangent (input in radians.)\n tanh( x ) - Hyperbolic tangent. txtmegaupload Search files in MegaUpload's base. +txtmp3 Search for a direct link to listen/download the searched song. +txtdownloadlink Download link: +txthelpdownload To download, once opened your web browser, go to File -> Save as... and save the file. +txttranslate Translate a given text to another language. +txtuptime Started since: +txtlifetime Alive since: +txtyears years +txtmonths months +txtdays days +txthours hours +txtminutes minutes +txtseconds seconds +txtversion Version: +txtdictionarysize Size of dictionary: rsphour The time is rspdate The date is + +errlng Sorry, but I don't know +erradd The word was not added because there are already the maximum possible answers for the length of the word. + +lngalbanian albanian +lngarabic arabic +lngarmenian armenian +lngbasque basque +lngbelarusian belarusian +lngbengali bengali +lngbosnian bosnian +lngbreton breton +lngbulgarian bulgarian +lngcatalan catalan +lngchinese-simplified chinese-simplified +lngchinese-traditional chinese-traditional +lngcroatian croatian +lngczech czech +lngdanish danish +lngdutch dutch +lngenglish english +lngesperanto esperanto +lngfilipino filipino +lngfinnish finnish +lngfrench french +lnggalician galician +lnggerman german +lnggreek greek +lnghebrew hebrew +lnghungarian hungarian +lngirish irish +lngitalian italian +lngjapanese japanese +lngkorean korean +lnglatin latin +lnglithuanian lithuanian +lngmacedonian macedonian +lngmongolian mongolian +lngnorwegian norwegian +lngpersian persian +lngpolish polish +lngportuguese-brazil portuguese-brazil +lngportuguese-portugal portuguese +lngromanian romanian +lngrussian russian +lngscots escots +lngserbian serbian +lngserbo-croatian serbo-croatian +lngslovak eslovaK +lngslovenian eslovenian +lngspanish spanish +lngswedish swedish +lngturkish turkish +lngukrainian ukrainian +lngvietnamese vietnamese +lngwelsh welsh \ No newline at end of file Modified: trunk/amsn-extras/plugins/jake/lang/langes =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langes 2009-06-25 16:43:03 UTC (rev 11275) +++ trunk/amsn-extras/plugins/jake/lang/langes 2009-06-26 13:20:31 UTC (rev 11276) @@ -10,7 +10,6 @@ msgon Estoy activado. msgoff Estoy desactivado. -msgonoff Solo mi credor puede activarme y desactivarme. cmdstate estado cmdhelp ayuda @@ -26,6 +25,8 @@ cmderror Error en la sintaxis del comando. cmdexpr expr cmdmegaupload megaupload +cmdmp3 cancion +cmdtranslate traduce a cmdargsgoogle palabra/s cmdargsdefine palabra/s @@ -34,6 +35,8 @@ cmdargsyoutube palabra/s cmdargsexpr Cualquiera expresion matematica. cmdargsmegaupload archivo/s +cmdargsmp3 Artista y/o titulo. +cmdargstranslate idioma texto txtcommands Comandos disponibles: txthelp Muestra este mensaje. @@ -61,6 +64,77 @@ txtsolution La solucion es: txtexprhelp abs( x ) - Valor absoluto (negativo si es negativo.)\n acos( x ) - Arcocoseno (resultado en radianes.)\n asin( x ) - Arcoseno (resultado en radianes.)\n atan( x ) - Arcotangente (resultado en radianes.)\n atan2( y , x ) - Arcotangente (resultado en radianes.)\n ceil( x ) - Redondeo a la alta (se debe usar con numeros decimales.)\n cos( x ) - Coseno (se debe usar con radianes.)\n cosh( x ) - Coseno hiperbolico.\n double( x ) - Convierte enteros a decimales.\n exp( x ) - Funccion exponencial.\n floor( x ) - Redondeo a la baja (se debe usar con numeros decimales.)\n fmod( x ) - Punto flotante.\n hypot( x , y ) - Calculador de la hipotenusa.\n int( x ) - Convierte numeros a enteros, sin redondear.\n log( x ) - Logaritmo.\n log10( x ) - Logaritmo en base 10.\n pow( x , y ) - Potencia.\n rand( ) - Numero aleatorio. Aleatoriaridad en el rango [0,1].\n round( x ) - Redondea.\n sin( x ) - Seno (se debe usar con radianes.)\n sinh( x ) - Seno hiperbolico.\n sqrt( x ) - Raiz cuadrada.\n srand( x ) - Numero aleatorio.\n tan( x ) - Tangente (se debe usar con radianes.)\n tanh( x ) - Tangente hiperbolico. txtmegaupload Busca en la base de MegaUpload. +txtmp3 Busca un enlace directo para escuchar/descargar el mp3 buscado. +txtdownloadlink Link de descarga: +txthelpdownload Para descargar, una vez abierto el navegador, haz click en Archivo -> Guardar como... y guarda el archivo. +txthelptranslate Error en la sintaxis del comando. La forma correcta de usar el traductor es: !traduce xx-yy texto, donde xx es el idioma actual e yy es el idioma al que se quiere traducir. Idiomas soportados: en (Ingles), es (Español), fr (Frances), it (Italiano), gr (Aleman) +txttranslate Traducir un texto dado a otro idioma. +txtuptime Iniciado hace: +txtlifetime Vivo desde hace: +txtyears años +txtmonths meses +txtdays dias +txthours horas +txtminutes minutos +txtseconds secundos +txtversion Version: +txtdictionarysize Tamaño del diccionario: rsphour La hora es -rspdate La fecha es \ No newline at end of file +rspdate La fecha es + +errlng Lo siento, pero no se +erradd No se ha podido agregar la palabra porque ya se han alcanzado el maximo numero de posibles respuestas para la longitud de dicha palabra. + +lngalbanian albanes +lngarabic arabe +lngarmenian armenio +lngbasque vasco +lngbelarusian bielorruso +lngbengali bengali +lngbosnian bosnio +lngbreton breton +lngbulgarian bulgaro +lngcatalan catalan +lngchinese-simplified chino-simplificado +lngchinese-traditional chino-tradicional +lngcroatian croata +lngczech checo +lngdanish danes +lngdutch holandes +lngenglish ingles +lngesperanto esperanto +lngfilipino filipino +lngfinnish finlandes +lngfrench frances +lnggalician gallego +lnggerman aleman +lnggreek griego +lnghebrew hebreo +lnghungarian hungaro +lngirish irlandes +lngitalian italiano +lngjapanese japones +lngkorean coreano +lnglatin latin +lnglithuanian lituano +lngmacedonian macedonio +lngmongolian mongol +lngnorwegian noruego +lngpersian persa +lngpolish polaco +lngportuguese-brazil portugues-brazil +lngportuguese-portugal portugues +lngromanian rumano +lngrussian ruso +lngscots escoces +lngserbian serbio +lngserbo-croatian serbocroata +lngslovak eslovaco +lngslovenian esloveno +lngspanish español +lngswedish sueco +lngturkish turco +lngukrainian ucraniano +lngvietnamese vietnamita +lngwelsh gales \ No newline at end of file Modified: trunk/amsn-extras/plugins/jake/lang/langfi =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langfi 2009-06-25 16:43:03 UTC (rev 11275) +++ trunk/amsn-extras/plugins/jake/lang/langfi 2009-06-26 13:20:31 UTC (rev 11276) @@ -25,6 +25,7 @@ cmdyoutube youtube cmderror Muodostusvirhe. cmdexpr laske +cmdmegaupload megaupload cmdargsdefine sana/t cmdargsgoogle sana/t @@ -32,6 +33,7 @@ cmdargsforget \"sanonta\" cmdargsyoutube sana/t cmdargsexpr Laskettava lauseke. +cmdargsmegaupload sana/t txtcommands Mahdollisia komentoja: txthelp Näyttää tämän viestin. @@ -58,6 +60,7 @@ txtexpr Tämä kertoo vastauksen laskuun. Nähdäksesi mitä kaikkea voit tehdä, kirjoita \"!laske help\" txtsolution Vastaus on: txtexprhelp abs( x ) - Itseisarvo (kielteinen jos negatiivinen.)\n acos( x ) - Käänteinen kosini (tulos radiaaneissa.)\n asin( x ) - Käänteinen sini (tulos radiaaneissa.)\n atan( x ) - Käänteinen tangentti (tulos radiaaneissa.)\n atan2( y , x ) - Käänteinen tangentti (tulos radiaaneissa.)\n ceil( x ) - Kattofunktio (määritelty liukuluvuista.)\n cos( x ) - Kosini (syöttö radiaaneissa.)\n cosh( x ) - Hyperbolinen kosini.\n double( x ) - Muunna numero liukuluvuksi.\n exp( x ) - Eksponentaalinen funktio.\n floor( x ) - Lattiafunktio (määritelty liukuluvuista.)\n fmod( x ) - Liukulukujäännös.\n hypot( x , y ) - Hypotenuusalaskin.\n int( x ) - Muunna numero kokonaisluvuksi lyhentämällä.\n log( x ) - Luonnollinen logaritmi.\n log10( x ) - Logaritmi suhteessa kantaan 10.\n pow( x , y ) - Potenssifunktio.\n rand( ) - Satunnainen luku. Käyttää yhdenmukaista distribuutiota yli arvojoukon [0,1].\n round( x ) - Pyöristä lähimpään kokonaiseen lukuun.\n sin( x ) - Sini (syöttö radiaaneissa.)\n sinh( x ) - Hyperbolinen sini.\n sqrt( x ) - Neliöjuuri.\n srand( x ) - Aseta satunnaislukugeneraattori annetulla arvolla.\n tan( x ) - Tangentti (syöttö radiaaneissa.)\n tanh( x ) - Hyperbolinen tangentti. +txtmegaupload Etsii tiedostoja MegaUploadin tietokannasta. rsphour Kello on Modified: trunk/amsn-extras/plugins/jake/plugininfo.xml =================================================================== --- trunk/amsn-extras/plugins/jake/plugininfo.xml 2009-06-25 16:43:03 UTC (rev 11275) +++ trunk/amsn-extras/plugins/jake/plugininfo.xml 2009-06-26 13:20:31 UTC (rev 11276) @@ -1,54 +1,55 @@ -<?xml version="1.0"?> -<plugin> - <name>jake</name> - <author>Alexander Nestorov (ale...@ho...)</author> - <description>Chatbot made in Tcl. Really usefull, a lot of options. To see the help, type !help</description> - <description_es>Chat Bot hecho en Tcl. Muy util, con muchas opciones. Para ver la ayuda escribe !help</description_es> - <description_it>Chat Bot realizzato in Tcl. Veramente utile, con molte opzioni. Per visulizzare l'aiuto digita !help</description_it> - <description_fr>Chatbot réalisé en Tcl. Très utile et plein d'options. Pour afficher l'aide, tapez !aide</description_fr> - <description_fi>Tcl:llä tehty keskustelubotti. Todella kätevä, paljon ominaisuuksia. Nähdäksesi ohjeen kirjoita !help.</description_fi> - - <amsn_version>0.97</amsn_version> - <plugin_version>0.6.2</plugin_version> - <plugin_file>jake.tcl</plugin_file> - <plugin_namespace>jake</plugin_namespace> - <init_procedure>jakeStart</init_procedure> - <cvs_version>11150</cvs_version> - - <lang> - <langcode>en</langcode> - <version>11175</version> - </lang> - - <lang> - <langcode>es</langcode> - <version>11175</version> - </lang> - - <lang> - <langcode>fr</langcode> - <version>11175</version> - </lang> - - <lang> - <langcode>it</langcode> - <version>11175</version> - </lang> - - <lang> - <langcode>fi</langcode> - <version>11175</version> - </lang> - - <file> - <path>README</path> - <version>11175</version> - </file> - - <URL> - <main>http://www.amsn-project.net/autoupdater/plugins/jake/jake.tcl</main> - <plugininfo>http://www.amsn-project.net/autoupdater/plugins/jake/plugininfo.xml</plugininfo> - <lang>http://www.amsn-project.net/autoupdater/plugins/jake/lang/lang$langcode</lang> - <file>http://www.amsn-project.net/autoupdater/plugins/jake/$file</file> - </URL> -</plugin> +<?xml version="1.0"?> +<plugin> + <name>jake</name> + <author>Alexander Nestorov (ale...@ho...)</author> + <description>Chatbot made in Tcl. Really usefull, a lot of options. To see the help, type !help</description> + <description_en>Chatbot made in Tcl. Really usefull, a lot of options. To see the help, type !help</description_en> + <description_es>Chat Bot hecho en Tcl. Muy util, con muchas opciones. Para ver la ayuda escribe !help</description_es> + <description_it>Chat Bot realizzato in Tcl. Veramente utile, con molte opzioni. Per visulizzare l'aiuto digita !help</description_it> + <description_fr>Chatbot réalisé en Tcl. Très utile et plein d'options. Pour afficher l'aide, tapez !aide</description_fr> + <description_fi>Tcl:llä tehty keskustelubotti. Todella kätevä, paljon ominaisuuksia. Nähdäksesi ohjeen kirjoita !help.</description_fi> + + <amsn_version>0.97</amsn_version> + <plugin_version>0.8 BETA</plugin_version> + <plugin_file>jake.tcl</plugin_file> + <plugin_namespace>jake</plugin_namespace> + <init_procedure>jakeStart</init_procedure> + <cvs_version>11275</cvs_version> + + <lang> + <langcode>en</langcode> + <version>11275</version> + </lang> + + <lang> + <langcode>es</langcode> + <version>11275</version> + </lang> + + <lang> + <langcode>fr</langcode> + <version>11175</version> + </lang> + + <lang> + <langcode>it</langcode> + <version>11175</version> + </lang> + + <lang> + <langcode>fi</langcode> + <version>11275</version> + </lang> + + <file> + <path>README</path> + <version>11175</version> + </file> + + <URL> + <main>http://www.amsn-project.net/autoupdater/plugins/jake/jake.tcl</main> + <plugininfo>http://www.amsn-project.net/autoupdater/plugins/jake/plugininfo.xml</plugininfo> + <lang>http://www.amsn-project.net/autoupdater/plugins/jake/lang/lang$langcode</lang> + <file>http://www.amsn-project.net/autoupdater/plugins/jake/$file</file> + </URL> +</plugin> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |