# 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
# class command(object):
# 
#     """
#     Decorator for command handlers in bot Plugins.
#     """
# 
#     def __init__(self, name=None, pattern=None, help=None):
#         assert not callable(name), 'You forgot the parentheses for the decorator'
# 
#         self.name = name
#         if isinstance(pattern, str):
#             pattern = re.compile(pattern)
#         self.regex = pattern
#         self.help = help
# 
#     def __call__(self, func):
#         """
#         Decorator
#         """
#         if self.name is None:
#             self.name = func.__name__.replace('_', ' ')
#         if self.help is None:
#             self.help = func.__doc__.strip().split('\n')[0] if func.__doc__ else None
#         func._command = self
#         return func
# 
#     def as_help(self):
#         cmd = "`{prefix}{name}{pattern}`".format(
#             prefix=PREFIX,
#             name=self.name,
#             pattern=' {}'.format(self.regex.pattern) if self.regex else ''
#         )
#         return "{cmd}{spacer}{help}".format(cmd=cmd, help=self.help or '', spacer=' - ' if self.help else '')
# 
# Path: bot/plugins/status/models.py
# class GameStatus(models.Model):
# 
#     status = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.status


import logging
import re
from discord import CustomActivity
from bot.plugins.base import BasePlugin
from bot.plugins.commands import command
from .models import GameStatus
        """
        Randomly picks a new status
        """
        status = command.args.status
        if not status:
            status = GameStatus.objects.order_by('?').values_list('status', flat=True).first()
            if status is None:
                await command.reply('I have no known statuses...')
                return
        await self.client.change_presence(activity=CustomActivity(name=status))

    @command()
    async def clear_status(self, command):
        await self.client.change_presence(activity=None)

    @command()
    async def list_status(self, command):
        """
        Lists all available statuses
        """
        statuses = GameStatus.objects.values('id', 'status').order_by('id')
        msg = '\n'.join(['{id} - {status}'.format(**status) for status in statuses])
        await command.reply(msg)

    @command(pattern=re.compile(r'(?P<id>\d+)'))
    async def delete_status(self, command):
        """
        Deletes the specified status (supply the ID from !list status)
        """
        id_ = command.args.id

# 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
# class command(object):
# 
#     """
#     Decorator for command handlers in bot Plugins.
#     """
# 
#     def __init__(self, name=None, pattern=None, help=None):
#         assert not callable(name), 'You forgot the parentheses for the decorator'
# 
#         self.name = name
#         if isinstance(pattern, str):
#             pattern = re.compile(pattern)
#         self.regex = pattern
#         self.help = help
# 
#     def __call__(self, func):
#         """
#         Decorator
#         """
#         if self.name is None:
#             self.name = func.__name__.replace('_', ' ')
#         if self.help is None:
#             self.help = func.__doc__.strip().split('\n')[0] if func.__doc__ else None
#         func._command = self
#         return func
# 
#     def as_help(self):
#         cmd = "`{prefix}{name}{pattern}`".format(
#             prefix=PREFIX,
#             name=self.name,
#             pattern=' {}'.format(self.regex.pattern) if self.regex else ''
#         )
#         return "{cmd}{spacer}{help}".format(cmd=cmd, help=self.help or '', spacer=' - ' if self.help else '')
# 
# Path: bot/plugins/status/models.py
# class GameStatus(models.Model):
# 
#     status = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.status


# Path: bot/plugins/status/plugin.py
import logging
import re
from discord import CustomActivity
from bot.plugins.base import BasePlugin
from bot.plugins.commands import command
from .models import GameStatus

        """
        Randomly picks a new status
        """
        status = command.args.status
        if not status:
            status = GameStatus.objects.order_by('?').values_list('status', flat=True).first()
            if status is None:
                await command.reply('I have no known statuses...')
                return
        await self.client.change_presence(activity=CustomActivity(name=status))

    @command()
    async def clear_status(self, command):
        await self.client.change_presence(activity=None)

    @command()
    async def list_status(self, command):
        """
        Lists all available statuses
        """
        statuses = GameStatus.objects.values('id', 'status').order_by('id')
        msg = '\n'.join(['{id} - {status}'.format(**status) for status in statuses])
        await command.reply(msg)

    @command(pattern=re.compile(r'(?P<id>\d+)'))
    async def delete_status(self, command):
        """
        Deletes the specified status (supply the ID from !list status)
        """
        id_ = command.args.id

        deleted, _ = GameStatus.objects.filter(id=id_).delete()