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.

Joining a channel, then checking if the user is an op.

Old posts that have not been replied to for several years.
Locked
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Joining a channel, then checking if the user is an op.

Post by Aron »

Im working on a script that allows users to type a certain trigger (!trigger <channel>, after which the bot joins the specified channel, and checks if the user is an OP.

If the user isnt an OP, the bot leaves again. The problem is that it wont recognize anyone as an OP, even though they are opped.

Thanks in advance.
The best way to start learning is to start helping.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

That's probably because you're checking [isop $the_dude] before the bot has recieved the entire /WHO list. (Triggered by a join bind?) Eggdrop does '/WHO #chan' upon joining a new channel to get its info about the people there and doesn't care about the /NAMES recieved :P

You can either wait a few moments for the RPL_ENDOFWHO (318), and then use [isop] or parse every RPL_NAMREPLY (353) recieved. (You get those no matter what and they arrive before the /WHO is even sent in most cases)
OR you could do it the lazy way and just add a slight delay after joining. (ugly hack IMO)
Have you ever read "The Manual"?
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

yeah i already tried something with a delay (timers) , but it was the first time i actually used timers, and well.... the delay didnt work :(

I figure it must be about one line of code, but i cant seem to get a working delay.. Any ideas?
The best way to start learning is to start helping.
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

sorry for bumping...

Post by Aron »

Excuse my bumping, but i just can't figure out how to make a working delay... I tried timers, but it wont work :(
The best way to start learning is to start helping.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: sorry for bumping...

Post by user »

AsoAron wrote:I tried timers, but it wont work :(
How are we supposed to correct your code when you don't show it to us? :)
Did you try a raw bind with that RPL_ENDOFWHO numeric I suggested?
Have you ever read "The Manual"?
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

alright, here we go :)
This is not the entire script, but i think this is the most relevant part..:

Code: Select all

proc addstats {nick host hand chan arg} {
  global file handle channel statchans

  set handle $hand

  set channel [lindex $arg 0]

  if {[validchan $channel]} { 
    putserv "NOTICE $nick :I already have a record for that channel.."
    return 0
  }
  channel add [string tolower $channel]
  utimer 10 [check_op $nick $channel $host]
}

proc check_op {nick channel host} {
  global file
  if {![isop $nick $channel]} { 
    channel remove $channel
    putserv "NOTICE $nick :You must be an OP in $channel to request me!"
    return 0
  } else {
      set fs [open $file a+] 
        puts $fs "### Channel added by $nick ($host) ###" 
        puts $fs "<channel=\"$channel\">"
        puts $fs "  Logfile=\"/home/aron/jabot/mel/logs/[string trim $channel ?#?].log\""
        puts $fs "  Format=\"mIRC\""
        puts $fs "  Network=\"quakenet\""
        puts $fs "  OutputFile=\"/home/aron/public_html/[string trim $channel #].html\""
        puts $fs "</channel>"
        puts $fs " "
      close $fs
      mel_add +chan [string tolower $channel]
      lappend statchans "$channel"
  }

}
Just for clearification, the problem is that the bot doesnt see the specified user as an OP when he joins the channel, which is why i wanted to create a delay, after which it will check. This is done with a 10 second utimer, but somehow, it wont work.

Thanks in advance :)

-A
The best way to start learning is to start helping.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

The problem is in this line:
AsoAron wrote:

Code: Select all

utimer 10 [check_op $nick $channel $host]
...which will, because of command substitution, be executed right at that moment and the return value from check_op will be executed 10 seconds later. This problem has been discussed before and a quick forum search should give you some working examples.
Have you ever read "The Manual"?
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

Alright, thanks for the help. Its working now :)

Now, there's another problem..

I want to store all channels the bot will send a message to, to a text file, seperated by spaces, on one line.
But when i use "lappend" to add the channel to the list, it wont add it, although it does write the already existing channels to the file.

Here's the code:

Code: Select all

proc statchans {arg channel} {
    global statsfile
    if {$arg == "r"} {
      set fs [open $statsfile r] 
        gets $fs x
        set statchans $x
      close $fs
      return $statchans
  } elseif {$arg == "a"} {
      set fs [open $statsfile r]
        gets $fs x
        set statchans $x
      lappend statchans $channel
      close $fs
      set fs [open $statsfile w]
        puts $fs $statchans
      close $fs
  }
}
... and yes, $channel is a working variable.
The best way to start learning is to start helping.
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

nevermind, im stupid. I should have used $x as a variable.
The best way to start learning is to start helping.
Locked