Module - return bool for Nick perms in Chan?

Help
stebi3
2009-04-23
2013-06-05
  • stebi3
    stebi3
    2009-04-23

    With creating modules, is there an easy way to determine whether a user has Op/HalfOp/Voice status in a channel?

    Thanks.

     
    • Psychon
      Psychon
      2009-04-23

      Example from autoop.cpp line 160:

      virtual void OnJoin(const CNick& Nick, CChan& Channel) {
      // If we have ops in this chan
      if (Channel.HasPerm(CChan::Op)) {
      [...]

      If you mean user in the "some random guy in #channel"-sense instead of the "some znc user"-sense:

      // Check if "peter" has op in CChannl& chan
      CNick *pPeter = chan.FindNick("peter");
      if (!pPeter) {
      // "peter" is not in that channel
      } else if (!pPeter->HasPerm('o') {
      // "peter" doesn't have op
      } else {
      // "peter got op"
      }

      (This is untested and I just came up with it, but it should (hopefully) work)

      You can't use CNick::HasPerm() on a CNick passed in via a module call since that instance is only initialized with the hostmask, not the nick's permissions.

      Cheers,
      psychon

       
    • Psychon
      Psychon
      2009-04-23

      I just noticed that it might be HasPerm('@') instead of HasPerm('o')....

       
      • stebi3
        stebi3
        2009-04-23

        Thanks for that - works perfect! I'm using both snipplets in a module to cancel out if either myself is not (half-)opped or the user is (half-)opped (in OnChanMsg):

        if (!Channel.HasPerm('o') && !Channel.HasPerm('h') && !Channel.HasPerm('@') && !Channel.HasPerm('%'))
           return CONTINUE;
        CNick* chkNick = Channel.FindNick(Nick.GetNick());
        if (chkNick->HasPerm('o') || chkNick->HasPerm('h') || chkNick->HasPerm('@') || chkNick->HasPerm('%'))
           return CONTINUE;

        I initially didn't read your last reply, thus experienced problems when using HasPerm('o'). But all now is well!

        Thanks again.