mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
<nick-1> !Add alpha
-nick-2- You are in the Alpha group
<nick-1> !groups
<nick-2> Group Alpha 1 users
<nick-2> Group Beta 0 users
<nick-1> !Add beta
-nick-2- You are in the Beta group
<nick-1> !groups
<nick-2> Group Alpha 0 users
<nick-2> Group Beta 1 users

Code:
on $69:text:$(/^[!](groups)$/Si):#: {
  if $regml(1) = groups { msg # Group Alpha $numtok(%alpha,32) users | msg # Group Beta $numtok(%beta,32) users }
}

on *:text:*:#:{
  if $strip($1) = !add && !$3 { 
    if $strip($2) = alpha {
      if $istok(%beta,$nick,32) { set %beta $remtok(%beta,$nick,1,32) }
      if !$istok(%alpha,$nick,32) { 
        set %alpha $addtok(%alpha,$nick,32)
        notice $nick You are in the Alpha group
      }
    }
    elseif $strip($2) = beta { 
      if $istok(%alpha,$nick,32) { set %alpha $remtok(%alpha,$nick,1,32) } 
      if !$istok(%beta,$nick,32) { 
        set %beta $addtok(%beta,$nick,32)
        notice $nick You are in the Beta group
      }
    }
    else { msg # Group nonexistent. Use: !group  }
  } 
}

Thanks!!!

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Suggestion:
Code:
on *:text:*:#:{
  tokenize 32 $strip($1-)
  if ($1 == !add) { 
    if $istok(alpha beta,$2,32) {
      var %temp = $iif($2 == alpha,beta,alpha)
      set $+(%,%temp) $remtok($($+(%,%temp),2),$iif($3,$3,$nick),1,32)
      var %temp = $iif(%temp == alpha,beta,alpha)
      set $+(%,%temp) $addtok($($+(%,%temp),2),$iif($3,$3,$nick),32)
    } 
    else { msg # Group nonexistent. Use: !group alpha or !group beta }
  }
}


Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
RusselB, I'm not 100% sure about that suggestion... If I may,...
Code:
on *:text:*:#:{
  tokenize 32 $strip($1-)
  if ($1 == !add) { 
    if !$istok(alpha beta,$2,32) {
      msg # Group nonexistent. Use: !group alpha or !group beta
      return
    }

    var %temp = % $+ $iif($2 == alpha,beta,alpha)
    var %nick = $iif($3,$3,$nick)
    set $+(%temp) $remtok($(%temp,2),%nick,1,32)

    %temp = % $+ $2
    set $+(%temp) $addtok($(%temp,2),%nick,32)
  }
}


Optimize for... speed, or size?
Code:
alias init_commands {
  hmake commands
  hadd commands !add cmd_add
  hadd commands !groups cmd_groups

  hmake commands_add
  hadd commands_add alpha cmd_add_alpha
  hadd commands_add beta cmd_add_beta

  hmake alpha
  hmake beta
}

alias cmd_add {
  if ($hget(commands_add,$1)) {
    $v1
  }
  else {
    msg # Group nonexistent. Use: !group
  }
}

alias cmd_groups {
  msg # Group Alpha $hget(alpha,0).item users
  msg # Group Beta $hget(beta,0).item users
}

alias cmd_add_alpha {
  if $hget(beta,$nick) { hdel beta $nick }

  ; you could store other data here... 
  hadd alpha $nick $true
}

alias cmd_add_beta {
  if $hget(alpha,$nick) { hdel alpha $nick }

  ; you could store other data here... 
  hadd beta $nick $true
}

on 1:LOAD: { init_commands }
on 1:START: { init_commands }

on *:text:*:#:{
  if ($3) { return }
  if ($hget(commands,$strip($1))) { $v1 $strip($2) }
}

Last edited by s00p; 09/11/09 10:11 AM.
Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
I hope you've read my previous message. Here's the next step to reducing needless whitespacing:
Code:
on *:text:*:#:{
  tokenize 32 $strip($1-)
  if ($1 != !add) { 
    return
  }
  else if !$istok(alpha beta,$2,32) {
    msg # Group nonexistent. Use: !group alpha or !group beta
    return
  }

  var %temp = % $+ $iif($2 == alpha,beta,alpha)
  var %nick = $iif($3,$3,$nick)
  set $+(%temp) $remtok($(%temp,2),%nick,1,32)

  %temp = % $+ $2
  set $+(%temp) $addtok($(%temp,2),%nick,32)
}

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Your latest suggestion requires the first word to be !add, yet if the 2nd word isn't alpha or beta, the outgoing message says to use !group

