Make the at_channel_create method automatically add a new channel to the channelhandler.
This commit is contained in:
parent
ff1ee76421
commit
628dd268f9
2 changed files with 21 additions and 3 deletions
|
|
@ -188,8 +188,8 @@ class ChannelHandler(object):
|
||||||
|
|
||||||
def add(self, channel):
|
def add(self, channel):
|
||||||
"""
|
"""
|
||||||
Add an individual channel to the handler. This should be
|
Add an individual channel to the handler. This is called
|
||||||
called whenever a new channel is created.
|
whenever a new channel is created.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
channel (Channel): The channel to add.
|
channel (Channel): The channel to add.
|
||||||
|
|
@ -223,6 +223,18 @@ class ChannelHandler(object):
|
||||||
self.cached_cmdsets = {}
|
self.cached_cmdsets = {}
|
||||||
add_channel = add # legacy alias
|
add_channel = add # legacy alias
|
||||||
|
|
||||||
|
def remove(self, channel):
|
||||||
|
"""
|
||||||
|
Remove channel from channelhandler. This will also delete it.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
channel (Channel): Channel to remove/delete.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if channel.pk:
|
||||||
|
channel.delete()
|
||||||
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
Updates the handler completely, including removing old removed
|
Updates the handler completely, including removing old removed
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from evennia.comms.managers import ChannelManager
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
from evennia.utils.utils import make_iter
|
from evennia.utils.utils import make_iter
|
||||||
from future.utils import with_metaclass
|
from future.utils import with_metaclass
|
||||||
|
_CHANNEL_HANDLER = None
|
||||||
|
|
||||||
|
|
||||||
class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
|
class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
|
||||||
|
|
@ -51,7 +52,12 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
|
||||||
Called once, when the channel is first created.
|
Called once, when the channel is first created.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
# delayed import of the channelhandler
|
||||||
|
global _CHANNEL_HANDLER
|
||||||
|
if not _CHANNEL_HANDLER:
|
||||||
|
from comms.channelhandler import CHANNEL_HANDLER as _CHANNEL_HANDLER
|
||||||
|
# register ourselves with the channelhandler.
|
||||||
|
_CHANNEL_HANDLER.add(self)
|
||||||
|
|
||||||
# helper methods, for easy overloading
|
# helper methods, for easy overloading
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue