# close your eyes - if you don't look it does not look hacky :-)
sys.path.append('../../implementation/checkers')
import checker


PORT = 6667 if len(sys.argv) < 2 else sys.argv[1]
HOST = 'localhost' if len(sys.argv) < 3 else sys.argv[2]


client1 = checker.RandomClient(HOST, PORT)
client2 = checker.RandomClient(HOST, PORT)


channel = '#' + checker.generate_string(10)
client1.send('JOIN :%s' % channel)
client2.send('JOIN :%s' % channel)


c1r = client1.recv_until(' 366 ', error=('First in channel: Waited for 366 '
                                         'status but got none :('))
c2r = client2.recv_until(' 366 ', error=('Second in channel: Waited for 366 '
                                         'status but got none :('))


checker.check_regex(r':[^ ]+ 353 %s @ %s :@%s'
                    % (client1.nickname, channel, client1.nickname),
                    c1r,
                    'Status 353 message has no OP-prefix for client 1.')

# close your eyes - if you don't look it does not look hacky :-)
sys.path.append('../../implementation/checkers')
import checker


PORT = 6667 if len(sys.argv) < 2 else sys.argv[1]
HOST = 'localhost' if len(sys.argv) < 3 else sys.argv[2]


client1 = checker.RandomClient(HOST, PORT)
client2 = checker.RandomClient(HOST, PORT)


channel = '#' + checker.generate_string(10)
client1.send('JOIN :%s' % channel)


client2.send('WHOIS :%s' % client1.nickname)
error_msg = 'Waited for 5 seconds on 318 status code.'
replies = client2.recv_until(' 318 ', error=error_msg)


checker.check_regex(r':[^ ]+ 311 %s %s x [^ ]+ \* :[\da-fA-F:\.]+:\d+'
                    % (client2.nickname, client1.nickname),
                    replies,
                    'Status 311 message missing/incomplete')


checker.check_regex(r':[^ ]+ 319 %s %s :%s'