Thus following the format from the outgoing message, the initial command would never be executed, since !add != !group

Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Correct. That's the same behaviour as your suggestion.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Opps.. my mistake and my apologies.

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117

<any_nick> !Add alpha
-Your_Bot- You are in the Alpha group
<any_nick> !groups
<Your_Bot> [Group] Alpha 1 users [Group] Beta 0 users
<any_nick> !Add beta
-Your_Bot- You are in the Beta group
<any_nick> !groups
<Your_Bot> [Group] Alpha 0 users [Group] Beta 1 users

Code:
on $*:text:/^!groups$/iS:#:msg # [Group] Alpha $numtok(%alpha,32) users [Group] Beta $numtok(%beta,32) users

on $*:text:/^!add\b/iS:#:{
  tokenize 32 $strip($1-)
  if $istok(alpha beta,$2,32) {
    set $+(%,$2) $addtok($($+(%,$2),2),$nick,32)
    var %2 = $iif($2 == alpha,beta,alpha)
    set $+(%,%2) $remtok($($+(%,%2),2),$nick,1,32)
    notice $nick You are in the $2 group
  } 
  else { msg # Group nonexistent. Use: !add alpha or !add beta }
}


Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Code:
on $*:text:/^!groups$/iS:#:msg # [Group] Alpha $numtok(%alpha,32) users [Group] Beta $numtok(%beta,32) users

on $*:text:/^!add\b/iS:#:{
  tokenize 32 $strip($1-)
  ; remove the else branch, since you can expect it not to be executed most of the time.
  var %g1, %g2
  if ($2 == alpha || $2 == beta) {
    goto $2
  }

  msg # Group nonexistent. Use: !add alpha or !add beta
  return

  :alpha
  set %alpha $addtok(%alpha,$nick,32)
  set %beta $remtok(%beta,$nick,1,32)
  goto end

  :beta
  set %alpha $remtok(%alpha,$nick,1,32)
  set %beta $remtok(%beta,$nick,32)
  goto end

  :end
  notice $nick You are in the $2 group
}


wink

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
Code:
on $*:text:/^!add\b/iS:#:{
  var %g $strip($2)
  $iif(!$3 && (%g == alpha || %g == beta),goto %g)

  msg # Group nonexistent. Use: !add alpha or !add beta
  halt

  :alpha
  %alpha = $addtok(%alpha,$nick,32)
  %beta = $remtok(%beta,$nick,1,32)
  goto end

  :beta
  %beta = $addtok(%beta,$nick,32)
  %alpha = $remtok(%alpha,$nick,1,32)

  :end
  notice $nick You are in the %g group
}

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
<nick_one> !Add alpha
-Your_Bot- You are in the Alpha group
<any_nick> !group
<Your_Bot> [Group] Alpha 1 users [Group] Beta 0 users
<nick_one> !Add beta
-Your_Bot- You are in the Beta group
<any_nick> !groups
<Your_Bot> [Group] Alpha 0 users [Group] Beta 1 users

Code:
on $*:text:/^!add (alpha|beta)$/iS:#:{
  var %g $regml(1)
  notice $nick You are in the %g group
  set $+(%,%g) $addtok($($+(%,%g),2),$nick,32)
  %g = $iif(%g = alpha,beta,alpha)
  set $+(%,%g) $remtok($($+(%,%g),2),$nick,1,32)
}
on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!group(s)?$/iS:#:msg # [Group] Alpha $numtok(%alpha,32) users [Group] Beta $numtok(%beta,32) users

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
gooshie, why another two text events when you can do:
Code:
on *:text:*:#:{
  if ($strip($1) == !add) && (!$istok(alpha beta,$strip($2),32)) { 
    msg # Invalid Parameters. Use: !add alpha or !add beta 
  }
  if ($regex($1-,/^!(add) (alpha|beta)$/iS)) {
    var %g $regml(2)
    notice $nick You are in the %g group
    set $+(%,%g) $addtok($($+(%,%g),2),$nick,32)
    %g = $iif(%g = alpha,beta,alpha)
    set $+(%,%g) $remtok($($+(%,%g),2),$nick,1,32)
  }
  if ($regex($1-,/^!group(s)?$/iS)) { 
    msg # [Group] Alpha $numtok(%alpha,32) users [Group] Beta $numtok(%beta,32) users
  }
}

Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Didn't you listen to my lecture on excess tabbing? Your solution goes about doing the same comparison twice in an incredibly inefficient manner. Please don't insult gooshie like that.

Here's my suggestion for improvement:
Code:
alias alpha {
  set %alpha $addtok(%alpha,$nick,32)
  set %beta $remtok(%beta,$nick,1,32)
}

alias beta {
  set %alpha $remtok(%alpha,$nick,1,32)
  set %beta $addtok(%beta,$nick,32)
}

