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.

Problem binding to variable trigger with pubm

Old posts that have not been replied to for several years.
C
Cavemanm85de
Voice
Posts: 10
Joined: Mon Jul 05, 2004 8:39 am

Problem binding to variable trigger with pubm

Post by Cavemanm85de »

Hi,
i am trying myself on the following ...

---
proc bot_shutup {nick host handle chan text} {
putserv "PRIVMSG $chan :$nick: Nice Try! ;-)"
}
bind pubm - "#bottest $botnick*shut*up*" bot_shutup
---

But somehow '$botnick' does not get evaluated.

The manuals are not really that helpful .)

Could someone point me in the right direction?

TIA Ingo
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

It's a global var, so you have to declare it in the beginning of your proc.

Code: Select all

proc bot_shutup {nick host handle chan text} { 
 global botnick
 #....
[/quote]
C
Chojin

Post by Chojin »

Hi all, I'm new :-)

gb, are you sure, he has to globalize botnick within the proc to have it evaluated within the "bind pubm"-statement ??

I just tried it myself:

Code: Select all

global botnick
...
bind pubm - "#channel $botnick*hush*" bot_hush
...
proc bot_hush...
My bot's name is bot. The proc bot_hush gets executed whenever someone says "hush" in a sentence, no matter if s/he uses "bot hush", "joe, would you hush please" or just "hush".

I'm running 1.6.12... time to upgrade ?

But first it would be good to know, wether $variables are expanded within "bind pubm"-statement's <mask> at all. Anyone ?
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

nm, I didnt read the code properly, i thought he used $botnick inside the proc

Code: Select all

proc bot_shutup {nick host handle chan text} {
 putserv "PRIVMSG $chan :$nick: Nice Try! "
}

bind pubm - "#channel $botnick*shut*up*" bot_shutup
It seem to work just fine here though, it respond to "botnick shut up" but not just "shut up".

Running 1.6.16
C
Cavemanm85de
Voice
Posts: 10
Joined: Mon Jul 05, 2004 8:39 am

Post by Cavemanm85de »

ARG!

Thanks a lot GB.

It did not matter that you did not read the code correctely, your solution is still valid!

--
proc bot_shutup {nick host handle chan text} {
global botnick
putserv "PRIVMSG $chan :$nick: Nice Try! ;-)"
}

bind pubm - "% $botnick*shut*up*" bot_shutup
--

Now $botnick is evaluated ccorrectely!
Even though it defies what I learned till now.
Now the bot only answers to "<botnick> shut up" just as it should and not like before to "shut up"
C
Chojin

Post by Chojin »

gb, could you elaborate on why it has to be globalized within the proc, please ?

I mean, the "bind pubm"-statement is not within the proc. I wasn't going to use the variable $botnick within the proc (neither seems Cavemanm85de), so I thought you just misinterpreted Cavemanm85de question.

I see no connection why to globalize a variable within a proc-context to use it within the main-context.

Any advise to restore (my) logic on this will be greatly appreciated.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Yea that was my mistake.
gb wrote:nm, I didnt read the code properly, i thought he used $botnick inside the proc
C
Chojin

Post by Chojin »

Well, it seems to work here, too... weird !

So I'll upgrade to 1.6.16 to find out, if this phenomenon has to do with eggdrop or my version of tcl (8.3.3).

Cavemanm85de, gb, what versions of tcl have you guys running ?
C
Cavemanm85de
Voice
Posts: 10
Joined: Mon Jul 05, 2004 8:39 am

Post by Cavemanm85de »

Same TCL, Eggdrop 1.6.12 (to lazy to update) :D
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

8.3.4
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

The problem is when you are first starting up your bot...
The variable "botnick" has not been initialized, when the binding is about to be created, as the bot has yet to connect to irc... best to use a binding such as:

Code: Select all

bind pubm - "#channel *shut*up*" bot_shutup
And check for $botnick from within the procedure itself:

Code: Select all

proc bot_shutup {nick host handle chan text} { 
  global botnick
  if {![string match "*$botnick*" $text]} { return }
  putserv "PRIVMSG $chan :$nick: Nice Try! " 
}
C
Cavemanm85de
Voice
Posts: 10
Joined: Mon Jul 05, 2004 8:39 am

Post by Cavemanm85de »

Strikelight, the $botnick is afaik a global variable which gets initializes when eggdrop parses it's conffile.
The nick is set way before the scripts are loaded.

I would have agreed with you, if the bind did not work at all.
But it does. If you 'declare' $botnick as global inside the proc you bind.

And that is the strange thing. As I understood the eggdrop scripting the procs get read the first time a bind is triggered. Which is why the bot seems to lag a bit the first time.

Your code might be a work around when the bind does not work.
But I strongely suggest not to do the matching inside the proc.
It may be a good style, but people running the bot on small machines might face a problem, as your code does a double-check. First inside the bind (matching for '*shut*up*') and then inside the proc (matching for '$botnick'). And this makes for two checks for every line of text.

But I still have the same problem Chojin has...
Am I using a bug or is this illogical handling some kind of abstract logic thing out of my grasp?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Cavemanm85de,

Strikelight was right -- the botnick variable is set when eggdrop connects to the server and is assigned a nickname, not when the bot loads the config file. You might be thinking of the $nick variable instead. The $botnick variable does exist, of course, but it will be blank.

Solution: create the bind after connection/registration to the server is complete. Try 376 (I think) -- end of motd message.
C
Cavemanm85de
Voice
Posts: 10
Joined: Mon Jul 05, 2004 8:39 am

Post by Cavemanm85de »

imho is the discussion wether it get's set on connect or on startup mood.

It works this way

--
proc bot_shutup {nick host handle chan text} {
global botnick
putserv "PRIVMSG $chan :$nick: Nice Try! "
}

bind pubm - "% $botnick*shut*up*" bot_shutup
--

but not if I leave 'global' out of it.

As for binding it after conneting seems also mood to me as it is a pubm bind which can not be executed if the bot is not joined to a channel.

Sorry if I seem to obnoxious...

Why do I have to set a global in a lower level of code if it get's used in a higher level? I have spent more than 2 days searching and still gotten no clue :(
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Dude, you have seen both me and stdragon tell you about $botnick...

From doc/tcl-commands.doc:
botnick

Value: the current nickname the bot is using (for example: "Valis", "Valis0", etc.)

Module: server
Now, if the bot has NOT connected to IRC, (ie. when you first start your eggdrop from the shell), your bot will not have a current nickname, because it has not yet connected to irc... this is fairly simple to understand, and is not a hard concept to grasp.

And because it doesn't get set on startup, whereas your bind DOES, the binding will be INCORRECT, thus will NOT work when you try it, regardless of your usage of "global".... The only reason it works is because you are .rehash'ing your bot after it has already connected to irc, thus $botnick has been initialized, thus the binding will use that value correctly.

So again, to reiterate, the problem occurs when you are starting your bot out for the first time.... See my previous post for the solution.

Oy vay...

(btw. the word you were looking for was "moot" not "mood", even though the solution we've given is NOT "moot").
Locked