mIRC Home    About    Download    Register    News    Help

Print Thread
PM acces script needs help #231409 17/04/11 09:40 AM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
I just don't see why this dont work:

Code:
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  .+ Create access database: hmake -s pmusers 100

  $iif($hget(pmusers) != $null, PM rights)
  .+ $iif($hget(pmusers, $nick) == $null, Give, Remove) {
    if ($hget(pmusers, $nick) == $null) {
      hadd -m pmusers $$1
      .notice $me $$1 has now PM rights.
    }

    else {
      hdel pmusers $$1
      .notice $me Removed PM rights from $$1.
    }
  }
  .-
  .+ Remove access database {
    hfree -sw pmusers
  }
} 


The code:
Code:
.+ $iif($hget(pmusers, $nick) == $null, Give, Remove) {
    if ($hget(pmusers, $nick) == $null) {


What is wrong in that? It creates database good then it shows give option and grants access right, but then it never give Remove option to user that is already in database.

I need some help with this. Whats wrong?

Re: PM acces script needs help [Re: Jeroi] #231410 17/04/11 10:22 AM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Ok found the solution instead of using $nick, I must use $$1 in nicklist popup for the iif to work properly now this works:

Code:
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database: hmake -s pmusers 100

  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $$1) != $$1, Give, Remove) {
    if ($hfind(pmusers, $$1) != $$1) {
      hadd pmusers $$1 $$1
      .notice $me $$1 got now PM rights.
    }

    else {
      hdel -w pmusers $$1
      .notice $me Removed PM rights from $$1.
    }
  }
  .-
  . Remove PM access database {
    hfree -sw pmusers
  }
} 

Re: PM acces script needs help [Re: Jeroi] #231412 17/04/11 11:17 AM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Next proplem. I am trying to add while loop so you can grant multiple acces grants in same time ie. whole channel or every friend in channel you got.

This is what it looks now:

Code:
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database {
    hmake pmusers 100
    .notice $me PM access database created.
  }
  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $$1) != $$1, Give, Remove) {
    var %counter = 0  
    while ($$1- != $null) {
      if ($hfind(pmusers, $$N) != $$N) {
        %counter = %counter + 1
        hadd pmusers $$N $$N
        if ($$N == $null && %counter == 1) {
          .notice $me $$N got now PM rights.
        }
        if ($$N == $null && %counter > 1) {
          .notice $me Selected group got now PM rights.
        }        
      }
      else {
        %counter = counter + 1
        hdel -w pmusers $N
        if ($N == $null && %counter == 1) {
          .notice $me Removed PM rights from $$1.
        }
        if ($N == $null && %counter > 1) {
          .notice $me Removed PM rights from selected group.
        }  
      }
    }
  }
  .-
  . Remove access database {
    hfree -w pmusers
    .notice $me PM access database destroyed.
  }
} 


How ever, the while loop dosent do anything so there must be somehting wrong.

Can anybody help?

Last edited by Jeroi; 17/04/11 11:18 AM.
Re: PM acces script needs help [Re: Jeroi] #231415 17/04/11 01:33 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
What is the $N? Do you mean to have $1 in all of those? And if so, your while loop already checks if $1 != $null, so your IF statements inside the loop that check that aren't needed.

Also, it is usually a better idea to leave a menu "clean" rather than having a lot of code in there. Have your menu item call and alias instead of having everything in there and it will make the menu a lot more readable.


Invision Support
#Invision on irc.irchighway.net
Re: PM acces script needs help [Re: Riamus2] #231418 17/04/11 04:15 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Originally Posted By: Riamus2
What is the $N? Do you mean to have $1 in all of those? And if so, your while loop already checks if $1 != $null, so your IF statements inside the loop that check that aren't needed.

Also, it is usually a better idea to leave a menu "clean" rather than having a lot of code in there. Have your menu item call and alias instead of having everything in there and it will make the menu a lot more readable.


Ok you have valid point but can alias use nicklist selected names as variables when alias is called from nicklist?

The problems is that I need to loop selected users form nicklist to be able to give access rights to all. How ever the while loop dont do anyhting atm because no notice message is given to me anykind

Re: PM acces script needs help [Re: Jeroi] #231419 17/04/11 05:31 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Ok I have now sorted the while loop. How ever it worked before I made some edits to if statements on adding and delling the names fron selected nicknames

Here is the code:

Code:
on ^*:OPEN:?:*: {
  if ($hget(pmusers) != $null) {
    if ($nick != $hget(pmusers, $nick)) {
      .notice $me $nick just tried to sen PM with stareting word: $1
      .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
      halt
    }
    else {
      msg $nick Hello, I got your message and will try to respond to you ASAP.
    }
  }
}
alias selected {
  var %counter = 1  
  var %count = $snick($chan,0)
  while (%counter <= %count) {
    var %nick = $snick($chan, %counter)
    if ($hfind(pmusers, $snick($chan, %counter) == $false) ) {
      hadd pmusers %nick %nick
      if (%count == 1 ) {
        .notice $me %nick got now PM rights.
      }
      elseif (%counter == %count) {
        .notice $me Selected group got now PM rights.
      }
      inc %counter        
    }
    elseif ($hfind(pmusers, $snick($chan, %counter) == $true)) {
      hdel -w pmusers %nick
      if (%count == 1 ) {
        .notice $me Removed PM rights from %nick.
      }
      elseif (%counter == %count) {
        .notice $me Removed PM rights from selected group.
      }
      else .notice $me Removed PM rights from selected group.
      inc %counter  
    }
  }
}
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database {
    hmake pmusers 100
    .notice $me PM access database created.
  }
  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $snick($chan,1)) != $snick($chan,1), Give, Remove): selected 
  .-
  . Remove access database {
    hfree -w pmusers
    .notice $me PM access database destroyed.
  }
}


Whats causeing the eternal loop here?
Does it generate eternal loop because I have another skript that uses menu nicklist also ie Q/L/chanserv/nickserv controlling skript?

Re: PM acces script needs help [Re: Jeroi] #231420 17/04/11 05:40 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Jeroi
Whats causeing the eternal loop here?
It looks like you have an extra set of /inc %counter. You may need to remove the first one and keep the one at the bottom.

Re: PM acces script needs help [Re: Jeroi] #231422 17/04/11 06:14 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Ok sorted the loop now and working fantastic. Anymore is to do some kind of OP checking system that checks if pm sender is OP in same channel than I am thus automatically grants pm access to Operators.

Code:
on ^*:OPEN:?:*: {
  if ($hget(pmusers) != $null) {
    if ($nick != $hget(pmusers, $nick)) {
      .notice $me $nick just tried to sen PM with stareting word: $1
      .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
      halt
    }
    else {
      msg $nick Hello, I got your message and will try to respond to you ASAP.
    }
  }
}
alias selected {

  var %counter = 1  
  var %count = $snick($chan,0)
  var %first = $snick($chan, 1)
  var %boolean = $hfind(pmusers, %first)

  while (%counter <= %count) { 
    var %nick = $snick($chan, %counter)

    if (%boolean != %first) {
      hadd pmusers %nick %nick
      if (%count == 1 ) {
        .notice $me %nick added to PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Selected group added to PM access database.
      }        
    }
    if (%boolean == %first ) {      
      hdel -w pmusers %nick
      if (%count == 1) {
        .notice $me Removed %nick from PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Removed selected group from PM access database.
      }
    }
    inc %counter
  }
}
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database {
    hmake pmusers 100
    .notice $me PM access database created.
  }
  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $snick($chan,1)) != $snick($chan,1), Give, Remove): selected 
  .-
  . Remove access database {
    hfree -w pmusers
    .notice $me PM access database destroyed.
  }
}

Last edited by Jeroi; 17/04/11 06:14 PM.
Re: PM acces script needs help [Re: Jeroi] #231424 17/04/11 06:40 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Jeroi
to do some kind of OP checking system that checks if pm sender is OP in same channel than I am thus automatically grants pm access to Operators.
There is no $chan in the PM, so we need to loop through the common channels to check if that person who sends you a PM is an OP or not. What I have done here is that non-ops who send you a PM will be closed:
Code:
on *:open:?:*:{
  var %pm $comchan($nick,0)
  while (%pm) {
    if ($nick !isop $comchan($nick,%pm)) { close -m $nick }
    else {
      if ($hget(pmusers) != $null) {
        if ($nick != $hget(pmusers, $nick)) {
          .notice $me $nick just tried to sen PM with stareting word: $1
          .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
          return
        }
        else { msg $nick Hello, I got your message and will try to respond to you ASAP. }
      }
    }
    dec %pm
  }
}

Last edited by Tomao; 17/04/11 06:44 PM.
Re: PM acces script needs help [Re: Tomao] #231426 17/04/11 07:33 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Originally Posted By: Tomao
Originally Posted By: Jeroi
to do some kind of OP checking system that checks if pm sender is OP in same channel than I am thus automatically grants pm access to Operators.
There is no $chan in the PM, so we need to loop through the common channels to check if that person who sends you a PM is an OP or not. What I have done here is that non-ops who send you a PM will be closed:
Code:
on *:open:?:*:{
  var %pm $comchan($nick,0)
  while (%pm) {
    if ($nick !isop $comchan($nick,%pm)) { close -m $nick }
    else {
      if ($hget(pmusers) != $null) {
        if ($nick != $hget(pmusers, $nick)) {
          .notice $me $nick just tried to sen PM with stareting word: $1
          .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
        }
        else { msg $nick Hello, I got your message and will try to respond to you ASAP. }
      }
    }
    dec %pm
  }
}


Nice, that helped alot. I added also save hash to txt file on exit and when script is loaded it opens txt file.

Anyways the PM acces rights databse script is more likely complete now.

Here is the code:
Code:
alias selected {
  var %counter = 1  
  var %count = $snick($chan,0)
  var %first = $snick($chan, 1)
  var %boolean = $hfind(pmusers, %first)

  while (%counter <= %count) { 
    var %nick = $snick($chan, %counter)

    if (%boolean != %first) {
      hadd pmusers %nick %nick
      if (%count == 1 ) {
        .notice $me %nick added to PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Selected group added to PM access database.
      }        
    }
    if (%boolean == %first ) {      
      hdel -w pmusers %nick
      if (%count == 1) {
        .notice $me Removed %nick from PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Removed selected group from PM access database.
      }
    }
    inc %counter
  }
}
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database {
    hmake pmusers 100
    .notice $me PM access database created.
  }
  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $snick($chan,1)) != $snick($chan,1), Give, Remove): selected 
  .-
  . Remove access database {
    hfree -w pmusers
    .notice $me PM access database destroyed.
  }
}
on *:LOAD: {
  hmake pmusers 100
  hload pmusers pmusers.txt
} 
on *:EXIT: {
  hsave pmusers pmusers.txt
}
on ^*:open:?:*:{
  var %pm $comchan($nick,0)
  while (%pm) {
    if ($nick !isop $comchan($nick,%pm)) { close -m $nick }
    else {
      if ($hget(pmusers) != $null) {
        if ($nick != $hget(pmusers, $nick)) {
          .notice $me $nick just tried to send PM with starting word: $1
          .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
          return
        }
        else { msg $nick Hello, I got your message and will try to respond to you ASAP. }
      }
    }
    dec %pm
  }
}


What do you guys think?

I belive it needs tho send pm script if I am sending to someone pm the skript gives acces rights to that person automatically.


Tomao found bug in your script:
Originally Posted By: Tomao
Code:
on *:open:?:*:{
  var %pm $comchan($nick,0)
  while (%pm) {
    if ($nick !isop $comchan($nick,%pm)) { close -m $nick }
    else {
      if ($hget(pmusers) != $null) {
        if ($nick != $hget(pmusers, $nick)) {
          .notice $me $nick just tried to sen PM with stareting word: $1
          .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
          return
        }
        else { msg $nick Hello, I got your message and will try to respond to you ASAP. }
      }
    }
    dec %pm
  }
}


It prevented weradly some users and some users it allowed and I fixed your code to work properly. It now checks if user isop on same channel than you and addas boolean variable to 1. Then the acces list cheker checks also if boolean == 0 it blocks PM else gives welcome text.

Code:
on ^*:OPEN:?:*:{
  if ($hget(pmusers) != $null) {
    var %pm $comchan($nick,0)
    var %boolean 0
    while (%pm) {
      if ($nick isop $comchan($nick,%pm)) { 
        inc %boolean
        return
      }
      dec %pm
    }
    if ($nick != $hget(pmusers, $nick) && %boolean == 0) {
      .notice $me $nick just tried to sen PM with starting word: $1
      .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
      halt
    }
    else { 
      msg $nick Hello, I got your message and will try to respond to you ASAP. 
    }
  }
}



The main problem was also that you were looping all the time incoming messages. If user deletes database then the script is always looping when incoming messages are coming even tho there is no database from what to check. Now I added the while loop and variables inside databse check and made the while loop only increasy boolean if user is found as op in same channel. Also you changed halt to return which do not work in this case because halt prevents pm window to open and your skript opened window anyway.

Last edited by Jeroi; 17/04/11 09:56 PM.
Re: PM acces script needs help [Re: Jeroi] #231429 17/04/11 09:50 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yeah thanks. I completely overlooked the matter. I was throwing my example together to make do.

Re: PM acces script needs help [Re: Jeroi] #231430 17/04/11 10:11 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Here is current scritp in whole deal:

Code:
alias selected {
  var %counter = 1  
  var %count = $snick($chan,0)
  var %first = $snick($chan, 1)
  var %boolean = $hfind(pmusers, %first)

  while (%counter <= %count) { 
    var %nick = $snick($chan, %counter)

    if (%boolean != %first) {
      hadd pmusers %nick %nick
      if (%count == 1 ) {
        .notice $me %nick added to PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Selected group added to PM access database.
      }        
    }
    if (%boolean == %first ) {      
      hdel -w pmusers %nick
      if (%count == 1) {
        .notice $me Removed %nick from PM access database.
      }
      if (%counter == %count && %count > 1) {
        .notice $me Removed selected group from PM access database.
      }
    }
    inc %counter
  }
}
menu nicklist {
  $iif($hget(pmusers) == $null, PM rights)
  . Create access rights database {
    hmake pmusers 100
    .notice $me PM access database created.
  }
  $iif($hget(pmusers) != $null, PM rights)
  . $iif($hfind(pmusers, $snick($chan,1)) != $snick($chan,1), Give, Remove): selected 
  .-
  . Remove access database {
    hfree -w pmusers
    .notice $me PM access database destroyed.
  }
}
on *:LOAD: {
  hmake pmusers 100
  hload pmusers pmusers.txt
} 
on *:EXIT: {
  hsave pmusers pmusers.txt
}
on ^*:OPEN:?:*:{
  if ($hget(pmusers) != $null) {
    var %pm $comchan($nick,0)
    var %boolean 0

    while (%pm) {
      if ($nick isop $comchan($nick,%pm)) { 
        inc %boolean
        return
      }
      dec %pm
    }
    if ($nick != $hget(pmusers, $nick) && %boolean == 0) {
      .notice $me $nick just tried to sen PM with starting word: $1
      .notice $nick Sorry, unknown PM messages are not allowed and not received. Please ask privlidges in main chat.
      halt
    }
    else { 
      msg $nick Hello, I got your message and will try to respond to you ASAP. 
    }
  }
}
on 1:INPUT:?: {
  if ($active != $hget(pmusers, $active)) {
    hadd pmusers $active $active
  }
}


If you have suggestions or find bugs please gimme trout.

Re: PM acces script needs help [Re: Jeroi] #231434 18/04/11 01:25 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Suggestions:
Change ON LOAD to ON START
Check that pmusers.txt exists before you load it.
The -w switch in both the /hdel and /hfree commands is unnecessary, as you aren't specifying a wildcard in the line.

Re: PM acces script needs help [Re: RusselB] #231447 18/04/11 10:55 AM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
-w is necessary on del because it uses item name as wildcard and deletes all similar names. It's there just because if database happens to have two timessame item name tho add overwrites same name so you may be right.

Re: PM acces script needs help [Re: Jeroi] #231448 18/04/11 12:31 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
You can't have more than one item with the same name in a hash table. The -w would be needed if you wanted to delete something with a wildcard in it. For example deleting nick* so that alternate nicks like nick|away are also removed. But to do that, you'd need to include the * wildcard with your /hdel. In general, you don't really want to do that with nicks, though. There is too much chance of removing additional nicks that are not alternates.

Last edited by Riamus2; 18/04/11 12:34 PM.

Invision Support
#Invision on irc.irchighway.net
Re: PM acces script needs help [Re: Riamus2] #231468 18/04/11 05:32 PM
Joined: Jun 2004
Posts: 31
J
Jeroi Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jun 2004
Posts: 31
Does !== be case senisitve for length?

I have discovered that if I compare with != nick from table and like this:

if Jeroi == Jeroi_away returns TRUE

Does Jeroi === Jeroi_away return FALSE?

Or doa I need to check with $len($nick) == $len(tablenick)

Last edited by Jeroi; 18/04/11 05:33 PM.
Re: PM acces script needs help [Re: Jeroi] #231472 18/04/11 06:13 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I think you're mistaken. smile

From the edit line:

//if (Jeroi == Jeroi_away) { echo -a true } | else { echo -a false }

You'll see that it is false and not true. What is your exact IF statement where you think that returns true?

=== is case sensitive. That means only that Jeroi is not the same as jeroi. It has nothing to do with additional characters, such as _away being on the nick.

Hash table items are case-insensitive for item names. That means that you cannot have both Jeroi and jeroi. You can have only one item with the same letters no matter what the case is. * The exception being that UTF-8 probably treats upper and lower case characters as different characters, but for normal A-Z and a-z, they are treated the same in the item name.

Your wildcard match currently doesn't match nick_away. It only matches nick. Unless you specifically add the person's nick_away nick, of course. If you want it to match the nick_away nick without specifically adding it, then you'd use the wildcard match for nick*. You need that * for it to do that kind of match. As mentioned, though... if you do that, you risk matching incorrectly. For example, someone might have have the nick Ram and another have the nick Ramses. Ram* would match both. You will need to decide what will be the best option for you.


Invision Support
#Invision on irc.irchighway.net