import time
from aztrom.irc.clientv1 import IRCClient

rot13 = str.maketrans('ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz', 'NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm')

client = IRCClient("irc.root-me.org", 6667)
time.sleep(2)
print(client.recv())

client.auth("aztrom")
time.sleep(2)
print(client.recv())

client.join("#root-me_challenge")
time.sleep(1)
print(client.recv())

client.send("candy", "!ep3")
time.sleep(1)
resp = client.recv()
print(resp)
for line in resp.split("\n"):
	if line.startswith(":Candy!Candy@root-me.org PRIVMSG aztrom :"):
		code = line.split("aztrom :")[1]
		print("Code = " + code)
		decoded = code.translate(rot13)
		print("Decoded = " + decoded)
		client.send("candy", "!ep3 -rep " + decoded)
		time.sleep(1)
		print(client.recv())
		break
