# 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/users/decorators.py
# def bot_admin_required(func):
#     """
#     This decorator peforms database lookups, so if you use it,
#     the plugin must be marked as ``has_blocking_io = True``.
#     """
# 
#     @wraps(func)
#     async def decorator(plugin, command, *args, **kwargs):
#         if not is_bot_admin(command.message):
#             await command.reply('You don\'t have permission for this command')
#             return
#         await func(plugin, command, *args, **kwargs)
#     return decorator


import datetime
import logging
import os
import platform
import re
import psutil
from io import StringIO
from django.conf import settings
from django.core.management import call_command
from django.template.defaultfilters import filesizeformat
from django.utils.timesince import timesince
from bot.plugins.base import BasePlugin
from bot.plugins.commands import command
from bot.users.decorators import bot_admin_required
        Check that the person sending the command has permission to restart the bot.
        We rely on ``supervisord`` here - if the process dies, supervisord will
        bring it back up.

        FIXME: https://docs.python.org/3/library/asyncio-dev.html#pending-task-destroyed
        """
        author_id = command.message.author.id
        logger.info('Restart issued by %s, with ID %d', command.message.author.name, author_id)
        await command.trigger_typing()
        await command.reply('Restarting...')
        raise KeyboardInterrupt

    @command()
    async def sysinfo(self, command):
        """
        Shows system/bot information
        """
        process = psutil.Process(os.getpid())
        mem_usage = process.memory_info().rss
        created = datetime.datetime.fromtimestamp(int(process.create_time()))

        msg = (
            f"Uptime: `{timesince(created)}`\n"
            f"Memory usage: `{filesizeformat(mem_usage)}`\n"
            f"OS: `{platform.system()}, {platform.release()}`\n"
            f"{settings.SITE_URL}, \n{settings.GITHUB_URL}\n"
        )
        await command.reply(msg)

    @command()

# 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/users/decorators.py
# def bot_admin_required(func):
#     """
#     This decorator peforms database lookups, so if you use it,
#     the plugin must be marked as ``has_blocking_io = True``.
#     """
# 
#     @wraps(func)
#     async def decorator(plugin, command, *args, **kwargs):
#         if not is_bot_admin(command.message):
#             await command.reply('You don\'t have permission for this command')
#             return
#         await func(plugin, command, *args, **kwargs)
#     return decorator


# Path: bot/plugins/system.py
import datetime
import logging
import os
import platform
import re
import psutil
from io import StringIO
from django.conf import settings
from django.core.management import call_command
from django.template.defaultfilters import filesizeformat
from django.utils.timesince import timesince
from bot.plugins.base import BasePlugin
from bot.plugins.commands import command
from bot.users.decorators import bot_admin_required

        Check that the person sending the command has permission to restart the bot.
        We rely on ``supervisord`` here - if the process dies, supervisord will
        bring it back up.

        FIXME: https://docs.python.org/3/library/asyncio-dev.html#pending-task-destroyed
        """
        author_id = command.message.author.id
        logger.info('Restart issued by %s, with ID %d', command.message.author.name, author_id)
        await command.trigger_typing()
        await command.reply('Restarting...')
        raise KeyboardInterrupt

    @command()
    async def sysinfo(self, command):
        """
        Shows system/bot information
        """
        process = psutil.Process(os.getpid())
        mem_usage = process.memory_info().rss
        created = datetime.datetime.fromtimestamp(int(process.create_time()))

        msg = (
            f"Uptime: `{timesince(created)}`\n"
            f"Memory usage: `{filesizeformat(mem_usage)}`\n"
            f"OS: `{platform.system()}, {platform.release()}`\n"
            f"{settings.SITE_URL}, \n{settings.GITHUB_URL}\n"
        )
        await command.reply(msg)

    @command()

    @bot_admin_required