Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import socket, string, time, thread, math, re, time
- SERVER = 'irc.root-me.org'
- PORT = 6667
- NICKNAME = 'malhac_a'
- CHANNEL = '#root-me_challenge'
- def main():
- global IRC
- IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print("Connecting to server: " + SERVER)
- IRC.connect((SERVER, PORT))
- Listener()
- #thread.start_new_thread(Listener(),("Thread No:1",2))
- def login(nickname, username="malhac_a", password = None, realname="malhac_a", hostname="malhac_a", servername=SERVER):
- send_data(('USER ' + ' ' + username + ' ' + hostname + ' ' + servername + ' ' + realname + '\r\n'))
- #send_data('USER %s' % NICKNAME)
- send_data('NICK %s' % NICKNAME)
- def send_data(command):
- print("Sending command: " + command + "\n")
- IRC.send(command + '\n')
- def closeSocket():
- print("Closing socket")
- IRC.close()
- def Listener():
- login(NICKNAME)
- bufferConnection = IRC.recv(4096)
- send_data('JOIN %s' % CHANNEL)
- matching = False
- while (matching == False):
- send_data('PRIVMSG Candy : !ep1')
- bufferMsg = IRC.recv(8096)
- print("Receiving command: " + bufferMsg)
- if re.match(":Candy!Candy@root-me.org*", bufferMsg):
- matching = True
- res = calcul(bufferMsg)
- send_data("PRIVMSG Candy : !ep1 -rep %s" % res)
- bufferMsg = IRC.recv(8096)
- print("Receiving responde: " + bufferMsg)
- closeSocket()
- def calcul(bufferMsg):
- tabValue = bufferMsg.split("/")
- nb2 = tabValue[1]
- nb2 = nb2.replace(" ","")
- nb2 = nb2.replace("\n","")
- tmp = tabValue[0].split(":")
- nb1 = tmp[2]
- nb1 = nb1.replace(" ", "")
- var1 = math.sqrt(float(nb1))
- var2 = var1 * float(nb2)
- final = round(var2, 2)
- print (final)
- return float(final)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement