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.

interesting problem with "say and respond" script

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

interesting problem with "say and respond" script

Post by dj-zath »

hi nml, speechles and all the cool peeps here!

I have been playing around with a "say and respond" script.. that is, when someone says somethig in the channel, the Bot will respond with a saying or response based on what someone has said...

example:

someone says "test" and the bot responds with a random line of 5 choices...

I have come across a strange issue with this piece of code.. I'll display the code then what I'm experiencing..

First, heres the "Setup" code:

This piece of code reads a file, then loads it into memory.. Code loads ONCE at bot-startup only; 10 seconds in...

Code: Select all

Proc    SetVars {} {
          if {(![catch {set VarA [open "$MyTPL/BotAI.txt" r]}])} {
               set BotAI [read $VarA];
               close $VarA;
          } else {
               set BotAI "";
               putlog "\r\nWARNING! - AI Template file not found!\r\n";
          };
          return 0;
};
then 30 seconds later, the main loops start and the bot logs into the channel.. all is good.

we now set a bind:

Code: Select all

bind pubm - * AI;
and, then, this piece of code is ready to run...

Code: Select all

proc    AI {nick uhost hand chan arg} {
          global MyChan botnick BotAI Show Song DJ;
          if {(([lsearch -exact [string tolower "#$MyChan"] [string tolower $chan]] != "-1")||("#$MyChan" == "*"))&&(![matchattr $hand b])&&($nick != $botnick)} {
          foreach VarA $BotAI {
          if {[string match [string tolower [lindex $VarA 0]] [string tolower $arg]]} {
               putquick "PRIVMSG #$MyChan :[subst [lindex [lindex $VarA 1] [rand [llength [lindex $VarA 1]]]]]";
               };
          };
     };
     return 0;
};
and, now the file it reads:

Code: Select all

{ "*test*" {  (<-- this is now correctly posted as it appears in the code)
"it works!"
"yessss!"
"awesome!!"
"coool!"
"test successful!"
}}
everything works, but.. I have noticed when this piece of code is implemented, the bot is REALLY lagged in its responses.. now, I understand that using the pubm on EVERY line of text will cause a slowed response, but 10 seconds worth?

to me that seems quite, um.. EXCESSIVE!

without it, the bot responds instantly (.2 seconds, if not sooner) but with it, its lagged to about 10 seconds.. and this includes EVERY command and response- even notices and admin commands.. and I mean 10 seconds PER command and/or response!

now, this isn't a high-priority issue.. if anything, I can pitch it altogether and forget it.. but I was wondering, if anything, what I did wrong here?

nml to the rescue?? :)

-DjZ-
:) :)
Last edited by dj-zath on Tue Dec 01, 2009 6:01 am, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

With the specific data you posted, I'm timing that proc to roughly 57ms on a 600MHz Via V3 system...
I wonder, do you really need a full subst on the data you retrieve from your list?
And why on earth are you using lsearch to search a string?
Btw, this part of your initial conditional is pointless, as it will always be false:

Code: Select all

"#$MyChan" == "*"
I've had far more complex scripts trigger on pubm-bindings without suffering performance-impacts ranging in seconds... With the code and data you've posted, that should'nt happen... of course, if you've got a line like [after 10000] in your template-list, the delay would not be surprising...
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

proc AI {nick uhost hand chan arg} {
	global MyChan BotAI Show Song DJ
	if {([string equal -nocase "#$MyChan" $chan] || [string equal "$MyChan" "*"])  && ![matchattr $hand b] && ![isbotnick $nick]} {
		foreach VarA $BotAI {
			if {[string match -nocase [lindex $VarA 0] $arg]} {
				putquick "PRIVMSG #$MyChan :[subst -nocommands [lindex [lindex $VarA 1] [rand [llength [lindex $VarA 1]]]]]"
				break
			}
		}
	}
	return 0
}
Here's a cleaned up version of your AI proc. Try this out ;)

The problem with your speed is your iterating the entire AI list even after a match has been found. If your only after the first matching entry then you need the "break" where I've put it. If you've done this so you can have multiple replies then remove the "break" statement shown above.

Also, just so you know...

Code: Select all

{ *"test*" { 
Notice the problem above, the double-quotes should surround the entry, but you've left an asterisk there hanging out... This might cause an unbalanced list structure and unexpected problems.
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

first of all.. you guys are awesome! let me tell you that :)


now, on to the fun...

for Speechles: .. thats actually not an error.. (from what I can understand) The orginal sintax was:

Code: Select all

Set AI_data {
 {
  "*text*"  {
     "response 1"
     "response 2"
   }
}
 {
 "*text*"  {
     "response 1"
     "response 2"
  }
 }
}
I just took the "innards" and made them into a varable, loaded it into memory and parsed it there instead of in an attached "source" script that it was orginally meant to be..

this code was taken from an old AI stript from.. oh, boy.. mid 90s?! ("SayAI" I think it was called... )

it was just an idea I was playing around with... but I DID ask "what was I doing wrong??" and you guys showed me! :)

you know?, I should post the entire code I've written.. and have you guys look at it... I'm sure you can find LOTS of silly things I've done.. and/or come up with improvements...

nml has been a great help thus, so far.. his input has made things possable in the first place.. since he helped me get past the "blocking sockets" issue way back at the start...

I'm no expert at coding.. and not especially with TCL.. but I am trying :) I am amazed I got as far as I have!

beers all around!

UPDATE!

in posting this note then re-reading the thread, I have realized I have MISREAD Speechles's post.. I'm sorry sir, that was a TYPO I overlooked in the POST.. (the orginal code doesn't contain this error)

when I post code, I have to copy/paste it line-by-line because I have a very LOW screen resolution.. where I can't paste, I just re-type in.. I try not to make (or catch) typos before posting, but that one slipped by me!

-DjZ-
:) :)
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hey hey gang!

I have plugged in Speechles's code.. and the results are the same.. up to 10 seconds delay on every command to the bot.

Thanks Speechles for that nice cleanup of the code.. you're truely a master of your craft (as is nml as well) :) I'll save that for a later date.. in the meantime, theres other, more pressing needs to that code, that need to be done.

(I also suspect perhaps parsing the $DJ, $Show and $Song varables from IN the $BotAI varable itself may be the culprit!)

when I come back around to it, I'll look more deeply...

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Just brainstorming here...
Given the scale of your previous endeavours, just how large is the list of trigger-words? Are we talking 10s, 100s, 1,000s or more patterns?
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hi nml!

actually the list only has 5 compares- with 5 replies for each.. (cusswords) and "cancall" , "Bill gates" and "Steve Jobs" oh, and "tiu".

I figure it would be expanded at one point.. but for now, its just started for testing..

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, such a small set should'nt leave much of a performance impact. I can't see much that would cause any odd interactions with other scripts. Does it impact msg-commands or dcc partyline?
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

Hi there nml.. thanks again for the reply..

just seems to affect whats in the main channel.. I suspect its the "pubm"

I also wonder if, that one of the "compare's" contains other varables in its responses..

..taken from the $BotAI file/varable (last compare):

Code: Select all

{ 
    "tiu" {
       "Way to go $DJ!! Turn it up Up UP!"
       "I love this song $Song crank it up!"
       "$DJ is one of the best DJs on WARP!"
       "$Show is one of the best shows on WARP"
    }
}
I call this a "happy accident" I didn't expect it to work.. but it DID so I left it for now.

I don't quite see where in the code that would allow this to function..

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then I am currently at loss as to the cause of this sluggish behaviour.

As for your variable substitutions, I thought that's why you explicitly included the subst command? After all, as I've been saying all week long, that's exactly what it does...
And no, subst doesn't require 10 seconds to substitute a couple of variables.. Possibly if you've got a read-trace on 'em, but then it would rather be the trace-code that'd be broken...
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hi Speechles and nml buddies!

you guys are AWESOME!

Nml:

yeah, what you were saying about the subst.. EXACTLY... though I got the code from another old script- I wonder if much of it is now "depreciated" (read: I took more of the code that is currently needed) I donno.. I have used this code before and without this lag- the only thing I can think of is that I'm including the inner varables.. I'll try it again but without the inner varables and see if the lag is still there.. I'll report back my findings..

in the meatime, I thought I'd give you a small demo of what all this code does..

examples:

128k Stream Online:
Image

24k Stream Online:
Image

Live Webcam Online:
Image

Current DJ/Song Title Image:
Image

elements are "portable" and can be placed almost anywhere.. and its FAST and secure!

now, all I need to figure out now is how to convert text strings into gif files! (that will be a new thread)

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Is that a good old Denon 2000f I see? Can't quite place the mixer though, A&H?
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hi nml!

you are close!

Its a Dennon DN-2000F MKII

Mixer is a Mackie CR 1604 vlz

(this is an old pic actually.. cira 1998)

you were close, though!

-DjZ-
:) :)
Post Reply