From a5c4e7ec39704cc94aed900881e0ce08d73f76ef Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 20:18:16 -0200 Subject: [PATCH 01/10] [irc] fix not joining --- syncplay/ircBot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 5fdf68c..656fbbb 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -49,7 +49,7 @@ class Bot(object): self.sock.recv(4096) #We don't want to join if nickserv hasn't done its job (shouldn't really matter, but good for vHost) if channel != '': - self.join(channel) + self.join(channel, channelPassword) self.active = True self.thread = threading.Thread(target=handlingThread, args=(self.sock, self)) @@ -75,7 +75,10 @@ class Bot(object): self.sockSend('PRIVMSG ' + who + ' :' + message) def join(self, channel, passw=''): if passw != '': passw = ' ' + passw - self.sockSend('JOIN ' + channel + passw) + self.sockSend('\r\nJOIN ' + channel + passw) + #Just to make sure we joined; doesn't hurt anyone + sleep(1) + self.sockSend('\r\nJOIN ' + channel + passw) def part(self, channel, reason=''): self.sockSend('PART ' + channel + ' :' + reason) def quit(self, reason='Leaving'): @@ -172,6 +175,9 @@ def handlingThread(sock, bot): lsplit = line.split(':') if len(lsplit) >= 2: + if lsplit[1].split(' ')[1] == '404': + bot.join(bot.channel, bot.channelPassword) + if 'PRIVMSG' in lsplit[1] or 'NOTICE' in lsplit[1]: # ---BEGIN WTF BLOCK--- lsplit = line.split(':') From 2aa872825347a34bede0042d78522dc701c650d6 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 20:43:50 -0200 Subject: [PATCH 02/10] Change "Error" to "Notice" when no rooms are found --- syncplay/ircBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 656fbbb..accc321 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -97,7 +97,7 @@ class Bot(object): rooms = self.functions[1]() if len(rooms) == 0: - self.msg(to, chr(3) + '5Error!' + chr(15) + ' No rooms found on server') + self.msg(to, chr(3) + '12Notice:' + chr(15) + ' No rooms found on server') return out = 'Currently the Syncplay server hosts viewing sessions as follows: ' From bd30e67a66b56d952de17b0005c654c971deae2a Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 20:49:52 -0200 Subject: [PATCH 03/10] [irc] fix IndexError exception --- syncplay/ircBot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index accc321..00f02da 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -175,8 +175,9 @@ def handlingThread(sock, bot): lsplit = line.split(':') if len(lsplit) >= 2: - if lsplit[1].split(' ')[1] == '404': - bot.join(bot.channel, bot.channelPassword) + if lsplit[1].split(' ') > 1: + if lsplit[1].split(' ')[1] == '404': + bot.join(bot.channel, bot.channelPassword) if 'PRIVMSG' in lsplit[1] or 'NOTICE' in lsplit[1]: # ---BEGIN WTF BLOCK--- From e4c57e6e972aef1758994651457352de6581081a Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:16:28 -0200 Subject: [PATCH 04/10] [irc] _hopefully_ fix unicode error --- syncplay/ircBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 00f02da..f97e9b2 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -70,7 +70,7 @@ class Bot(object): self.msg(self.channel, chr(2) + '<' + who + '>'+ chr(15) +' has jumped from ' + utils.formatTime(fromTime) + ' to ' + utils.formatTime(toTime) +' (room ' + room + ')') def sockSend(self, s): - self.sock.send(s + '\r\n') + self.sock.send(s + u'\r\n') def msg(self, who, message): self.sockSend('PRIVMSG ' + who + ' :' + message) def join(self, channel, passw=''): From 5a44c46e509733e4c8d6833bcd1ab19ac8a26892 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:20:46 -0200 Subject: [PATCH 05/10] [irc] no exception when the user does not have a file --- syncplay/ircBot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index f97e9b2..12cdb84 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -65,6 +65,8 @@ class Bot(object): def sp_paused(self, who, room): self.msg(self.channel, chr(2) + '<' + who + '>'+ chr(15) +' has paused (room ' + room + ')') def sp_fileplaying(self, who, filename, room): #for when syncplay knows what filename is being played + if filename == '': + return self.msg(self.channel, chr(2) + '<' + who + '>'+ chr(15) +' is playing "' + filename + '" (room ' + room + ')') def sp_seek(self, who, fromTime, toTime, room): self.msg(self.channel, chr(2) + '<' + who + '>'+ chr(15) +' has jumped from ' + utils.formatTime(fromTime) + ' to ' + utils.formatTime(toTime) +' (room ' + room + ')') @@ -122,7 +124,13 @@ class Bot(object): paused = self.functions[5](room) out = chr(2) + '' + chr(15) if paused else chr(2) + '' + chr(15) out += ' [' + utils.formatTime(self.functions[2](room)) + '/' + utils.formatTime(users[0]['length']) + '] ' - out += users[0]['file'] + + for u in users: + if u['file'] == None: continue + out += u['file'] + break + else: + out += '[no file]' self.msg(to, out) out = 'Users: ' i = 0 From 76186bc17b14fb5c873900e0d75cb2492acc6ed3 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:22:32 -0200 Subject: [PATCH 06/10] [irc] REALLY FIXES IT THIS TIME --- syncplay/ircBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 12cdb84..7516194 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -183,7 +183,7 @@ def handlingThread(sock, bot): lsplit = line.split(':') if len(lsplit) >= 2: - if lsplit[1].split(' ') > 1: + if len(lsplit[1].split(' ')) >= 2: if lsplit[1].split(' ')[1] == '404': bot.join(bot.channel, bot.channelPassword) From ac02d581b795da1a8d940ead50b4054029c9495f Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:24:24 -0200 Subject: [PATCH 07/10] [irc] print traceback on exceptions --- syncplay/ircBot.py | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 7516194..9fd036f 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -6,6 +6,7 @@ import socket import threading from syncplay import utils from time import sleep +import traceback class Bot(object): def __init__(self, server='irc.rizon.net', serverPassword='', port=6667, nick='SyncBot', nickservPass='', channel='', channelPassword='', functions=[]): @@ -172,36 +173,39 @@ def handlingThread(sock, bot): while bot.active: rcvd = sock.recv(4096).split('\n') for line in rcvd: - line = line.replace('\r', '') + try: + line = line.replace('\r', '') - if line.split(' ')[0] == 'PING': - try: - sock.send('\r\nPONG ' + line.split(' ')[1].replace(':', '') + '\r\n') - except: #if we were fooled by the server :C - sock.send('\r\nPONG\r\n') - #\r\n on the beggining too because if we send two things too fast, the IRC server can discern + if line.split(' ')[0] == 'PING': + try: + sock.send('\r\nPONG ' + line.split(' ')[1].replace(':', '') + '\r\n') + except: #if we were fooled by the server :C + sock.send('\r\nPONG\r\n') + #\r\n on the beggining too because if we send two things too fast, the IRC server can discern - lsplit = line.split(':') - if len(lsplit) >= 2: - if len(lsplit[1].split(' ')) >= 2: - if lsplit[1].split(' ')[1] == '404': - bot.join(bot.channel, bot.channelPassword) + lsplit = line.split(':') + if len(lsplit) >= 2: + if len(lsplit[1].split(' ')) >= 2: + if lsplit[1].split(' ')[1] == '404': + bot.join(bot.channel, bot.channelPassword) - if 'PRIVMSG' in lsplit[1] or 'NOTICE' in lsplit[1]: - # ---BEGIN WTF BLOCK--- - lsplit = line.split(':') - addrnfrom = '' - if '~' in lsplit[1]: - addrnfrom = lsplit[1].split('~')[1].split(' ')[0] - nfrom = lsplit[1].split('!')[0] - else: - nfrom = lsplit[1].split('!')[0] + if 'PRIVMSG' in lsplit[1] or 'NOTICE' in lsplit[1]: + # ---BEGIN WTF BLOCK--- + lsplit = line.split(':') + addrnfrom = '' + if '~' in lsplit[1]: + addrnfrom = lsplit[1].split('~')[1].split(' ')[0] + nfrom = lsplit[1].split('!')[0] + else: + nfrom = lsplit[1].split('!')[0] - if len(lsplit[1].split()) >= 3: - to = lsplit[1].split()[2] - msg = '' - for brks in lsplit[2:]: - msg += brks + ':' - msg = msg[:-1].lstrip() - # ---END WTF BLOCK- -- - bot.irc_onMsg(nfrom, addrnfrom, to, msg) + if len(lsplit[1].split()) >= 3: + to = lsplit[1].split()[2] + msg = '' + for brks in lsplit[2:]: + msg += brks + ':' + msg = msg[:-1].lstrip() + # ---END WTF BLOCK- -- + bot.irc_onMsg(nfrom, addrnfrom, to, msg) + except: + print traceback.format_exc() \ No newline at end of file From 0902154cef4815702c405a3024bdafef08a6e25c Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:52:39 -0200 Subject: [PATCH 08/10] [irc] fix stuff --- syncplay/ircBot.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 9fd036f..ef2f453 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -124,7 +124,14 @@ class Bot(object): users = self.functions[4](room) paused = self.functions[5](room) out = chr(2) + '' + chr(15) if paused else chr(2) + '' + chr(15) - out += ' [' + utils.formatTime(self.functions[2](room)) + '/' + utils.formatTime(users[0]['length']) + '] ' + time = self.functions[2](room) + if time == None: time = 0 + for u in users: + if u['length'] == None: continue + out += ' [' + time + '/' + utils.formatTime(u['length']) + '] ' + break + else: + out += ' ' for u in users: if u['file'] == None: continue @@ -153,7 +160,7 @@ class Bot(object): users = self.functions[4](room) for u in users: if u['nick'] == nickFrom: - self.functions[6](nickFrom, True) + self.functions[5](nickFrom, True) return self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') elif split[0].lower() == '!play': @@ -163,7 +170,7 @@ class Bot(object): users = self.functions[4](room) for u in users: if u['nick'] == nickFrom: - self.functions[6](nickFrom, False) + self.functions[5](nickFrom, False) return self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') elif split[0].lower() == '!help': From 0620a25e254ef0659fc1ea53ea5521d1e4b12199 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:56:42 -0200 Subject: [PATCH 09/10] [irc] *ahem* --- syncplay/ircBot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index ef2f453..2261298 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -160,7 +160,7 @@ class Bot(object): users = self.functions[4](room) for u in users: if u['nick'] == nickFrom: - self.functions[5](nickFrom, True) + self.functions[0](nickFrom, True) return self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') elif split[0].lower() == '!play': @@ -170,7 +170,7 @@ class Bot(object): users = self.functions[4](room) for u in users: if u['nick'] == nickFrom: - self.functions[5](nickFrom, False) + self.functions[0](nickFrom, False) return self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') elif split[0].lower() == '!help': From 5ea2880f24e2d1b8b46594e2014462f77de1b5f8 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 21:59:12 -0200 Subject: [PATCH 10/10] [irc] use formatTime --- syncplay/ircBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 2261298..1e6e1b7 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -128,7 +128,7 @@ class Bot(object): if time == None: time = 0 for u in users: if u['length'] == None: continue - out += ' [' + time + '/' + utils.formatTime(u['length']) + '] ' + out += ' [' + utils.formatTime(time) + '/' + utils.formatTime(u['length']) + '] ' break else: out += ' '