# Path: grazyna/models.py
# class Message(Base):
#     __tablename__ = 'messages'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     created = Column(DateTime, default=func.now())
#     channel = Column(String(30), nullable=False, index=True)
#     key = Column(String(20), nullable=False, index=True)
#     message = Column(String(200), nullable=False)
# 
# Path: grazyna/request.py
# class RequestBot(object):
#     """First argument in register functions.
#     Has useful informations as channel, nick
#     and methods to communicate with user/channel"""
# 
#     __slots__ = ('private', 'user', 'chan', 'protocol', 'config', 'plugin',
#                  'temp')
# 
#     def __init__(self, protocol, *, user=None, chan=None, private=False,
#                  config=None, plugin=None, temp=None):
#         self.protocol = protocol
#         self.private = private
#         self.user = user
#         self.chan = chan
#         self.config = config
#         self.plugin = plugin
#         self.temp = temp
# 
#     @coroutine
#     def is_admin(self, nick=None):
#         nick = nick or self.user.nick
#         result = yield from self.protocol.whois(nick)
#         return result.account in self.protocol.config.getlist('main', 'admins')
# 
#     @property
#     def nick_chan(self):
#         return self.user.nick if self.private else self.chan
# 
#     def say(self, msg, nick_chan=None):
#         nick_chan = nick_chan or self.nick_chan
#         self.protocol.say(nick_chan, msg)
# 
#     def notice(self, msg, nick=None):
#         self.protocol.notice(nick or self.user.nick, msg)
# 
#     def reply(self, msg, chan=None, nick=None):
#         self.protocol.reply(nick or self.user.nick, msg, chan or self.chan)
# 
#     def kick(self, who=None, why='', chan=None):
#         if self.private:
#             return
#         self.protocol.kick(who or self.user.nick, chan or self.chan, why)
# 
#     def private_say(self, msg, nick=None):
#         self.protocol.say(nick or self.user.nick, msg)
# 
#     def command(self, *args):
#         self.protocol.send(*args)
# 
#     def command_msg(self, *args):
#         self.protocol.send_msg(*args)
# 
#     def mode(self, flag, arg, chan=None):
#         self.protocol.mode(chan or self.chan, flag, arg)
# 
#     def time_ban(self, time, who=None, why='', prefix=None, chan=None):
#         chan = chan or self.chan
#         prefix = prefix or "*!%s@%s" % (self.user.realname, self.user.host)
#         who = who or self.user.nick
#         self.protocol.time_ban(time, who, chan, why, prefix)
# 
# Path: grazyna/format.py
# def bold(msg):
# def underline(msg):
# def italic(msg):
# def color(msg, front, back=None):


from asyncio import async, coroutine
from asyncio.futures import Future
from grazyna.models import Message
from grazyna.request import RequestBot
from grazyna import format
from importlib import reload
from collections import defaultdict
from inspect import getcallargs
from datetime import datetime, timedelta
from sqlalchemy.sql.functions import func
import re
import traceback
import sys
                yield from self.check_white_black_lists(cfg, channel, user)
            )
            if is_good:
                yield from self.execute_func(
                    func, plugin, private, channel, user, args, {})

    def find_function_in_plugin_with_name(self, private=None):
        return (
            (plugin, func)
            for name, plugin in self.plugins.items()
            for func in plugin
            if private is None
            or (not private and func.on_channel)
            or (private and func.on_private)
        )

    @coroutine
    def find_command(self, cmd, private=None, channel=None, user=None):
        for plugin, func in self.get_commands(private):
            is_good = yield from self.cmd_is_good(
                plugin, func, cmd, private, channel, user
            )
            if is_good:
                return plugin, func
        return None, None

    @coroutine
    def cmd_is_good(self, plugin, func, cmd=None, private=False, channel=None, user=None):
        cfg = self.get_plugin_cfg(plugin.name)


