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.

My request script. [wont validate.]

Help for those learning Tcl or writing their own scripts.
Y
Youri
Voice
Posts: 6
Joined: Tue Feb 08, 2005 7:03 am

My request script. [wont validate.]

Post by Youri »

Dear boys, and girls ;-)

I made my own script but there's a little problem. If i request the bot, the bot checks if the [requestedchannel] is in the blocklist, if it is he quits the validation. Thats all good, but if the channel is not in the blocklist a error comes up. The bot says [APPROVED] has been approved, validation will begin in a couple seconds. thats also good, the bot joins but does not continue with request:join_chan (the next chan).

View code below:

Code: Select all

###########################################################
# Package Name:          Request                          #
# Package Author:        Youri < xeonnn@gmail.com >       #
# Package Version:       1                                #
###########################################################
bind pub -|- .request pub:request
bind msg -|- .help pub:help

proc pub:help {nick uhost handle text} {
  putserv "PRIVMSG $nick : \[HELP\] To request the bot, typ .request <channel>"
  putserv "PRIVMSG $nick : \[HELP\] The channel needs to have minium 20 people, and you need a operator status."
  putserv "PRIVMSG $nick : \[HELP\] If the requested channel doesnt require the rules the bot will leave."
}
proc pub:request {nick uhost handle chan text} {
   set requestchannel [string tolower [lindex $text 0]]
   set requestnick [split $nick]
   set blocked(active) no
   set blocked(channels) {
    "#help"
    "#xeoN.development"
   }

   foreach block $blocked(channels) {
     if { $block == $requestchannel } { set blocked(active) yes  }
   }

  if { $blocked(active) == yes } {
     putserv "PRIVMSG $nick : \[ERROR\] $requestchannel has been blocked from the request service."
  } else {
     channel add $requestchannel
     putserv "PRIVMSG $nick : \[APPROVED\] $requestchannel has been approved, validation will begin in a couple seconds."
     request:join_chan $requestchannel $requestnick
  }
}

proc request:join_chan { requestchannel requestnick } {
  set t_users [llength [chanlist $requestchannel]]
  set usercheck [expr $t_users - 1]

  if { $usercheck >= 20  && [isop $requestnick] } {
    putserv "PRIVMSG $requestnick : \[VALIDATION\] Found 20, or more users in $requestchannel ."
    putserv "PRIVMSG $requestnick : \[VALIDATION\] You have operator(@)."
    putserv "PRIVMSG $requestnick : [\VALIDATION\] The channel meets the requirements, the bot will stay."
  } else {
    putserv "PRIVMSG $requestnick : \[ERROR\] The channel does not meet the requirements."
    putserv "PRIVMSG $requestnick : \[ERROR\] Typ .help to see the requirements."
    channel remove $requestchannel
  }

}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The problem is most likely due to the fact that your bot most likely hav'nt had time to gather any information about the channel by the time you call request:join_chan. The time for this may be from just a few secs for small channels, to 20secs or more for large channels (basically the time it takes to retrieve the output, and parse it, from a "WHO #channel" request).

I would probably use a timer to delay the member-check a minute or two.

A somewhat more advanced way of doing it would be to manually capturing the data of the who-request using raw bindings. Making any mistakes here might result in your bot behaving very oddly however.
NML_375
Y
Youri
Voice
Posts: 6
Joined: Tue Feb 08, 2005 7:03 am

Post by Youri »

nml375 wrote:The problem is most likely due to the fact that your bot most likely hav'nt had time to gather any information about the channel by the time you call request:join_chan. The time for this may be from just a few secs for small channels, to 20secs or more for large channels (basically the time it takes to retrieve the output, and parse it, from a "WHO #channel" request).

I would probably use a timer to delay the member-check a minute or two.

A somewhat more advanced way of doing it would be to manually capturing the data of the who-request using raw bindings. Making any mistakes here might result in your bot behaving very oddly however.
So the request:join_chan isnt wrong or something?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: My request script. [wont validate.]

Post by user »

Youri wrote:

Code: Select all

    putserv "PRIVMSG $requestnick : \[VALIDATION\] You have operator(@)."
    putserv "PRIVMSG $requestnick : [\VALIDATION\] The channel meets the requirements, the bot will stay."
