from txircd.modbase import Mode

class PrivateMode(Mode):
    def listOutput(self, command, data):
        if command != "LIST":
            return data
        cdata = data["cdata"]
        if "p" in cdata["channel"].mode and cdata["channel"].name not in data["user"].channels:
            cdata["name"] = "*"
            cdata["topic"] = ""
    # other +p stuff is in other modules

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.mode_p = None
    
    def spawn(self):
        self.mode_p = PrivateMode()
        return {
            "modes": {
                "cnp": self.mode_p
            },
            "actions": {
                "commandextra": [self.mode_p.listOutput]
            },
            "common": True
        }
    
    def cleanup(self):
        self.ircd.removeMode("cnp")
        self.ircd.actions["commandextra"].remove(self.mode_p.listOutput)
from txircd.modbase import Mode

class PrivateMode(Mode):
    def listOutput(self, command, data):
        if command != "LIST":
            return data
        if "cdata" not in data:
            return data
        cdata = data["cdata"]
        if "p" in cdata["channel"].mode and cdata["channel"].name not in data["user"].channels:
            cdata["name"] = "*"
            cdata["topic"] = ""
    # other +p stuff is in other modules

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.mode_p = None
    
    def spawn(self):
        self.mode_p = PrivateMode()
        return {
            "modes": {
                "cnp": self.mode_p
            },
            "actions": {
                "commandextra": [self.mode_p.listOutput]
            },
            "common": True
        }
    
    def cleanup(self):
        self.ircd.removeMode("cnp")
        self.ircd.actions["commandextra"].remove(self.mode_p.listOutput)
Fix LIST crashing on certain input
Fix LIST crashing on certain input

  from txircd.modbase import Mode
  
  class PrivateMode(Mode):
      def listOutput(self, command, data):
          if command != "LIST":
+             return data
+         if "cdata" not in data:
              return data
          cdata = data["cdata"]
          if "p" in cdata["channel"].mode and cdata["channel"].name not in data["user"].channels:
              cdata["name"] = "*"
              cdata["topic"] = ""
      # other +p stuff is in other modules
  
  class Spawner(object):
      def __init__(self, ircd):
          self.ircd = ircd
          self.mode_p = None
      
      def spawn(self):
          self.mode_p = PrivateMode()
          return {
              "modes": {
                  "cnp": self.mode_p
              },
              "actions": {
                  "commandextra": [self.mode_p.listOutput]
              },
              "common": True
          }
      
      def cleanup(self):
          self.ircd.removeMode("cnp")
          self.ircd.actions["commandextra"].remove(self.mode_p.listOutput)
Fix LIST crashing on certain input
## Code Before:
from txircd.modbase import Mode

class PrivateMode(Mode):
    def listOutput(self, command, data):
        if command != "LIST":
            return data
        cdata = data["cdata"]
        if "p" in cdata["channel"].mode and cdata["channel"].name not in data["user"].channels:
            cdata["name"] = "*"
            cdata["topic"] = ""
    # other +p stuff is in other modules

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.mode_p = None
    
    def spawn(self):
        self.mode_p = PrivateMode()
        return {
            "modes": {
                "cnp": self.mode_p
            },
            "actions": {
                "commandextra": [self.mode_p.listOutput]
            },
            "common": True
        }
    
    def cleanup(self):
        self.ircd.removeMode("cnp")
        self.ircd.actions["commandextra"].remove(self.mode_p.listOutput)
## Instruction:
Fix LIST crashing on certain input
## Code After:
from txircd.modbase import Mode

class PrivateMode(Mode):
    def listOutput(self, command, data):
        if command != "LIST":
            return data
        if "cdata" not in data:
            return data
        cdata = data["cdata"]
        if "p" in cdata["channel"].mode and cdata["channel"].name not in data["user"].channels:
            cdata["name"] = "*"
            cdata["topic"] = ""
    # other +p stuff is in other modules

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.mode_p = None
    
    def spawn(self):
        self.mode_p = PrivateMode()
        return {
            "modes": {
                "cnp": self.mode_p
            },
            "actions": {
                "commandextra": [self.mode_p.listOutput]
            },
            "common": True
        }
    
    def cleanup(self):
        self.ircd.removeMode("cnp")
        self.ircd.actions["commandextra"].remove(self.mode_p.listOutput)