-
Notifications
You must be signed in to change notification settings - Fork 31
Customizing Standard Modules
Teeko7 edited this page Feb 10, 2025
·
1 revision
from core.command_service import CommandService
from core.decorators import instance
@instance(name="command_service", override=True)
class CustomCommandService(CommandService):
def inject(self, registry):
super().inject(registry)
self.member_controller = registry.get_instance("member_controller")
def access_denied_response(self, message, sender, cmd_config, reply):
if not self.member_controller.get_member(sender.char_id):
reply("You must !register before you can use this bot.")
else:
super().access_denied_response(message, sender, cmd_config, reply)
If the char is not a member, we return a message telling them how to become a member of this bot. Otherwise, the default message is displayed.
from core.command_service import CommandService
from core.decorators import instance
from core.private_channel_service import PrivateChannelService
@instance(name="command_service", override=True)
class CustomCommandService(CommandService):
def process_command(self, message: str, channel: str, char_id, reply, conn):
if channel == PrivateChannelService.PRIVATE_CHANNEL_COMMAND:
return
else:
super().process_command(message, channel, char_id, reply, conn)
If the channel is the private channel, we simply return. Otherwise, we call the parent's version of process_command() and proceed as normal.
Here we override the existing command_service
with a custom version. override=True
is tells the bot that this is intentional, to prevent accidental name clashes. We extend the existing CommandService since we only want to change the process_command()
method, rather then implement a entirely new class.