mIRC Home    About    Download    Register    News    Help

Print Thread
Auto /part when channel is empty #181413 23/07/07 01:23 AM
Joined: Jul 2007
Posts: 6
U
UNOwen Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
U
Joined: Jul 2007
Posts: 6
I'm trying to write a script that'll part me from a channel when I'm the only user left in that channel.

I've got this far, but it's not working. Could someone please explain what else is needed.

Code:
on !*:part:#:{
  if ($nick(#,0) <= 1) {
      part $chan
  }
}
on !*:quit:#:{
  if ($nick(#,0) <= 1) {
      part $chan
  }
}


Thank you for your assistance!! smile

Re: Auto /part when channel is empty [Re: UNOwen] #181414 23/07/07 01:50 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The on quit event doesn't have a location for a channel parameter, so you need to loop through your channels

Code:
on !*:quit:{
  var %a = 1, %b = $chan(0)
  while %a <= %b {
    if $nick($chan(%a),0) = 1 {
      part $chan(%a)
    }
    inc %a
  }
}


Re: Auto /part when channel is empty [Re: UNOwen] #181415 23/07/07 02:11 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
On me:*:Join:#: {
  $+(.timerchkusers,.,$cid,.,$chan) 0 10 chkusers $chan
}

On me:*:Part:#: {
  if ($timer($+(chkusers,.,$cid,.,$chan))) $+(.timerchkusers,.,$cid,.,$chan) off
}

alias chkusers {
  if ($nick($1,0) == 1) {
    $+(.timerchkusers,.,$cid,.,$1) off
    part $1
  }
}


I'm not sure if there's a better way of doing this, and I've never really used $cid before.

When you join a channel a timer is started and checks every 10 seconds to see how many users are on the channel. If there's only 1 user (you) it parts the channel.

Re: Auto /part when channel is empty [Re: SladeKraven] #181417 23/07/07 06:26 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
No offense to your code, Slade, however, in my opinion, running a timer every 10 seconds would be a waste of resources.

Checking the number of users upon joining, is a good idea, but once that's done, then one only needs to check after people part, quit or are kicked.

In regards to the usage of $cid, for a code like this, it's not necessary, as the checking doesn't have to be done over multiple networks.
Here's my current recommendation for a full code
Code:
on me:*:join:#:{
  chkusers $chan
}
on !*:part:#:{
  chkusers $chan
}
on !*:quit:{
  chkusers $chan
}
on *:kick:#:{
  if $knick != $me {
    chkusers $chan
  }
}
alias chkusers {
  if $nick($1,0) == 1 {
    part $1
  }
}

Re: Auto /part when channel is empty [Re: RusselB] #181425 23/07/07 11:18 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Using your code I joined a room with 20 users in it, it parted me straight away.

Re: Auto /part when channel is empty [Re: SladeKraven] #181426 23/07/07 11:52 AM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
There's no point in checking if ($nick(#,0)) <= 1 because it could never go below 1 for as long as you're in the channel..

Here's some basic ones.

on *:QUIT:{ if ($nick != $me) { var %x = 1 | while ($comchan($nick,%x)) { var %v1 = $v1 | if ($nick($v1,0) == 1) { hop -c %v1 } | inc %x } }
on *:PART:#:{ if ($nick != $me) && ($nick($chan,0) == 1) { hop -c $chan } }

However, I extended some, and I don't think the next on quit works.

1.No point cycling a channel that's +i.
2.No point in cycling a channel when you're op.
3.If the channel is +r, ChanServ will -oh you you so you still get the +v, so no point in hopping it if you are +v.

Code:
on !*:part:#: { 
  if ($nick($chan,0) > 2) { /halt }
  else {
    if ($me isreg $chan) { 
      if (i !isin $chan($active).mode) {
        /hop $chan | /mode $chan +vh $me $me | echo $chan on part event
      } 
    }
  } 
}
on !*:quit: { 
  var %i = 1 
  while ($comchan($nick,%i)) { 
    if ($nick($comchan($nick,%i),0) > 2) { /halt }
    else {
      if (r !isincs $chan($chan).mode) && (i !isin $chan($chan).mode) {
        if ($me isreg $comchan($nick,%i)) {
          /hop -c $comchan($nick,1) | /mode $comchan($nick,%i) +vh $me $me 
        }
      } 
      if (r isincs $chan($chan).mode) {
        if ($me isreg $comchan($nick,%i)) {
          /hop -c $comchan($nick,%i)) | /mode $comchan($nick,%i) +vh $me $me
        }
      }
      inc %i 
    } 
    unset %i 
  } 
}



Re: Auto /part when channel is empty [Re: LostShadow] #181429 23/07/07 01:45 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Not all IRCds support the +h mode.

So maybe something like:

Code:
/mode $comchan($nick,%i) $+(+v,$iif(% isin $prefix,h $me)) $me


Without testing your code, I don't know how well it works but looking at this line:

Code:
if (r isincs $chan($chan).mode) {


$chan wouldn't have a value in the On Quit event.

Re: Auto /part when channel is empty [Re: SladeKraven] #181449 23/07/07 07:56 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Ah yes, I shall fix that. Thanks.

Re: Auto /part when channel is empty [Re: UNOwen] #181509 24/07/07 09:27 PM
Joined: Jul 2007
Posts: 6
U
UNOwen Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
U
Joined: Jul 2007
Posts: 6
I appreciate all your help.

Russel this one works in most instances:
Code:
on !*:quit:{
  var %a = 1, %b = $chan(0)
  while %a <= %b {
    if $nick($chan(%a),0) = 1 {
      part $chan(%a)
    }
    inc %a
  }
}


I've tried all the others except the last one by LostShadow and did't have much luck with them. Before I try yours LostShadow, I'm confused why you're using /hop instead of /part? Is that for debugging purposes? Could you please explain.

Re: Auto /part when channel is empty [Re: UNOwen] #181511 24/07/07 10:26 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
That would work fine when someone quits, but if they part the channel, leaving the OP alone on the channel, then the OP also wanted to depart the channel, which that code does not incorporate