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 

hooking multiple commands to the same function - possible?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming
View previous topic :: View next topic  
Author Message
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Tue Dec 06, 2005 8:30 am    Post subject: hooking multiple commands to the same function - possible? Reply with quote

hi guys,

I'm intending to write a module for which I need to hook multiple commands to the same function but still keep the possibility to figure out which command was called later on. The issue is that I'm totally new to eggdrop module programming, so I don't know if I can do that.
I've checked the TCL writing already and found that it seems to not be possible, is it possible when writing a module?

My main problem is that I cannot simply write a single function for a single trigger since I'm trying to write a li'l interpreter and don't know which triggers I will use in my scripts later on...

3d1t: Is it possible to just catch all the stuff ppl say in the channel? If it is, I can use that and "search" for the triggers myself...

Thx & Greetz MGee
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue Dec 06, 2005 11:27 am    Post subject: Reply with quote

just make a function to call the other functions...
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Tue Dec 06, 2005 12:45 pm    Post subject: Reply with quote

wow, I didn't ask for that great a detail, but thx anyway, that didn't help anything Twisted Evil Razz

what do you mean, call the other functions? what functions? sry, but I just don't get what you mean... Confused

I've made three functions already, one watching the channel, one waiting for /msgs and one keeping an eye at DCC which all cal the same interpreter function, but I don't want them to wait for a specific command or something. They're only supposed to call the interpreter on everything said, it will then determine what to do itself.

Greetz MGee
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue Dec 06, 2005 1:42 pm    Post subject: Reply with quote

Ah sorry, after reading it a third time I figured what you are talking. Well my general idea is still the one you are looking for. Just add an addional argument to your orignal function. Then create a new function with the orignal arguments for each command. Now call your original function with the arguments and the addional argument which contains an identifier for where it was called from. I would advice an int value presented by a DEFINE string for better readability of the source Smile.

btw. if you are going to hook them via the tcl command "bind" you can skip the thing with the new function (but still create a new argument, it must be inserted at the first place) and just use something like: bind dcc o command {function arg1}
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Tue Dec 06, 2005 2:14 pm    Post subject: Reply with quote

well, this is how far I have come yet:
http://mistagee.selfip.net:8080/mistagee/phparse.c

I'm trying to teach my eggdrop how2 use php since I _hate_ Evil or Very Mad TCL, and I just don't know how to make the module react to the triggers ppl use in IRC. the rest should (!) work, I didn't yet have the chance to test it. (how come..? Razz ) But for now, I only need help talking to my eggdrop.

This enourmous parser is used to allow the php script0rz to make the bot say something in IRC via printing the text in a specific syntax to stdout, which is then read by the eggdrop. In fact, this is the only function I'm pretty sure it'll work.

After having a look at it, you'll have better chances to give me a real clue ;p

Greetz MGee
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Dec 06, 2005 11:50 pm    Post subject: Reply with quote

check eggdrop source, see how Tcl binds work (in your case, [bind pub])
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
turbo0O
Voice


Joined: 31 Dec 2005
Posts: 4

PostPosted: Wed Jan 04, 2006 8:22 pm    Post subject: progress? Reply with quote

Have you made any further progress with your eggdrop PHP parser? I've been thinking about doing something like this for awhile now.
Back to top
View user's profile Send private message
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Wed Jan 04, 2006 8:47 pm    Post subject: Reply with quote

well I haven't come too far, been busy with other stuff.... we could write the plugin together though, I thought of checking how apache accesses PHP and just do the same with eggdrop...
I need to read and understand the apache and eggdrop source now and learn how2 write eggdrop modules... quite a pile of work to do Wink

It's just that atm I don't have too much time left to do that...

Greetz MGee
Back to top
View user's profile Send private message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Fri Jan 20, 2006 7:50 pm    Post subject: Reply with quote

Hmmm...your problem sounds like the same thing I tried to do.

But lets see...my problem was:

I wanted to have it that way:
Code:

!token1 cmd1 --> myfunc()
!token1 cmd2 --> myfunc()
!token1 cmd3 --> myfunc()
!token2 cmd1 --> myfunc()
!token2 cmd2 --> myfunc()

Unfortunatly you cannot bind function names with spaces.
Also I wanted to have a single input function for all commands regged by my module.
The problem that showed up was that eggdrop calls the bound function without the actual command token which triggered the event.


The solution I now use is rather tricky and was quite time consuming.
It also requires modifying the eggdrop sources:

  • When using add_builtins() with the cmd_t structure I use "cmd_t.funcname" to kinda tag my function
  • In check_tcl_bind() [tclhash.c] that tag appears in tcl_cmd_t.func_name.
    That value can be used to check for functions bound by your module
  • check_tcl_dcc() binds the command arguments, nick etc. to the Tcl variables ("_dcc1" etc).
    There I bind the command token to my own variable using Tcl_SetVar.
  • In check_tcl_bind() I extract that variable from Tcl (Tcl_GetVar)and modify the command arguments to contain the command token before executing the trigger.


