From 2f655abf1a09135b3c87d7fd397f78026d38bb4d Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 21 May 2016 22:16:52 +0200 Subject: [PATCH] Added the possibility to overload the dynamically created ChannelCommand. Implements #887. --- evennia/comms/channelhandler.py | 12 ++++++++++-- evennia/settings_default.py | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/evennia/comms/channelhandler.py b/evennia/comms/channelhandler.py index 322f22740a..330c468170 100644 --- a/evennia/comms/channelhandler.py +++ b/evennia/comms/channelhandler.py @@ -25,12 +25,15 @@ does this for you. """ from builtins import object +from django.conf import settings from evennia.comms.models import ChannelDB from evennia.commands import cmdset, command from evennia.utils.logger import tail_log_file - +from evennia.utils.utils import class_from_module from django.utils.translation import ugettext as _ +_CHANNEL_COMMAND_CLASS = None + class ChannelCommand(command.Command): """ {channelkey} channel @@ -194,8 +197,13 @@ class ChannelHandler(object): the Channel itself. """ + global _CHANNEL_COMMAND_CLASS + if not _CHANNEL_COMMAND_CLASS: + _CHANNEL_COMMAND_CLASS = class_from_module(settings.CHANNEL_COMMAND_CLASS) + # map the channel to a searchable command - cmd = ChannelCommand(key=channel.key.strip().lower(), + cmd = _CHANNEL_COMMAND_CLASS( + key=channel.key.strip().lower(), aliases=channel.aliases.all(), locks="cmd:all();%s" % channel.locks, help_category="Channel names", diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 33e6d17685..384c0fe708 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -324,6 +324,11 @@ CMDSET_PATHS = ["commands", "evennia", "contribs"] # Parent class for all default commands. Changing this class will # modify all default commands, so do so carefully. COMMAND_DEFAULT_CLASS = "evennia.commands.default.muxcommand.MuxCommand" +# The Channel Handler will create a command to represent each channel, +# creating it with the key of the channel, its aliases, locks etc. The +# default class logs channel messages to a file and allows for /history. +# This setting allows to override the command class used with your own. +CHANNEL_COMMAND_CLASS = "evennia.comms.channelhandler.ChannelCommand" ###################################################################### # Typeclasses and other paths