egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pandorabot.tcl
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
willyw
Owner


Joined: 15 Jan 2009
Posts: 891

PostPosted: Thu Mar 16, 2017 4:29 pm    Post subject: Reply with quote

heartbroken wrote:
Could you test this : http://paste.tclhelp.net/?id=6cfb
Replace it with your own settings.
and change http://www.pandorabots... links to https


Done.

Found a problem.
This line was line wrapped
Code:

regsub -all -- {\002|\037|\026|\017|\003([0-9][0-9]?(,[0-9][0-9]?)?)?|||([0-9][0-9]?(,[0-9][0-9]?)?)?|} $text "" text


and it has another problem too. Notice the funky character? (It didn't copy and paste to here ... sorry... check it out in your pastebin though )
That's not there, in the line numbered (top) part of your pastebin.
However, I used the bottom part, so I could 'select all' to copy-and-paste.

Then, when I instead copied just that one line, from the top part of the pastebin, and tried to paste it in nano... nano didn't like it. Jumped to some other part of the file.
So I did it char by char, by hand.

Quote:

so it's probably better to set https://... instead.


Now using:
Code:

set alice_url "https://pandorabots.com/pandora/talk?botid=*********"

Just double checked.

It will go try to do something now.
Now, it returns this, in the partyline:
Code:

Tcl error [alice:pub_query]: bogus URL: https://pandorabots.com/pandora/talk?botid=**********

_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 70
Location: somewhere out there

PostPosted: Thu Mar 16, 2017 9:04 pm    Post subject: Reply with quote

This 'Bogus URL..' comes from egghttp.tcl / proc egghttp:geturl :
Code:
if {![regexp -nocase {^(http://)?([^:/]+)(:([0-9]+))?(/.*)?$} $url x protocol server y port path]} {


This Regex only works for http URLs ,
if you Replace it to :
Code:
if {![regexp -nocase {^(http(s|)://)?([^:/]+)(:([0-9]+))?(/.*)?$} $url x protocol server y port path]} {


it can pass that 'Bogus ...' thing but

I see this egghttp using Eggdrop-Tcl's : connect <host> <port> command instead Tcl's http package or socket command
and I am not realy sure about does that method able to handle https connections.

I don't know why he'd prefer to use this instead but https links returns
Quote:

net: connect! sock 11
net: eof!(read) socket 11


and if you try http://pandorabots it return :
Quote:

DNS lookup failed
Tcl: while executing
Tcl: "connect $server $port"


and doesn't give more useful information i can use for debuging what it is the problem.

so I am still testing things with my little test snippets and i see that it is still available to work as https://pandora... and i've tried with using cookies or without it and i can get response.

I am gonna try to edit/re-write the whole fetching procedures with using http and tls packages instead egghttp.tcl but i have to make some more tests to figure out how works things.

it can takes some more time sorry for delay.

and Settore , I just tried once again and i didn't get any error , so i don't know what can i say but it is still working fine from here.

this is what my bot has.
Code:

#Bot's Nickname to Respond to: ex. MyBot - Usage: MyBot, what's 1+1?
set pandoraNick "k-bot"

#Your Pandora Bot ID. (Feel free to use the existing one if you want, but the bot will think its name is AlphaBot
set botid "a5cd504e4e342614"

#STOP EDITING HERE

package require http
if {[catch {package require tls 1.6}]} {
   putcmdlog "https links requires tcltls : https://core.tcl.tk/tcltls/wiki/Download"
   set enabletls 0
} else {
   set enabletls 1
   tls::init -ssl3 0 -ssl2 0 -tls1 1
   http::register https 443 [list ::tls::socket -require 0 -request 1]
}

bind pubm - "% ${pandoraNick}*" talkto

proc talkto {n u h c t} {
   set query [::http::formatQuery botid $::botid custid $n input [join [lrange [split $t] 1 end]]]
   if {[catch {set token [::http::geturl https://pandorabots.com/pandora/talk-xml -query $query -timeout 16000]} error]} {
      putlog "[string map [list \n " ,"] $error] ,[::http::status $token]"
      ::http::cleanup $token
   }
   if {[string match -nocase "timeout" [::http::status $token]]} {
      putlog "[::http::code $token]"
      ::http::cleanup $token
   }
   if {![string equal -nocase [::http::status $token] "ok"]} {
      putlog "[::http::code $token] ,[::http::status $token]"
      ::http::cleanup $token
   }
   if {[::http::ncode $token] == "200" && [string equal -nocase [::http::status $token] "ok"]} {
      set pandata [::http::data $token]
      ::http::cleanup $token
   }
   if {![regexp {<that>(.*?)</that>} $pandata -> responce]} {
      putlog "This regex sucks!!! Source codes changed or what?!?"
      return
   } else {
      puthelp "privmsg $c :[string map {&quot; \"} $responce]"
   }
   return 0
}

_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Settore
Voice


Joined: 05 Mar 2017
Posts: 7

PostPosted: Fri Mar 17, 2017 6:50 pm    Post subject: Same story... Reply with quote

It worked for some time.

Now:

Code:
[00:48:53] <(AI> [22:48:53] Tcl error [talkto]: can't read "token": no such variable


Something is wrong, somewhere...
Back to top
View user's profile Send private message
Koach
Voice


Joined: 19 Apr 2009
Posts: 9

PostPosted: Fri Mar 17, 2017 10:18 pm    Post subject: Reply with quote

Hi heartbroken,
If i wanted the eggdrop to respond if the bot's nick was anywhere in the sentence instead of the beginning only, what would I change in script you posted.
Thanks,
Koach
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 70
Location: somewhere out there

PostPosted: Sat Mar 18, 2017 3:09 am    Post subject: Reply with quote

Koach :

Code:
#Bot's Nickname to Respond to: ex. MyBot - Usage: MyBot, what's 1+1?
set pandoraNick "MyBot"

#Your Pandora Bot ID. (Feel free to use the existing one if you want, but the bot will think its name is AlphaBot
set botid "a5cd504e4e342614"

# enable chat in bot pm : 1 ,disable : 0 or ""
set botpm 1

# user must wait xx seconds between messages to get a response from bot.
set chatstop 10

#STOP EDITING HERE

package require http
if {[catch {package require tls 1.6}]} {
   putcmdlog "https links requires tcltls : https://core.tcl.tk/tcltls/wiki/Download"
   set enabletls 0
} else {
   set enabletls 1
   tls::init -ssl3 0 -ssl2 0 -tls1 1
   http::register https 443 [list ::tls::socket -require 0 -request 1]
}

# .chanset #channel +talk
setudef flag talk

bind pubm - "*" talkto_pub
bind msgm - "*" talkto_pvt

proc talkto_pub {nick uhost hand chan text} {
   if {![channel get $chan talk] || $::pandoraNick ni [fix_chars $text]} { return 0 }
       talkto $nick $uhost $hand $chan $text
}

proc talkto_pvt {nick uhost hand text} {
   if {$::pandoraNick ni [fix_chars $text]} { return }
   if {[string length $::botpm] && $::botpm >= "1"} {
        talkto $nick $uhost $hand $nick $text
   }
   return 0
}

proc talkto {nick uhost hand chan text} {
    if {[info exists ::flooder($nick)] && [expr {$::flooder($nick) + $::chatstop}] > [clock seconds]} { return 0 }
   regsub -all -- $::pandoraNick [fix_chars $text] {} TxT
   set query [::http::formatQuery botid $::botid custid $nick input $TxT]
   set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"
   set token [::http::config -useragent $ua -urlencoding "utf-8"]
   if {[catch {set token [::http::geturl https://pandorabots.com/pandora/talk-xml -query $query -timeout 16000]} error]} {
      putlog "[string map [list \n " ,"] $error] ,[::http::status $token]"
      ::http::cleanup $token
   } elseif {[string match -nocase "timeout" [::http::status $token]]} {
      putlog "[::http::code $token]"
      ::http::cleanup $token
   } elseif {![string equal -nocase [::http::status $token] "ok"]} {
      putlog "[::http::code $token] ,[::http::status $token]"
      ::http::cleanup $token
   } elseif {[::http::ncode $token] == "200" && [string equal -nocase [::http::status $token] "ok"]} {
      set pandata [::http::data $token]
      ::http::cleanup $token
   } else {
      putlog "Error: [::http::status $token] ,[::http::code $token]"
      ::http::cleanup $token
   }
   if {[info exists pandata]} {
      if {![regexp {<that>(.*?)</that>} $pandata -> responce]} {
         putlog "This regex sucks!!! Source codes changed or what?!?"
         return
      } else {
         puthelp "privmsg $chan :[fix_talk $responce]"
         set ::flooder($nick) [clock seconds]
      }
   }
   return 0
}

proc fix_chars {txt} {
    return [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} \$ \\\$ \" \\\"} $txt]
}

proc fix_talk {str} {
   return [string map {"&nbsp;" " " "&amp;" {\&} "&quot;" "\'" "&copy;" "(c)"\
         "&#" "#" "&lt;" "<" "&gt;" ">" "%20" " "} $str]
}

To activate : .chanset #Your-channel +talk in Partyline.

Settore try this version. I didn't get any error still.
I've added useragent and added an option to see unknown errors or connection failors .and a fix procedure for some html entities into bot response.

+ added another char fix procedure for your $text because if you say somethings to your bot which has some special Tcl characters in it like " { } [ ] \ code throws an error. this procedure (hopefully) fixing this issue.

Edit:
Script updated. Added flood control and bot able to response privat messages now. ( if you wish)
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh


Last edited by heartbroken on Sat Mar 18, 2017 9:32 am; edited 1 time in total
Back to top
View user's profile Send private message
Settore
Voice


Joined: 05 Mar 2017
Posts: 7

PostPosted: Sat Mar 18, 2017 8:33 am    Post subject: Thanks a lot... Reply with quote

Thanks a lot.

Will try now.
Back to top
View user's profile Send private message
Koach
Voice


Joined: 19 Apr 2009
Posts: 9

PostPosted: Sat Mar 18, 2017 6:46 pm    Post subject: Reply with quote

Thanks very much for this, heartbroken.

If i wanted to have it so chatters could type uppercase or lowercase for the bot's nick, where would be the easiest place to add that?

thanks again,
Koach
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Settore
Voice


Joined: 05 Mar 2017
Posts: 7

PostPosted: Sat Mar 18, 2017 8:11 pm    Post subject: Still error Reply with quote

Thanks, but still gets an error. Eggdrop 1.8.0 on TCL 8.6

Code:
02:10:36] <(AI> [00:10:32] Tcl error [talkto]: Unknown option -urlencoding, must be: -accept, -proxyfilter, -proxyhost, -proxyport, -useragent


I think I'll quit on the idea of using pandorabots.com and stay at bMotion.
Back to top
View user's profile Send private message
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 70
Location: somewhere out there

PostPosted: Sun Mar 19, 2017 3:57 am    Post subject: Reply with quote

Settore :
Do you have another old http.tcl sourced in your bot .conf ?
http::config has -urlencoding -option since http 2.5 and Tcl 8.6 has http 2.8.5 <-> 2.8.10 is the newest one.
http package already included in Tcl. there is no need to source it elsewhere.
and Your Tcl 8.6 / http version 'should' support this -urlencoding http::config -option.

I am testing things with an Eggdrop 1.8.1rc2 bot and Tcl 8.6.6

Older versions doesn't have this .You can check the differences at :
Tcl 8.3 / http man page / http::config : https://www.tcl.tk/man/tcl8.3/TclCmd/http.htm#M6
Tcl 8.4 / http man page / http::config : https://www.tcl.tk/man/tcl8.4/TclCmd/http.htm#M6
or ,for all 'changes' : http://wiki.tcl.tk/405

Add a line outside of the procs, like:
Code:
putlog "I am: [lindex $::version 0] with Tcl: [info patchlevel] is in $::tcl_library with http: [package present http] and tcltls: [package present tls] OS: $::tcl_platform(os) $::tcl_platform(osVersion)/$::tcl_platform(machine)"

this will show you some info while rehash/restart at partyline.

Koach :

Change; proc talkto_pub :

Code:
if {![channel get $chan talk] || $::pandoraNick ni [fix_chars $text]} { return 0 }

to
Code:
if {![channel get $chan talk] || ([expr {[lsearch -nocase [fix_chars $text] $::pandoraNick]}] == "-1")} { return 0 }


and in proc talkto_pvt replace:

Code:
if {$::pandoraNick ni [fix_chars $text]} { return }

line to :
Code:
if {[expr {[lsearch -nocase [fix_chars $text] $::pandoraNick]}] == "-1"} { return 0 }
done.

note : lsearch has this -nocase -option since Tcl 8.5 older version didn't support this.
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Koach
Voice


Joined: 19 Apr 2009
Posts: 9

PostPosted: Sun Mar 19, 2017 5:30 pm    Post subject: Reply with quote

Thanks heartbroken,

Everything works great.

But, and I hope you don't mind me asking, I have one more question (I hope lol). How can i get the bot to respond when its nick has a trailing comma, or colon. For example "hi bot, how are you" or "Bot: what does this mean."

I really appreciate all the time you have spent answering my questions.

Koach
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 70
Location: somewhere out there

PostPosted: Sun Mar 19, 2017 10:30 pm    Post subject: Reply with quote

You can add an asterisk { * } right'n side of $::pandoraNick variable in both [expr [lsearch .. lines. :
${::pandoraNick}* or $::pandoraNick* works.
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Koach
Voice


Joined: 19 Apr 2009
Posts: 9

PostPosted: Sun Mar 19, 2017 10:38 pm    Post subject: Reply with quote

Sheesh, I don't know why I always try to make things harder than they are lol

Thanks again for all your help.

Koach
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber