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.

Communication between scripts

General support and discussion of Eggdrop bots.
Post Reply
A
Avalanchee
Voice
Posts: 4
Joined: Mon Jun 22, 2015 8:40 am

Communication between scripts

Post by Avalanchee »

Hello,
I would like to know what is the best way to reuse code between different scripts?

I'll split my post into multiple questions:

1) Is there a way to invoke a procedure that belongs to script #1 from within script #2?
I know about the "source" command, but I don't think it's healthy to invoke the same script multiple times. script #1 contains binds and one-time inits which I don't want to run more than once.

2) Is there a way to trigger a bind manually? I mean script #1 binds the proc to a specific event, which script #2 will trigger using some TCL command.

3) Relates to question #2 - Is there a way to make the bot trigger events on their own IRC commands? For instance, if I bind something to pubm on #chan - can the bot somehow trigger that event when it performs PRIVMSG #chan text?

Thank you for your help.

[EDIT: I was able to solve 1) using namespaces. Would still like to hear opinions regarding 2) and 3)]
w
willyw
Revered One
Posts: 1197
Joined: Thu Jan 15, 2009 12:55 am

Re: Communication between scripts

Post by willyw »

Avalanchee wrote: ...

1) Is there a way to invoke a procedure that belongs to script #1 from within script #2?
Think of a proc as a new command.
Just use it the same as you would any other command. (assuming when you call it, you are in the same namespace - I see that you have discovered them )

2) Is there a way to trigger a bind manually? I mean script #1 binds the proc to a specific event, which script #2 will trigger using some TCL command.
Can you elaborate more? Give an example if you can.

Also, check out:
http://www.eggheads.org/support/egghtml ... mands.html
and text search for
callevent
In some certain situations, it might do what you want. Else, we will see what you specifically have, via the examples you post.
3) Relates to question #2 - Is there a way to make the bot trigger events on their own IRC commands? For instance, if I bind something to pubm on #chan - can the bot somehow trigger that event when it performs PRIVMSG #chan text?
The bot doesn't 'see' its own posts.

Here can be found a way to make it log its own posts:
http://thommey.tclhelp.net/?page=scripts

But - again, how about some example or more description of what you are really wanting to do?
What comes to mind, is instead of having the bot do:
putserv "privmsg #chan ...
in hopes of triggering the bind, just call the proc right there, that the bind would have called anyway. If you need to have the public post, then simply do both.

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
A
Avalanchee
Voice
Posts: 4
Joined: Mon Jun 22, 2015 8:40 am

Post by Avalanchee »

Thanks for the answer :)

First of all I'll explain my scenario.
I have a bot with multiple scripts that each have their own bind such as: 'bind pubm -|- * MyProc'.
In addition, the bot has a "web chat" functionality - meaning users are able to connect via web and see the chat log, as well as write lines.
Naturally, as far as the IRC server sees it, those lines are originated from the bot.
The bottom line is that I'd like for all the pubm (et al.) binds to trigger for lines that originate from the bot.
Also, check out:
http://www.eggheads.org/support/egghtml ... mands.html
and text search for
callevent
In some certain situations, it might do what you want. Else, we will see what you specifically have, via the examples you post.
Yea I found callevent but it appears to be a very specific set of events.
My idea was more about triggering a bind.
For instance I have a script with a bind:

Code: Select all

bind pubm -|- * Main
and would've liked to "artificially" trigger this pubm event using some special tcl command.
For example, it would be cool to be able to tap into the internal eggdrop buffer that receives pubm messages and manually insert a fake event (in this case, a channel message) into the queue.
The bot doesn't 'see' its own posts.
This is unfortunate.
I would've liked to have a specific bind for IRC events (such a pubm or topic) that originate from the bot.
What comes to mind, is instead of having the bot do:
putserv "privmsg #chan ...
in hopes of triggering the bind, just call the proc right there, that the bind would have called anyway. If you need to have the public post, then simply do both.
This could get complicated quickly.
It means that for each script that has a "putserv privmsg #chan", I need to add proc calls for all the other scripts.
i.e. for x scripts there needs to be x^2 proc calls.
Nonetheless it seems like this is the only viable option to do this.

I'd love to hear how would you guys solve this issue.
Thanks again.
A
Avalanchee
Voice
Posts: 4
Joined: Mon Jun 22, 2015 8:40 am

Post by Avalanchee »

I must've read tcl-commands.html a dozen times but I guess I missed this event:

45. OUT (stackable)

bind out <flags> <mask> <proc>
proc-name <queue> <text> <queued|sent>

Description: triggered whenever output is sent to the server. Normally the event will occur twice for each line sent: once before entering a server queue and once after the message is actually sent. This allows for more flexible logging of server output and introduces the ability to cancel messages. Mask is matched against "queue status", where status is either 'queued' or 'sent'. Queues are: mode, server, help, noqueue. noqueue is only used by the putnow tcl command.

Module: server
I believe this is exactly what I'm looking for.
Thanks dude!
Post Reply