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.

[SOLVED] A little problem with the INVITE raw

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

[SOLVED] A little problem with the INVITE raw

Post by Riddler »

Hello guys, I`m having a issue with my code

The Code

Code: Select all

set si(mc) "#monitoringchan"

set si(ac) "#alertchan"

set si(except) {
 "*!cservice@undernet.org"
 "*!*@me.users.undernet.org"
}

bind raw - INVITE show:invite

proc show:invite { nick uhost key args } {
 global botnick si
  set nik [lindex [split $nick !] 0]
  set host [lindex [split $nick !] 1]
  set ban [lindex [split $nick @] 1]
  set text [lindex [split $args #] 1]
  foreach ehost $si(except) {
    if {[string match $ehost "$nik!$host"]} { return 0 }
  }
     putserv "PRIVMSG $si(ac) :INVITE SPAM by\0032 $nik \003\[$host\]: invited to $text"
     putserv "PRIVMSG $si(mc) :.ban *!*@$ban Inviter!"
}
The Error:
On Alert chan

(05:03:22) <bot> INVITE SPAM by XXXX [~xxx@127.0.0.1]: invited to ......
I can't get the right setting for $text so that will see in the alert chan, .... the channel that the bot got invited to by XXXX

Have any ideas ?
Last edited by Riddler on Sun Dec 16, 2007 8:56 pm, edited 2 times in total.
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, it would appear you've got the parameters for your proc slightly off..
(17) RAW (stackable)
bind raw <flags> <keyword> <proc>
procname <from> <keyword> <text>

Description: previous versions of Eggdrop required a special compile
option to enable this binding, but it's now standard. The keyword
is either a numeric, like "368", or a keyword, such as "PRIVMSG".
from will be the server name or the source user (depending on
the keyword); flags are ignored. The order of the arguments is
identical to the order that the IRC server sends to the bot. The
pre-processing only splits it apart enough to determine the
keyword. If the proc returns 1, Eggdrop will not process the line
any further (this could cause unexpected behavior in some cases).
Module: server
That is, there should be only three arguments. Furthermore, in your case, you are using the special argument "args" wich may take 0 or more parameters, and concatenates them into a list (in this case, an empty list as there is no 4th or further parameters).

Now, what will your variables contain? (assuming rfc1459 compliant server)
nick: "nick"
uhost: "INVITE"
key: "botnick #channel"
args: ""

First off, I would suggest that you adjust your proc's argument-list, using "args" when it's not needed is a very bad idea. Also, using names that clearly illustrate the contents helps alot.

Secondly, as rfc1459 requires the server to provide the nickname of the provider, and not full host, you'll need to use the "getchanhost" command. Keep in mind that this will only work if the nick is currently in any of the eggdrop's channels.
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Hey,

I do agree with you nml375, I`ve just made the script yesterday and never worked with the INVITE raw before :o
So thanks for the info about how to use that raw... I`ll paste the code again with the modifications...

Code: Select all

set si(mc) "#monitoringchan"

set si(ac) "#alertchan"

set si(except) {
 "*!cservice@undernet.org"
 "*!*@me.users.undernet.org"
}

bind raw - INVITE show:invite

proc show:invite {from key args} {
 global botnick si
  set nick [lindex [split $from !] 0]
  set host [lindex [split $from !] 1]
  set ban [lindex [split $from @] 1]
  set text [lindex [split $args] 1]
  foreach ehost $si(except) {
    if {[string match $ehost "$nick!$host"]} { return 0 }
  }
     putserv "PRIVMSG $si(ac) :INVITE SPAM by\0032 $nick \003\[$host\]: invited me to $text"
     putserv "PRIVMSG $si(mc) :.ban *!*@$ban Inviter!"
}
So I've made try this code with the modification and now it's working a little better but still ...
(20:48:06) <bot> INVITE SPAM by XXXX [~ident@127.0.0.1]: invited me to #chan}
the rest of the script is working great, only that "}" I need to remove...

And if I change this:

Code: Select all

  set text [lindex [split $args] 1]
with this:

Code: Select all

  set text $args 
the result will be this:
(20:34:11) <bot> INVITE SPAM by XXXX [~ident@127.0.0.1]: invited me to {bot #chan}
So... how do I extract the #chan from $args ?!
I am a man of few words, but many riddles
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:Furthermore, in your case, you are using the special argument "args" wich may take 0 or more parameters, and concatenates them into a list
Guess you didn't read this part. Your use of args is making those { } in creating the list, and your further splitting complicates it. Your getting two words you see, in one as a string. You need to split the string and then lindex it for its 2nd part. Using args creates a list containing a single two word element, not what you had intended..

Code: Select all

proc show:invite {from key text} {
...
set text [lindex [split $text] 1]
perhaps? :roll:

edit: or even, if you insist on using args:

Code: Select all

set text [lindex [split [lindex $args 0]] 1]
Last edited by speechles on Sun Dec 16, 2007 8:06 pm, edited 4 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Riddler:
As I said, don't use "args" as a argument name unless you really understand how it works, and really need it's behaviour.
A somewhat common misconception is that eggdrop will add one argument for each word in the message. That is not the case, the number of parameters is always the same, and thus your proc should accept a fixed number of arguments. Hence there is no need or use for "args". Follow speechles suggestion and use "text" instead, which has no special function.
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Upsss.... :shock: sorry if I didn't pay attention :?

@speechles: thanks for the ideea, the script it's working great now :lol:

@nml375: I didn't really know untill now, what's the real function of the "args" argument... sorry again... but I`ve saw some other codes ( I needed a example on how the raw INVITE proc works )....... so that's why my code wasn't "by the book".... as you guys ar tryin to make me understand :)

Maybe next time I should ask you guys first and not only trust a tcl code ( not all of them ar very good coded :x )

Anyway thanks again speechles & nml375 for the support on this issue :D
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Studying other peoples code is a good start on learning any coding language, just remember to cross-reference with a good instruction documentation or similar when you find something "interresting" or new.

None can be expected to make flawless code from the beginning, keep up the good work. And don't be afraid of asking whenever something is unclear or you can't seem to find the right answer on your own.
NML_375
Post Reply