on $*:text:/^!add (alpha|beta)$/iS:#:{
  var %g $regml(1)
  notice $nick You are in the %g group
  %g
}

on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!group(s)?$/iS:#:msg # [Group] Alpha $numtok(%alpha,32) users [Group] Beta $numtok(%beta,32) users

Last edited by s00p; 16/11/09 01:30 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: s00p
Please don't insult gooshie like that.
Excuse me, s00p. Please don't be melodramatic. Insult is too strong of a word for me to begin with. I was just offering my take on it. You sound, to me, as if one should feel insulted to post against another person's suggestion. For God's sake, this is a learning forum where people are free to give it a shot with their ideas.

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
Tomao asked, "why another two text events..."
Answer: Because compared to your example it is six lines shorter,
over a hundred bytes smaller and only triggers on what it should.

would this be better?

Code:
on $*:text:/^!(add\b|groups?\b) ?(alpha\b|beta\b)?/giS:#:{
  var %c $regml(1),%g $regml(2)
  if !$3 && %g && %c = add {
    notice $nick You are in the %g group
    set $+(%,%g) $addtok($($+(%,%g),2),$nick,7)
    %g = $iif(%g = alpha,beta,alpha)
    set $+(%,%g) $remtok($($+(%,%g),2),$nick,1,7)
  }
  elseif %c = add { msg # Invalid Parameters. Use: !add alpha or !add beta }
  elseif !$2 { msg # [Group] Alpha $numtok(%alpha,7) users [Group] Beta $numtok(%beta,7) users }
}

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
s00p

Code:
on $*:text:/^!add (alpha|beta)$/iS:#:notice $nick You are in the $regml(1) group | $regml(1)
on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!groups?$/iS:#:msg # [Group] Alpha $numtok(%alpha,7) users [Group] Beta $numtok(%beta,7) users
alias alpha %alpha = $addtok(%alpha,$nick,7) | %beta = $remtok(%beta,$nick,1,7)
alias beta %alpha = $remtok(%alpha,$nick,1,7) | %beta = $addtok(%beta,$nick,7)

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
Two more methods using hash tables:

Code:
on $*:text:/^!(add\b|groups?\b) ?(alpha\b|beta\b)?/giS:#:{
  var %g $regml(2)
  if !$3 && $regml(1) = add && %g {
    hadd -m %g $nick
    notice $nick You are in the %g group
    %g = $iif(%g = alpha,beta,alpha)
    $iif($hget(%g),hdel %g $nick)
  }
  elseif ($regml(1) = add) msg # Invalid Parameters. Use: !add alpha or !add beta
  elseif (!$2) msg # [Group] Alpha $hget(alpha,0).item users [Group] Beta $hget(beta,0).item users
}


Smaller and more precise:

Code:
on $*:text:/^!add (alpha|beta)$/iS:#:{
  var %g $regml(1)
  hadd -m %g $site
  notice $nick You are in the %g group
  %g = $iif(%g = alpha,beta,alpha)
  $iif($hget(%g),hdel %g $site)
}
on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!groups?$/iS:#:msg # [Group] Alpha $hget(alpha,0).item users [Group] Beta $hget(beta,0).item users

Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
Originally Posted By: gooshie
s00p

Code:
on $*:text:/^!add (alpha|beta)$/iS:#:notice $nick You are in the $regml(1) group | $regml(1)
on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!groups?$/iS:#:msg # [Group] Alpha $numtok(%alpha,7) users [Group] Beta $numtok(%beta,7) users
alias alpha %alpha = $addtok(%alpha,$nick,7) | %beta = $remtok(%beta,$nick,1,7)
alias beta %alpha = $remtok(%alpha,$nick,1,7) | %beta = $addtok(%beta,$nick,7)


'smaller' isn't always 'more optimal'.

Joined: Nov 2009
Posts: 117
Vogon poet
Offline
Vogon poet
Joined: Nov 2009
Posts: 117
would this be better?

Code:
on $*:text:/^!add (alpha|beta)$/iS:#:{
  if $regml(1) = beta { %alpha = $remtok(%alpha,$nick,1,7) | %beta = $addtok(%beta,$nick,7) }
  else { %alpha = $addtok(%alpha,$nick,7) | %beta = $remtok(%beta,$nick,1,7) }
  notice $nick You are in the $regml(1) group
}
on $*:text:/^!add\b/iS:#:msg # Invalid Parameters. Use: !add alpha or !add beta
on $*:text:/^!groups?$/iS:#:msg # [Group] Alpha $numtok(%alpha,7) users [Group] Beta $numtok(%beta,7) users


Link Copied to Clipboard