# 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/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# class Message(list):
# 
#     def __init__(self, *args):
#         arg, *args = args
#         super().__init__([arg.upper()] + args)
# 
# Path: grazyna/irc/models.py
# class User(object):
#     """User class - has nick, realname, and host"""
#     nick = ""
#     host = ""
#     realname = ""
# 
#     def __init__(self, prefix):
#         try:
#             self.nick, _, name_host = prefix.partition('!')
#             self.realname, _, self.host = name_host.partition('@')
#         except:
#             pass
# 
#     @property
#     def prefix(self):
#         return "%s@%s" % (self.realname, self.host)
# 
#     def __repr__(self):
#         return "User('%s!%s')" % (self.nick, self.prefix)
# 
#     def __eq__(self, other):
#         if not isinstance(other, type(self)):
#             return False
# 
#         return (
#             self.nick == other.nick
#             and self.realname == other.realname
#             and self.host == other.host
#         )


from grazyna.request import RequestBot
from grazyna.test_mocks.sender import SayMessage, Message
from grazyna.irc.models import User
    assert protocol.messages == [SayMessage('#czarnobyl', 'foobar')]


def test_notice(protocol):
    bot = make_bot(protocol)
    bot.notice('foobar')
    assert protocol.messages == [Message('NOTICE', 'socek', ':foobar')]


def test_reply(protocol):
    bot = make_bot(protocol)
    bot.reply('foobar')
    assert protocol.messages == [SayMessage('#czarnobyl', 'socek: foobar')]


def test_kick(protocol):
    bot = make_bot(protocol)
    bot.kick(who='firemark', why='dunno lol')
    assert protocol.messages == [Message('KICK', '#czarnobyl', 'firemark', ':dunno lol')]


def test_kick_on_private(protocol):
    bot = make_bot(protocol, private=True)
    bot.kick()  # is not possible to kick on private message
    assert protocol.messages == []
    

def test_private_say(protocol):
    bot = make_bot(protocol)
    bot.private_say('foobar')

# 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/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# class Message(list):
# 
#     def __init__(self, *args):
#         arg, *args = args
#         super().__init__([arg.upper()] + args)
# 
# Path: grazyna/irc/models.py
# class User(object):
#     """User class - has nick, realname, and host"""
#     nick = ""
#     host = ""
#     realname = ""
# 
#     def __init__(self, prefix):
#         try:
#             self.nick, _, name_host = prefix.partition('!')
#             self.realname, _, self.host = name_host.partition('@')
#         except:
#             pass
# 
#     @property
#     def prefix(self):
#         return "%s@%s" % (self.realname, self.host)
# 
#     def __repr__(self):
#         return "User('%s!%s')" % (self.nick, self.prefix)
# 
#     def __eq__(self, other):
#         if not isinstance(other, type(self)):
#             return False
# 
#         return (
#             self.nick == other.nick
#             and self.realname == other.realname
#             and self.host == other.host
#         )


# Path: grazyna/tests/test_request.py
from grazyna.request import RequestBot
from grazyna.test_mocks.sender import SayMessage, Message
from grazyna.irc.models import User

    assert protocol.messages == [SayMessage('#czarnobyl', 'foobar')]


def test_notice(protocol):
    bot = make_bot(protocol)
    bot.notice('foobar')
    assert protocol.messages == [Message('NOTICE', 'socek', ':foobar')]


def test_reply(protocol):
    bot = make_bot(protocol)
    bot.reply('foobar')
    assert protocol.messages == [SayMessage('#czarnobyl', 'socek: foobar')]


def test_kick(protocol):
    bot = make_bot(protocol)
    bot.kick(who='firemark', why='dunno lol')
    assert protocol.messages == [Message('KICK', '#czarnobyl', 'firemark', ':dunno lol')]


def test_kick_on_private(protocol):
    bot = make_bot(protocol, private=True)
    bot.kick()  # is not possible to kick on private message
    assert protocol.messages == []
    

def test_private_say(protocol):
    bot = make_bot(protocol)
    bot.private_say('foobar')

    assert protocol.messages == [SayMessage('socek', 'foobar')]