This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Pandorabot.tcl

Support & discussion of released scripts, and announcements of new releases.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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: Select all

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.
so it's probably better to set https://... instead.
Now using:

Code: Select all

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: Select all

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 !
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

This 'Bogus URL..' comes from egghttp.tcl / proc egghttp:geturl :

Code: Select all

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: Select all

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
net: connect! sock 11
net: eof!(read) socket 11


and if you try http://pandorabots it return :
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: Select all

#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 {" \"} $responce]"
	}
	return 0
}
Life iS Just a dReaM oN tHE wAy to DeaTh
S
Settore
Voice
Posts: 8
Joined: Sun Mar 05, 2017 4:55 am

Same story...

Post by Settore »

It worked for some time.

Now:

Code: Select all

[00:48:53] <(AI> [22:48:53] Tcl error [talkto]: can't read "token": no such variable
Something is wrong, somewhere...
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

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
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Koach :

Code: Select all

#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 {" " " " "&" {\&} """ "\'" "©" "(c)"\
			"&#" "#" "<" "<" ">" ">" "%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)
Last edited by heartbroken on Sat Mar 18, 2017 9:32 am, edited 1 time in total.
Life iS Just a dReaM oN tHE wAy to DeaTh
S
Settore
Voice
Posts: 8
Joined: Sun Mar 05, 2017 4:55 am

Thanks a lot...

Post by Settore »

Thanks a lot.

Will try now.
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

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
S
Settore
Voice
Posts: 8
Joined: Sun Mar 05, 2017 4:55 am

Still error

Post by Settore »

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

Code: Select all

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.
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

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: Select all

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: Select all

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

Code: Select all

if {![channel get $chan talk] || ([expr {[lsearch -nocase [fix_chars $text] $::pandoraNick]}] == "-1")} { return 0 }
and in proc talkto_pvt replace:

Code: Select all

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

Code: Select all

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
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

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
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

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
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

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

Thanks again for all your help.

Koach
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

heartbroken,

I wonder if you, or anyone, might have an answer to this.

When I type the bot's name starting with a lowercase f, the response includes the bot's name inserted in the sentence. An uppercase F, replies correctly.

Example:
<Koach> fovea branson is nuts
<Fovea> Koach: Ok I will add that fact about fovea branson to my database.

<Koach> Fovea branson is nuts
<Fovea> Koach: Ok I will add that fact about branson to my database.

Aside from your recommended changes, the only thing I added was the chatters nick:
puthelp "privmsg $chan $nick: [fix_talk $responce]"

Thanks,
Koach
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Script sending your messages as a -query to the pandorabots site and pandorabots doesn't recognize the bot name if the comparison is fail cause they looking for -exact match.

Go to proc talkto :

Code: Select all

regsub -all -- $::pandoraNick [fix_chars $text] {} TxT
and change this line to:

Code: Select all

regsub -all -nocase $::pandoraNick [fix_chars $text] {} TxT
And :

Code: Select all

puthelp "privmsg $chan $nick: [fix_talk $responce]"
line should be :

Code: Select all

puthelp "privmsg $chan :$nick: [fix_talk $responce]"
like this.
Life iS Just a dReaM oN tHE wAy to DeaTh
K
Koach
Voice
Posts: 21
Joined: Sun Apr 19, 2009 6:42 pm
Contact:

Post by Koach »

heartbroken,

Once again, thank you. I should have known that $nick: should be :$nick:.

But, I would not have figured out the change to the regsub line. Thanks for that explanation.

Koach
Post Reply