"[" != "\["
Have you ever read "The Manual"?
Y
Youri
Voice
Posts: 6
Joined: Tue Feb 08, 2005 7:03 am

Post by Youri »

thanks user, works HALFY now :-)

i think i need to work with a timer indeed. :-)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Shouldn't need any timers, since the bot will wait til the result of [chanlist] is returned before doing the next commands..


Try putting some "putcmdlog" lines into your script to aid in debugging the process.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

chanlist will output the content of eggdrop's internal list of channel-members, it will not trigger a fetch from the server. Thus, if you call it too soon from your eggie joining a channel, you will not get a list of the channel members.
Hence, you'd need to delay that process until the internal list has been fully updated... Either using a timer, or a raw binding triggering on the numeric for "End of who".
NML_375
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

i bind to raw 315 (end of /who), and then continue.

Code: Select all

###########################################################
# Package Name:          Request                          #
# Package Author:        Youri < xeonnn@gmail.com >       #
# Package Version:       1                                #
###########################################################
bind pub -|- .request pub:request
bind msg -|- .help pub:help

set requestchannel ""
set requestnick ""

proc pub:help {nick uhost handle text} {
  putserv "PRIVMSG $nick : \[HELP\] To request the bot, typ .request <channel>"
  putserv "PRIVMSG $nick : \[HELP\] The channel needs to have minium 20 people, and you need a operator status."
  putserv "PRIVMSG $nick : \[HELP\] If the requested channel doesnt require the rules the bot will leave."
}
proc pub:request {nick uhost handle chan text} {
   global requestchannel requestnick
   set requestchannel [string tolower [lindex $text 0]]
   set requestnick [split $nick]
   set blocked(active) no
   set blocked(channels) {
    "#help"
    "#xeoN.development"
   }

   foreach block $blocked(channels) {
     if { $block == $requestchannel } { set blocked(active) yes  }
   }

  if { $blocked(active) == yes } {
     putserv "PRIVMSG $nick : \[ERROR\] $requestchannel has been blocked from the request service."
  } else {
     catch {bind raw - {315} request:endofwho}
     channel add $requestchannel
     putserv "PRIVMSG $nick : \[APPROVED\] $requestchannel has been approved, validation will begin in a couple seconds."
  }
}

proc request:endofwho {from raw arg} {
   global requestchannel requestnick
   if {[string equal -nocase [lindex [split $arg] 1] $requestchannel]} {
      request:join_chan $requestchannel $requestnick
      catch {unbind raw - {315} request:endofwho}
   }
}

proc request:join_chan { requestchannel requestnick } {
  set t_users [llength [chanlist $requestchannel]]
  set usercheck [expr $t_users - 1]

  if { $usercheck >= 20  && [isop $requestnick] } {
    putserv "PRIVMSG $requestnick : \[VALIDATION\] Found 20, or more users in $requestchannel ."
    putserv "PRIVMSG $requestnick : \[VALIDATION\] You have operator(@)."
    putserv "PRIVMSG $requestnick : [\VALIDATION\] The channel meets the requirements, the bot will stay."
  } else {
    putserv "PRIVMSG $requestnick : \[ERROR\] The channel does not meet the requirements."
    putserv "PRIVMSG $requestnick : \[ERROR\] Typ .help to see the requirements."
    channel remove $requestchannel
  }

}
Might work, might not.
r0t3n @ #r0t3n @ Quakenet
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Idea looks good, a few thoughts tho..
When working with raw-bindings, the returncode of the proc is very important, as it determines wether any further processing will be done, and bindings added with scripts trigger before those built in. If a return-value is not provided explicitly, an implicit return-value will be generated from the last executed command within the proc (in this case; catch {unbind raw - {315} request:endofwho})

Also, would'nt it be easier to keep the binding active at all times, extract the channel-name from the message body, and check wether this matches the channel you're trying to validate (in theory, the triggered binding may be from a different who-query, although very unlikely).
NML_375
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

