from twisted.plugin import IPlugin
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements

class InvisibleMode(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)
    
    name = "InvisibleMode"
    core = True
    affectedActions = [ "showchanneluser" ]
    
    def actions(self):
        return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisible) ]
    
    def userModes(self):
        return [ ("i", ModeType.NoParam, self) ]
    
    def isInvisible(self, user, channel, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def apply(self, actionName, user, param, channel, fromUser, sameUser):
        if user != sameUser:
            return None
        if not channel or fromUser not in channel.users:
            return False
        return None

invisibleMode = InvisibleMode()
from twisted.plugin import IPlugin
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements

class InvisibleMode(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)
    
    name = "InvisibleMode"
    core = True
    affectedActions = [ "showchanneluser", "showuser" ]
    
    def actions(self):
        return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisibleChan),
                ("modeactioncheck-user-i-showuser", 1, self.isInvisibleUser) ]
    
    def userModes(self):
        return [ ("i", ModeType.NoParam, self) ]
    
    def isInvisibleChan(self, user, channel, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def isInvisibleUser(self, user, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def apply(self, actionName, user, param, *params):
        if actionName == "showchanneluser":
            return self.applyChannels(user, *params)
        return self.applyUsers(user, *params)
    
    def applyChannels(self, user, channel, fromUser, sameUser):
        if user != sameUser:
            return None
        if not channel or fromUser not in channel.users:
            return False
        return None
    
    def applyUsers(self, user, fromUser, sameUser):
        if user != sameUser:
            return None
        for channel in fromUser.channels:
            if user in channel.users:
                return None
        return False

invisibleMode = InvisibleMode()
Make the invisible check action not necessarily require an accompanying channel
Make the invisible check action not necessarily require an accompanying channel

  from twisted.plugin import IPlugin
  from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
  from txircd.utils import ModeType
  from zope.interface import implements
  
  class InvisibleMode(ModuleData, Mode):
      implements(IPlugin, IModuleData, IMode)
      
      name = "InvisibleMode"
      core = True
-     affectedActions = [ "showchanneluser" ]
+     affectedActions = [ "showchanneluser", "showuser" ]
      
      def actions(self):
-         return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisible) ]
+         return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisibleChan),
+                 ("modeactioncheck-user-i-showuser", 1, self.isInvisibleUser) ]
      
      def userModes(self):
          return [ ("i", ModeType.NoParam, self) ]
      
-     def isInvisible(self, user, channel, fromUser, userSeeing):
+     def isInvisibleChan(self, user, channel, fromUser, userSeeing):
          if "i" in user.modes:
              return True
          return None
      
+     def isInvisibleUser(self, user, fromUser, userSeeing):
+         if "i" in user.modes:
+             return True
+         return None
+     
-     def apply(self, actionName, user, param, channel, fromUser, sameUser):
+     def apply(self, actionName, user, param, *params):
+         if actionName == "showchanneluser":
+             return self.applyChannels(user, *params)
+         return self.applyUsers(user, *params)
+     
+     def applyChannels(self, user, channel, fromUser, sameUser):
          if user != sameUser:
              return None
          if not channel or fromUser not in channel.users:
              return False
          return None
+     
+     def applyUsers(self, user, fromUser, sameUser):
+         if user != sameUser:
+             return None
+         for channel in fromUser.channels:
+             if user in channel.users:
+                 return None
+         return False
  
  invisibleMode = InvisibleMode()
Make the invisible check action not necessarily require an accompanying channel
## Code Before:
from twisted.plugin import IPlugin
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements

class InvisibleMode(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)
    
    name = "InvisibleMode"
    core = True
    affectedActions = [ "showchanneluser" ]
    
    def actions(self):
        return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisible) ]
    
    def userModes(self):
        return [ ("i", ModeType.NoParam, self) ]
    
    def isInvisible(self, user, channel, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def apply(self, actionName, user, param, channel, fromUser, sameUser):
        if user != sameUser:
            return None
        if not channel or fromUser not in channel.users:
            return False
        return None

invisibleMode = InvisibleMode()
## Instruction:
Make the invisible check action not necessarily require an accompanying channel
## Code After:
from twisted.plugin import IPlugin
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements

class InvisibleMode(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)
    
    name = "InvisibleMode"
    core = True
    affectedActions = [ "showchanneluser", "showuser" ]
    
    def actions(self):
        return [ ("modeactioncheck-user-i-showchanneluser", 1, self.isInvisibleChan),
                ("modeactioncheck-user-i-showuser", 1, self.isInvisibleUser) ]
    
    def userModes(self):
        return [ ("i", ModeType.NoParam, self) ]
    
    def isInvisibleChan(self, user, channel, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def isInvisibleUser(self, user, fromUser, userSeeing):
        if "i" in user.modes:
            return True
        return None
    
    def apply(self, actionName, user, param, *params):
        if actionName == "showchanneluser":
            return self.applyChannels(user, *params)
        return self.applyUsers(user, *params)
    
    def applyChannels(self, user, channel, fromUser, sameUser):
        if user != sameUser:
            return None
        if not channel or fromUser not in channel.users:
            return False
        return None
    
    def applyUsers(self, user, fromUser, sameUser):
        if user != sameUser:
            return None
        for channel in fromUser.channels:
            if user in channel.users:
                return None
        return False

invisibleMode = InvisibleMode()