There might also be another possibility to achieve the same goal:
Bind the commands to MSGM, PUBM and FILT instead of MSG, PUB and DCC.
Those pass the whole text including the command token.
However they are matched against the whole line and not just via the start of the line and thus might trigger your binds too often.


Quote:

MSGM (stackable)

bind msgm <flags> <mask> <proc>
procname <nick> <user@host> <handle> <text>

Description: matches the entire line of text from a /msg with the mask. This is useful for binding Tcl procs to words or phrases spoken anywhere within a line of text.
---------
PUBM (stackable)

bind pubm <flags> <mask> <proc>
procname <nick> <user@host> <handle> <channel> <text>

Description: just like MSGM, except it's triggered by things said on a channel instead of things /msg'd to the bot. The mask is matched against the channel name followed by the text and can contain wildcards. Also, if a line triggers a PUB bind, it will not trigger a PUBM bind.
---------
FILT (stackable)

bind filt <flags> <mask> <proc>
procname <idx> <text>

Description: party line and file system users have their text sent through filt before being processed. If the proc returns a blank string, the text is considered parsed. Otherwise, the bot will use the text returned from the proc and continue parsing that.



Unfortunatly I found out about that just today after putting in the solution mentioned first Very Happy
If you need any more hints post below...

Regards,
Kappa
Back to top
View user's profile Send private message
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Sat Jan 21, 2006 7:04 am    Post subject: Reply with quote

thanxXx a great lot!

Unfortunately I don't have too much time for this, so I had to delay the project, but soon I'll have two months of holidays and I guess I'ma continue my project then and see how far I can get.

Greetz MGee
Back to top
View user's profile Send private message
OpEn_FiRe
Voice


Joined: 29 Jan 2006
Posts: 2

PostPosted: Sun Jan 29, 2006 10:14 am    Post subject: Reply with quote

If i understood this right it wouldnt be necessary to modify the eggdrop code just to find out wich bind called that proc...
when a bind is triggered it saves the match used in a variable called lastbind.
So all you need to do is add the lastbind to the global part of your proc and u will have wich bind started that proc... Very simple when u read the documentation that comes with eggdrop actually
Back to top
View user's profile Send private message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Mon Jan 30, 2006 5:52 pm    Post subject: Reply with quote

OpEn_FiRe wrote:
If i understood this right it wouldnt be necessary to modify the eggdrop code just to find out wich bind called that proc...
when a bind is triggered it saves the match used in a variable called lastbind.
So all you need to do is add the lastbind to the global part of your proc and u will have wich bind started that proc... Very simple when u read the documentation that comes with eggdrop actually


Indeed!

Quote:

Tcl_SetVar(interp, "lastbind", (char *) fullmatch, TCL_GLOBAL_ONLY);


Just one line above the changes I applied *doh*
Guess I should have read the docs Cool
Back to top
View user's profile Send private message
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Tue Jan 31, 2006 8:52 am    Post subject: Reply with quote

I'm reading the eggdrop source code right now in order to find out how the TCL module makes eggdrop call the function that checks the binds whenever needed, but I can't figure out how this is actually done since the author chose to not add any helpful comments at all.

I'm not intending to implement this /msg and DCC stuff right now, so lezz just pretend it wouldn't exist until the "normal" chat binds work Smile

Can I actually register my chat binds with eggdrop, so that eggdrop calls a function in my module everytime a chatter uses the bind? Then I'd just have to check which bind it was, and make PHP execute the according script.

If not:
Can I tell Eggdrop to call a function everytime any chatter says something and then check for a bind myself?

Both ways, I will need eggdrop to tell my function what the user actually said, and I'll need some way to figure out which bind was actually used.

Finding out which chat bind belongs to which file won't be too hard, I'll just implement that with a register_bind() function or something in the php scripts, but I need a command to add into eggdrop.conf which tells my module to use a specific php script.
How do I introduce a command to eggdrop which is intended to be used in the config? Can I actually use every command in there or do I have to do something special?

Greetz MGee
Back to top
View user's profile Send private message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Tue Jan 31, 2006 7:31 pm    Post subject: Reply with quote

Not quite sure what you mean but as OpEn_FiRe pointed out, if you bind
!cmd1 -> myfunc()
!cmd2 -> myfunc()
!cmd3 -> myfunc()

Just call Tcl_GetVar(...,"lastbind") in myfunc() to find out what command (!cmd1, !cmd2, !cmd3) triggered it.
Back to top
View user's profile Send private message
MistaGee
Voice


Joined: 06 Dec 2005
Posts: 7

PostPosted: Thu Feb 02, 2006 7:55 am    Post subject: Reply with quote

I think I understood Eggdrop module coding by now and I know a little bit what I'm doing... How do I have to use this Tcl_GetVar function? Atm I'm doing it like this:
Code:
   char* used_bind;
   used_bind = Tcl_GetVar(interp, "lastbind", 0);

is that correct? (It actually does compile...)

Still I need an idea how to establish the communication to the PHP part of the module, and until I found out how to do that, I won't be able to develop the eggdrop part further...

Greetz MGee
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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