if you want the bind active all the time, remove the catch lines and add the bind raw line under the other pub/msg bind lines.
r0t3n @ #r0t3n @ Quakenet
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Still have to add proper return-values to prevent your eggie from going nuts...
doc/tcl-commands.doc wrote: (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
NML_375
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Updated:

Code: Select all

###########################################################
# Package Name:          Request                          #
# Package Author:        Youri < xeonnn@gmail.com >       #
# Package Version:       1                                #
###########################################################
bind pub -|- .request pub:request
bind msg -|- .help pub:help
bind raw - {315} request:endofwho

set requestchannel ""
set requestnick ""

proc pub:help {nick uhost handle text} {
  putserv "PRIVMSG $nick : \[HELP\] To request the bot, typ .request <channel>"
  putserv "PRIVMSG $nick : \[HELP\] The channel needs to have minium 20 people, and you need a operator status."
  putserv "PRIVMSG $nick : \[HELP\] If the requested channel doesnt require the rules the bot will leave."
}
proc pub:request {nick uhost handle chan text} {
   global requestchannel requestnick
   set requestchannel [string tolower [lindex $text 0]]
   set requestnick [split $nick]
   set blocked(active) no
   set blocked(channels) {
    "#help"
    "#xeoN.development"
   }

   foreach block $blocked(channels) {
     if { $block == $requestchannel } { set blocked(active) yes  }
   }

  if { $blocked(active) == yes } {
     putserv "PRIVMSG $nick : \[ERROR\] $requestchannel has been blocked from the request service."
  } else {
     channel add $requestchannel
     putserv "PRIVMSG $nick : \[APPROVED\] $requestchannel has been approved, validation will begin in a couple seconds."
  }
}

proc request:endofwho {from raw arg} {
   global requestchannel requestnick
   if {[string equal -nocase [lindex [split $arg] 1] $requestchannel]} {
      request:join_chan $requestchannel $requestnick
      return 1
   }
}

proc request:join_chan { requestchannel requestnick } {
  set t_users [llength [chanlist $requestchannel]]
  set usercheck [expr $t_users - 1]

  if { $usercheck >= 20  && [isop $requestnick] } {
    putserv "PRIVMSG $requestnick : \[VALIDATION\] Found 20, or more users in $requestchannel ."
    putserv "PRIVMSG $requestnick : \[VALIDATION\] You have operator(@)."
    putserv "PRIVMSG $requestnick : [\VALIDATION\] The channel meets the requirements, the bot will stay."
  } else {
    putserv "PRIVMSG $requestnick : \[ERROR\] The channel does not meet the requirements."
    putserv "PRIVMSG $requestnick : \[ERROR\] Typ .help to see the requirements."
    channel remove $requestchannel
  }

}
r0t3n @ #r0t3n @ Quakenet
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

nml375 wrote:chanlist will output the content of eggdrop's internal list of channel-members, it will not trigger a fetch from the server. Thus, if you call it too soon from your eggie joining a channel, you will not get a list of the channel members.
Hence, you'd need to delay that process until the internal list has been fully updated... Either using a timer, or a raw binding triggering on the numeric for "End of who".
I was not aware of that. Learned something new <tips hat> :)
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

rosc2112 wrote:
nml375 wrote:chanlist will output the content of eggdrop's internal list of channel-members, it will not trigger a fetch from the server. Thus, if you call it too soon from your eggie joining a channel, you will not get a list of the channel members.
Hence, you'd need to delay that process until the internal list has been fully updated... Either using a timer, or a raw binding triggering on the numeric for "End of who".
I was not aware of that. Learned something new <tips hat> :)
Also you can use the raw binding, with the command: /NAMES #channel
This can be done immediately on join and does not need any delay when called. It will give you the member-list of the channel from the server. Also nicks with ops and voices will have their respective operator sign infront of them.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Y
Youri
Voice
Posts: 6
Joined: Tue Feb 08, 2005 7:03 am

Post by Youri »

you missed a ] at

Code: Select all

proc request:endofwho {from raw arg} {
   global requestchannel requestnick
   if {[string equal -nocase [lindex [split $arg] 1]] $requestchannel]} {
      request:join_chan $requestchannel $requestnick
      return 1
   }
} 
Post Reply