# Path: bot/plugins/base.py
# class BasePlugin(metaclass=BasePluginMeta):
# 
#     has_blocking_io = False  # set to True to run events in an executor
#     commands = None
#     _callbacks = None
# 
#     def __init__(self, client, options):
#         self.client = client
#         self.options = options
# 
#     def _wrap(self, method):
#         handler = functools.partial(method, self)
#         handler.__name__ = method.__name__
#         handler._has_blocking_io = self.has_blocking_io
#         return handler
# 
#     def get_command(self, msg):
#         """
#         Get the command that matches with str:`msg`
#         """
#         for cmd, handler in self.commands.items():
#             if msg.lower().startswith(cmd.lower()):
# 
#                 # Simple command
#                 if handler._command.regex is None:
#                     # in this case, it must be the exact same command
#                     if msg.lower() != cmd.lower():
#                         continue
#                     command = commands.Command(handler._command)
#                     return handler, command
# 
#                 # Regex matching, cut of the command part
#                 str_to_test = msg[len(cmd):].strip()
#                 match = handler._command.regex.match(str_to_test)
#                 if not match:
#                     continue
# 
#                 command = commands.Command(handler._command, **match.groupdict())
#                 return handler, command
#         return None
# 
#     async def on_message(self, message):
#         result = self.get_command(message.content)
#         if result:
#             handler, command = result
#             command.for_message, command.client = message, self.client
#             stop = await command_resolved.dispatch(command=command, handler=handler)
#             if not stop:
#                 assert asyncio.iscoroutinefunction(handler)
#                 await handler(self, command)
# 
#     async def on_message_edit(self, before, after):
#         pass
# 
# Path: bot/plugins/commands.py
# PREFIX = os.getenv('PREFIX', '!')
# 
# class Command(object):
# 
#     for_message = None
#     client = None
# 
#     def __init__(self, command, for_message=None, **kwargs):
#         self.command = command
#         self.args = Args(**kwargs)
#         self.for_message = for_message
# 
#     @property
#     def message(self):
#         return self.for_message
# 
#     async def trigger_typing(self, dest=None):
#         dest = dest or self.for_message.channel
#         await dest.trigger_typing()
# 
#     async def reply(self, text):
#         channel = self.for_message.channel
#         await channel.send(text)
# 
# Path: bot/plugins/custom_commands/models.py
# class CommandAction(models.Model):
#     command = models.ForeignKey(Command, on_delete=models.CASCADE)
#     action = models.TextField(_('action'), help_text=_('Text to be replied'))
# 
#     class Meta:
#         verbose_name = _('command action')
#         verbose_name_plural = _('command actions')
# 
#     def __str__(self):
#         return self.action[:30]


import logging
from discord.enums import Status
from discord import Game
from django.conf import settings
from bot.plugins.base import BasePlugin
from bot.plugins.commands import PREFIX, Command
from .models import CommandAction




logger = logging.getLogger(__name__)


class Plugin(BasePlugin):

    has_blocking_io = True

    def _member_active(self, member):
        statuses = [Status.online, Status.idle]
        gaming = settings.DEBUG is False and any(
            (isinstance(activity, Game) for activity in member.activities)
        )
        return member.status in statuses and not member.is_afk and not gaming

    async def on_message(self, message):
        await super().on_message(message)

        if not message.content.startswith(PREFIX):
            return

        command = Command(None, for_message=message)
        command.client = self.client


# Path: bot/plugins/base.py
# class BasePlugin(metaclass=BasePluginMeta):
# 
#     has_blocking_io = False  # set to True to run events in an executor
#     commands = None
#     _callbacks = None
# 
#     def __init__(self, client, options):
#         self.client = client
#         self.options = options
# 
#     def _wrap(self, method):
#         handler = functools.partial(method, self)
#         handler.__name__ = method.__name__
#         handler._has_blocking_io = self.has_blocking_io
#         return handler
# 
#     def get_command(self, msg):
#         """
#         Get the command that matches with str:`msg`
#         """
#         for cmd, handler in self.commands.items():
#             if msg.lower().startswith(cmd.lower()):
# 
#                 # Simple command
#                 if handler._command.regex is None:
#                     # in this case, it must be the exact same command
#                     if msg.lower() != cmd.lower():
#                         continue
#                     command = commands.Command(handler._command)
#                     return handler, command
# 
#                 # Regex matching, cut of the command part
#                 str_to_test = msg[len(cmd):].strip()
#                 match = handler._command.regex.match(str_to_test)
#                 if not match:
#                     continue
# 
#                 command = commands.Command(handler._command, **match.groupdict())
#                 return handler, command
#         return None
# 
#     async def on_message(self, message):
#         result = self.get_command(message.content)
#         if result:
#             handler, command = result
#             command.for_message, command.client = message, self.client
#             stop = await command_resolved.dispatch(command=command, handler=handler)
#             if not stop:
#                 assert asyncio.iscoroutinefunction(handler)
#                 await handler(self, command)
# 
#     async def on_message_edit(self, before, after):
#         pass
# 
# Path: bot/plugins/commands.py
# PREFIX = os.getenv('PREFIX', '!')
# 
# class Command(object):
# 
#     for_message = None
#     client = None
# 
#     def __init__(self, command, for_message=None, **kwargs):
#         self.command = command
#         self.args = Args(**kwargs)
#         self.for_message = for_message
# 
#     @property
#     def message(self):
#         return self.for_message
# 
#     async def trigger_typing(self, dest=None):
#         dest = dest or self.for_message.channel
#         await dest.trigger_typing()
# 
#     async def reply(self, text):
#         channel = self.for_message.channel
#         await channel.send(text)
# 
# Path: bot/plugins/custom_commands/models.py
# class CommandAction(models.Model):
#     command = models.ForeignKey(Command, on_delete=models.CASCADE)
#     action = models.TextField(_('action'), help_text=_('Text to be replied'))
# 
#     class Meta:
#         verbose_name = _('command action')
#         verbose_name_plural = _('command actions')
# 
#     def __str__(self):
#         return self.action[:30]


# Path: bot/plugins/custom_commands/plugin.py
import logging
from discord.enums import Status
from discord import Game
from django.conf import settings
from bot.plugins.base import BasePlugin
from bot.plugins.commands import PREFIX, Command
from .models import CommandAction





logger = logging.getLogger(__name__)


class Plugin(BasePlugin):

    has_blocking_io = True

    def _member_active(self, member):
        statuses = [Status.online, Status.idle]
        gaming = settings.DEBUG is False and any(
            (isinstance(activity, Game) for activity in member.activities)
        )
        return member.status in statuses and not member.is_afk and not gaming

    async def on_message(self, message):
        await super().on_message(message)

        if not message.content.startswith(PREFIX):
            return

        command = Command(None, for_message=message)
        command.client = self.client


        cmd = message.content[len(PREFIX):]