# Path: grazyna/models.py
# class Message(Base):
#     __tablename__ = 'messages'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     created = Column(DateTime, default=func.now())
#     channel = Column(String(30), nullable=False, index=True)
#     key = Column(String(20), nullable=False, index=True)
#     message = Column(String(200), nullable=False)
# 
# Path: grazyna/request.py
# class RequestBot(object):
#     """First argument in register functions.
#     Has useful informations as channel, nick
#     and methods to communicate with user/channel"""
# 
#     __slots__ = ('private', 'user', 'chan', 'protocol', 'config', 'plugin',
#                  'temp')
# 
#     def __init__(self, protocol, *, user=None, chan=None, private=False,
#                  config=None, plugin=None, temp=None):
#         self.protocol = protocol
#         self.private = private
#         self.user = user
#         self.chan = chan
#         self.config = config
#         self.plugin = plugin
#         self.temp = temp
# 
#     @coroutine
#     def is_admin(self, nick=None):
#         nick = nick or self.user.nick
#         result = yield from self.protocol.whois(nick)
#         return result.account in self.protocol.config.getlist('main', 'admins')
# 
#     @property
#     def nick_chan(self):
#         return self.user.nick if self.private else self.chan
# 
#     def say(self, msg, nick_chan=None):
#         nick_chan = nick_chan or self.nick_chan
#         self.protocol.say(nick_chan, msg)
# 
#     def notice(self, msg, nick=None):
#         self.protocol.notice(nick or self.user.nick, msg)
# 
#     def reply(self, msg, chan=None, nick=None):
#         self.protocol.reply(nick or self.user.nick, msg, chan or self.chan)
# 
#     def kick(self, who=None, why='', chan=None):
#         if self.private:
#             return
#         self.protocol.kick(who or self.user.nick, chan or self.chan, why)
# 
#     def private_say(self, msg, nick=None):
#         self.protocol.say(nick or self.user.nick, msg)
# 
#     def command(self, *args):
#         self.protocol.send(*args)
# 
#     def command_msg(self, *args):
#         self.protocol.send_msg(*args)
# 
#     def mode(self, flag, arg, chan=None):
#         self.protocol.mode(chan or self.chan, flag, arg)
# 
#     def time_ban(self, time, who=None, why='', prefix=None, chan=None):
#         chan = chan or self.chan
#         prefix = prefix or "*!%s@%s" % (self.user.realname, self.user.host)
#         who = who or self.user.nick
#         self.protocol.time_ban(time, who, chan, why, prefix)
# 
# Path: grazyna/format.py
# def bold(msg):
# def underline(msg):
# def italic(msg):
# def color(msg, front, back=None):


# Path: grazyna/modules.py
from asyncio import async, coroutine
from asyncio.futures import Future
from grazyna.models import Message
from grazyna.request import RequestBot
from grazyna import format
from importlib import reload
from collections import defaultdict
from inspect import getcallargs
from datetime import datetime, timedelta
from sqlalchemy.sql.functions import func
import re
import traceback
import sys

                yield from self.check_white_black_lists(cfg, channel, user)
            )
            if is_good:
                yield from self.execute_func(
                    func, plugin, private, channel, user, args, {})

    def find_function_in_plugin_with_name(self, private=None):
        return (
            (plugin, func)
            for name, plugin in self.plugins.items()
            for func in plugin
            if private is None
            or (not private and func.on_channel)
            or (private and func.on_private)
        )

    @coroutine
    def find_command(self, cmd, private=None, channel=None, user=None):
        for plugin, func in self.get_commands(private):
            is_good = yield from self.cmd_is_good(
                plugin, func, cmd, private, channel, user
            )
            if is_good:
                return plugin, func
        return None, None

    @coroutine
    def cmd_is_good(self, plugin, func, cmd=None, private=False, channel=None, user=None):
        cfg = self.get_plugin_cfg(plugin.name)


        if cmd is not None and func.cmd.format(**cfg) != cmd: