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 

interesting problem with "say and respond" script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Mon Nov 30, 2009 11:50 am    Post subject: interesting problem with "say and respond" script Reply with quote

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:

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:

bind pubm - * AI;


and, then, this piece of code is ready to run...

Code:

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:

{ "*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?? Smile

-DjZ-
Smile Smile


Last edited by dj-zath on Tue Dec 01, 2009 6:01 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Nov 30, 2009 3:54 pm    Post subject: Reply with quote

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:
"#$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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Mon Nov 30, 2009 6:25 pm    Post subject: Reply with quote

Code:
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 Wink

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:
{ *"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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Tue Dec 01, 2009 5:51 am    Post subject: Reply with quote

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


now, on to the fun...

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

Code:

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! Smile

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 Smile 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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Tue Dec 01, 2009 7:30 am    Post subject: Reply with quote

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) Smile 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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Dec 01, 2009 11:51 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Tue Dec 01, 2009 12:18 pm    Post subject: Reply with quote

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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Dec 01, 2009 6:03 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Wed Dec 02, 2009 3:31 am    Post subject: Reply with quote

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:

{
    "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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Dec 02, 2009 5:14 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Wed Dec 02, 2009 4:13 pm    Post subject: Reply with quote

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:


24k Stream Online:


Live Webcam Online:


Current DJ/Song Title 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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Dec 02, 2009 5:10 pm    Post subject: Reply with quote

Is that a good old Denon 2000f I see? Can't quite place the mixer though, A&H?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Wed Dec 02, 2009 5:14 pm    Post subject: Reply with quote

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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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