from core.command_param_types import Any
from core.decorators import instance, command
from core.igncore import IgnCore
from core.text import Text


@instance()
class ChatController:
    def inject(self, registry):
        self.command_alias_service = registry.get_instance("command_alias_service")
        self.bot: IgnCore = registry.get_instance("bot")
        self.text: Text = registry.get_instance("text")

    def start(self):
        self.command_alias_service.add_alias("cmd", "shout")
        self.command_alias_service.add_alias("s", "shout")

    @command(command="shout", params=[Any("message")], access_level="leader",
             description="Show a highly visible message")
    def shout_command(self, _, message):
        self.bot.send_private_channel_message(f"<br><notice> .:: Raid Command ::.</notice>\n"
                                              f"<yellow>────────────────</yellow>\n"
                                              f"<highlight>{message}</highlight>\n"
                                              f"<yellow>────────────────</yellow>")

    @command(command="lft", params=[Any("message", is_optional=True)], access_level="member",
             description="Show a highly visible message")
    def lft_command(self, _, message):
        lft = f"<a href='chatcmd:///lft <font color=#FFFF00>» {message or '<myname>'}<end>'>/lft {message or '<myname>'}</a>"
        return self.text.format_page("Use this command for going LFT", "<yellow>────────────────</yellow>\n"
                                                                       f"<highlight>{lft}</highlight>\n"
                                                                       f"<yellow>────────────────</yellow>")
