From: <bi...@us...> - 2009-04-18 17:02:45
|
Revision: 11147 http://amsn.svn.sourceforge.net/amsn/?rev=11147&view=rev Author: billiob Date: 2009-04-18 17:02:42 +0000 (Sat, 18 Apr 2009) Log Message: ----------- update the jake plugin, by al3x 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/plugininfo.xml Added Paths: ----------- trunk/amsn-extras/plugins/jake/lang/langit Modified: trunk/amsn-extras/plugins/jake/jake.tcl =================================================================== --- trunk/amsn-extras/plugins/jake/jake.tcl 2009-04-18 16:21:33 UTC (rev 11146) +++ trunk/amsn-extras/plugins/jake/jake.tcl 2009-04-18 17:02:42 UTC (rev 11147) @@ -11,16 +11,16 @@ ::plugins::RegisterEvent jake chat_msg_received answer ::plugins::RegisterEvent jake ChangeMyState online - set langdir [file join $mydir "lang"] - set lang [::config::getGlobalKey language] - load_lang en $langdir - load_lang $lang $langdir + set langdir [file join $mydir "lang"] + set lang [::config::getGlobalKey language] + load_lang en $langdir + load_lang $lang $langdir array set ::jake::config { - botname {jake} - mystate {1} - helptxt {I'm $botname, an AI bot.} - nresults {5} + botname {jake} + mystate {1} + helptxt {I'm $botname, an AI bot.} + nresults {5} } set ::jake::configlist [list \ @@ -50,7 +50,6 @@ set c($n,$m) } - if {[catch { package require Tcl 8.5 namespace path {tcl::mathfunc tcl::mathop} @@ -69,24 +68,35 @@ expr {int(($m-$n)*rand()+$n)} } +proc getPage {url} { + package require http + ::http::config -useragent "Monkey cmdline tool (OpenBSD; en)" + if {[catch {set tokr [::http::geturl $url]} msg]} { + return "Error: $msg" + } else { + set data [::http::data $tokr] + } + return $data +} + proc answer {event epvar} { - + global mydir upvar 2 $epvar args - upvar 2 $args(msg) msg - upvar 2 $args(chatid) chatid - upvar 2 $args(user) user - set me [::abook::getPersonal login] - set window [::ChatWindow::For $chatid] + upvar 2 $args(msg) msg + upvar 2 $args(chatid) chatid + upvar 2 $args(user) user + 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]" } { + if { $user==$me && $msg == "![trans cmdon]" } { set ::jake::config(mystate) 1 plugins_log jake "Plugin Jake activado!" - set first 1 + #set first 1 ::amsn::MessageSend $window 0 "$botname: [trans msgon]" } elseif { $user==$me && $msg == "![trans cmdoff]" } { set ::jake::config(mystate) 0 @@ -106,101 +116,111 @@ ![trans cmdhelp] - [trans txthelp]\n\ ![trans cmdon] - [trans txtconveron]\n\ ![trans cmdoff] - [trans txtconveroff]\n\ - ![trans cmdgoogle] [trans mrgoogle] - [trans txtgoogle]\n\ - ![trans cmddefine] [trans mrdefine] - [trans txtdefine]\n\ + ![trans cmdgoogle] [trans cmdargsgoogle] - [trans txtgoogle]\n\ + ![trans cmddefine] [trans cmdargsdefine] - [trans txtdefine]\n\ ![trans cmdhour] - [trans txthour]\n\ ![trans cmddate] - [trans txtdate]\n\ ![trans cmdstate] - [trans txtstate]\n\ - ![trans cmdlearn] [trans mrlearn] - [trans txtlearn] $botname\n\ - ![trans cmdforget] [trans mrforget] - [trans txtforget] $botname" + ![trans cmdlearn] [trans cmdargslearn] - [trans txtlearn] $botname\n\ + ![trans cmdforget] [trans cmdargsforget] - [trans txtforget] $botname\n\ + ![trans cmdyoutube] [trans cmdargsyoutube] - [trans txtyoutube]\n\ + ![trans cmdexpr] [trans cmdargsexpr] - [trans txtexpr]" } 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 8 end] "+" msg - if [catch {set sock [socket www.google.com 80]} err] { - #TODO: show an error message to the user? - plugins_log "jake" "[trans errgoogle]" - exit - } + } elseif { [string first "![trans cmdgoogle] " $msg] == 0 } { + regsub -all { +} [string range $msg [expr [string length [trans cmdgoogle]] + 2] end] "+" msg set link "www.google.com/search?hl=" append link $language&num=$nresults&q=$msg - puts $sock "GET $link HTTP/1.0" - puts $sock "Connection: Keep-Alive" - puts $sock "User-Agent: Monkey cmdline tool (OpenBSD; $language)" - puts $sock "Host: www.google.com:80" - puts $sock "Accept-Encoding: gzip" - puts $sock "Accept-Language: $language" - puts $sock "Accept-Charset: iso-8859-1,utf-8" - puts $sock "\n" - flush $sock - set salida [read $sock] - close $sock - 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 + 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" } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" - } elseif { [string first "![trans cmddefine] " $msg] == 0 } { - regsub -all { +} [string range $msg 8 end] "+" msg - if [catch {set sock [socket www.google.com 80]} err] { - #TODO: show an error message to the user? - plugins_log "jake" "[trans errgoogle]" - exit + } 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" } + } elseif { [string first "![trans cmddefine] " $msg] == 0 } { + regsub -all { +} [string range $msg [expr [string length [trans cmddefine]] + 2] end] "+" msg set link "www.google.com/search?hl=" append link $language&q=define:$msg - puts $sock "GET $link HTTP/1.0" - puts $sock "Connection: Keep-Alive" - puts $sock "User-Agent: Monkey cmdline tool (OpenBSD; $language)" - puts $sock "Host: www.google.com:80" - puts $sock "Accept-Encoding: gzip" - puts $sock "Accept-Language: $language" - puts $sock "Accept-Charset: iso-8859-1,utf-8" - puts $sock "\n" - flush $sock - set salida [read $sock] - close $sock - 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 - } else { - set bool 0 + 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 + } else { + set bool 0 + } } + ::amsn::MessageSend $window 0 "$botname: \n\n$final" + } else { + ::amns::MessageSend $window 0 "$botname: Error: $salida" } - ::amsn::MessageSend $window 0 "$botname: \n\n$final" - } elseif { [string first "![trans cmdlearn] " $msg] == 0 } { - set msg [string range $msg 9 end] + } 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 @@ -211,10 +231,10 @@ ::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 mrlearn]" + [trans txthelplearn] ![trans cmdlearn] [trans cmdargslearn]" } - } elseif { [string first "![trans cmdforget] " $msg] == 0 } { - set msg [string range $msg 8 end] + } elseif { [string first "![trans cmdforget] " $msg] == 0 } { + set msg [string range $msg [expr [string length [trans cmdforget]] + 2] end] if { [regexp -- {^".*"$} $msg] } { if { [array exists diccionario] == 0 } { source [file join $::HOME diccionario.dic] @@ -237,8 +257,16 @@ ::amsn::MessageSend $window 0 "$botname: [trans txtregdel] [expr {$oldsize - [array size diccionario]}] [trans txtdic]" } else { ::amsn::MessageSend $window 0 "$botname: [trans cmderror]\n\ - [trans txthelpforget] ![cmdforget] [trans mrforget]" + [trans txthelpforget] ![cmdforget] [trans cmdargsforget]" } + } elseif { [string first "![trans cmdexpr ]" $msg] == 0 } { + set msg [string range $msg [expr [string length [trans cmdexpr]] + 2] 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]" + } } elseif { $mystate == 1 } { if { $user != $me } { if { [array exists diccionario] == 0 } { @@ -254,7 +282,9 @@ if { $i > 1 } { ::amsn::MessageSend $window 0 "$botname: $respuesta([rand [array size respuesta] 1])" } else { - ::amsn::MessageSend $window 0 "$botname: [trans txtneedhelp]" + if { [rand 5 1] == 1 } { + ::amsn::MessageSend $window 0 "$botname: [trans txtneedhelp]" + } } } } @@ -275,3 +305,5 @@ } } + + Modified: trunk/amsn-extras/plugins/jake/lang/langen =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langen 2009-04-18 16:21:33 UTC (rev 11146) +++ trunk/amsn-extras/plugins/jake/lang/langen 2009-04-18 17:02:42 UTC (rev 11147) @@ -1,25 +1,38 @@ amsn_lang_version 2 + state Active + name Bot's name + helptext Message for !help + nresults Number of results from searches in Google + msgon I'm on. msgoff I'm off. msgonoff Only mi creator can turn me on or off. + cmdstate state cmdhelp help cmdon on cmdoff off cmdgoogle google -mrgoogle word/s cmddefine define -mrdefine word/s cmdhour hour cmddate date cmdlearn learn -mrlearn \"phrase\" \"response\" cmdforget forget -mdforget \"phrase\" +cmdyoutube youtube +cmderror Syntaxis error. +cmdexpr expr + +cmdargsdefine word/s +cmdargsgoogle word/s +cmdargslearn \"phrase\" \"response\" +cmdargsforget \"phrase\" +cmdargsyoutube word/s +cmdargsexpr Any math expression. + txtcommands Available commands: txthelp Shows this message. txtconveron Turn's on the bot's speak capabilities. @@ -31,12 +44,8 @@ txtstate Will show the actual state of the bot. txtlearn Phrase and response will be added to the dictionary of txtforget Phrase will be deleted from the dictionary of -rsphour The time is -rspdate The date is -errgoogle Impossible to connect to Google. txtregadd Phrase added succesfully. There are txtreg phrases -cmderror Syntaxis error. txthelplearn The right syntaxis for adding phrases is: txtneedhelp I think I don't understand you. If you want to know how do I work, type !help txtchangestate Change state to @@ -44,4 +53,12 @@ txtlogdesactivated deactivated! txtregdel Deleted txtdic phrases from the dictionary. -txthelpforget The right syntaxis for deleting phrases is: \ No newline at end of file +txthelpforget The right syntaxis for deleting phrases is: +txtyoutube Will search in YouTuBe for a video. +txtexpr This will give the answer for a math expression. To see the math expressions that you can use, type \"!expr help\" +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. + + +rsphour The time is +rspdate The date is Modified: trunk/amsn-extras/plugins/jake/lang/langes =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langes 2009-04-18 16:21:33 UTC (rev 11146) +++ trunk/amsn-extras/plugins/jake/lang/langes 2009-04-18 17:02:42 UTC (rev 11147) @@ -1,25 +1,37 @@ amsn_lang_version 2 + state Activado + name Nombre del bot + helptext Mensaje para !ayuda + nresults Numero de resultados de la busqueda en Google + msgon Estoy activado. msgoff Estoy desactivado. msgonoff Solo mi credor puede activarme y desactivarme. + cmdstate estado cmdhelp ayuda cmdon on cmdoff off cmdgoogle google -mrgoogle palabra/s cmddefine define -mrdefine palabra/s cmdhour hora cmddate fecha cmdlearn aprende -mrlearn \"frase\" \"respuesta\" cmdforget olvida -mrforget \"frase\" +cmdyoutube youtube +cmderror Error en la sintaxis del comando. +cmdexpr expr +cmdargsgoogle palabra/s +cmdargsdefine palabra/s +cmdargslearn \"frase\" \"respuesta\" +cmdargsforget \"frase\" +cmdargsyoutube palabra/s +cmdargsexpr Cualquiera expresion matematica. + txtcommands Comandos disponibles: txthelp Muestra este mensaje. txtconveron Activa la capacidad de conversar. @@ -31,12 +43,8 @@ txtstate Devuelve el estado actual del bot. txtlearn Se añadiran los datos introducidos al diccionario de txtforget Se borraran las frases que coinciden del diccionario de -rsphour La hora es -rspdate La fecha es -errgoogle Imposible conectar con Google. txtregadd Registro añadido con exito. Hay txtreg registros. -cmderror Error en la sintaxis del comando. txthelplearn La forma correcta de añadir datos es: txtregdel Se ha/n borrado txtdic elemento/s del diccionario. @@ -44,4 +52,12 @@ txtneedhelp Creo que no te he entendido. Si quieres saber como funciono, escribe !ayuda txtchangestate Cambio estado a txtlogactivated activado! -txtlogdesactivated desactivado! \ No newline at end of file +txtlogdesactivated desactivado! +txtyoutube Buscara en YouTuBe para videos. +txtexpr Respondera diciendo la respuesta a la expresion matematica. Para ver las expresiones que puedes utilizar escribe \"!expr ayuda\" +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. + + +rsphour La hora es +rspdate La fecha es \ No newline at end of file Added: trunk/amsn-extras/plugins/jake/lang/langit =================================================================== --- trunk/amsn-extras/plugins/jake/lang/langit (rev 0) +++ trunk/amsn-extras/plugins/jake/lang/langit 2009-04-18 17:02:42 UTC (rev 11147) @@ -0,0 +1,47 @@ +amsn_lang_version 2 +state Attivo +name Nome del Chat Bot +helptext Messaggio per !help +nresults Numero di risultati per le ricerche in Google +msgon Sono attivo. +msgoff Sono disattivo. +msgonoff Solo il mio creatore può attivarmi o disattivarmi. +cmdstate state +cmdhelp help +cmdon on +cmdoff off +cmdgoogle google +mrgoogle word/s +cmddefine define +mrdefine word/s +cmdhour hour +cmddate date +cmdlearn learn +mrlearn \"phrase\" \"response\" +cmdforget forget +mdforget \"phrase\" +txtcommands Comandi disponibili: +txthelp Visualizza questo messaggio. +txtconveron Avvia il Chat Bot. +txtconveroff Arresta il Chat Bot. +txtgoogle Cerca in Google le parole che hai digitato e visualizza i risultati nella finestra di chat. +txtdefine Cerca di spiegare il meglio possibile il significato di una parola. +txthour Visualizza l'ora corrente. +txtdate Visualizza la data corrente. +txtstate Visualizza lo stato attuale del Chat Bot. +txtlearn Aggiunge una frase e la risposta risposta al dizionario di +txtforget Elimina una frase dal dizionario di +rsphour L'ora è +rspdate La data è +errgoogle Impossibile connettersi a Google. +txtregadd Frase aggiunta con successo. Ci sono +txtreg frasi +cmderror Errore di sintassi. +txthelplearn La giusta sintassi per aggiungere una frase è: +txtneedhelp Non riesco a comprenderti. Se vuoi sapere come funziono digita !help +txtchangestate Cambia lo stato in +txtlogactivated Attivato! +txtlogdesactivated Disattivato! +txtregdel Eliminate +txtdic frasi dal dizionario +txthelpforget La giusta sintassi per eliminare una frase è: \ No newline at end of file Modified: trunk/amsn-extras/plugins/jake/plugininfo.xml =================================================================== --- trunk/amsn-extras/plugins/jake/plugininfo.xml 2009-04-18 16:21:33 UTC (rev 11146) +++ trunk/amsn-extras/plugins/jake/plugininfo.xml 2009-04-18 17:02:42 UTC (rev 11147) @@ -4,20 +4,24 @@ <author>Alexander Nestorov (ale...@ho...)</author> <description>Chatbot made in Tcl. Really usefull, a lot of options. To see the help, type !help</description> <amsn_version>0.97</amsn_version> - <plugin_version>0.5.0</plugin_version> + <plugin_version>0.6.0</plugin_version> <plugin_file>jake.tcl</plugin_file> <plugin_namespace>jake</plugin_namespace> <init_procedure>jakeStart</init_procedure> - <cvs_version>11140</cvs_version> + <cvs_version>11146</cvs_version> <lang> <langcode>en</langcode> - <version>11140</version> + <version>11146</version> </lang> <lang> <langcode>es</langcode> - <version>11140</version> + <version>11146</version> </lang> + <lang> + <langcode>it</langcode> + <version>11146</version> + </lang> <file> <path>README</path> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |