From dff203f4365f81ff74ca42216cde7d046c59fed8 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 18:56:04 -0200 Subject: [PATCH 1/4] [irc] remove "room" argument for !play and !pause --- syncplay/ircBot.py | 58 ++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 2d11cad..fd75481 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -19,10 +19,10 @@ class Bot(object): # channel - channel to autojoin and interact with # channelPassword - if channel is +k # functions - list/tuple of functions that can be used from the bot: - # * pause(setBy, room, state=bool) + # * pause(setBy, state=bool) # * getRooms() -> list # * getPosition(room) -> int - # * setPosition(setBy, room, seconds) + # * setPosition(setBy, seconds) # * getUsers(room) -> list of {'nick': str, 'file': str, 'length': int} # * isPaused(room) -> bool @@ -132,41 +132,29 @@ class Bot(object): else: self.msg(to, chr(2) + 'Usage:' + chr(15) + ' !roominfo [room]') elif split[0].lower() == '!pause': - if len(split) >= 2: - rooms = self.functions[1]() - for room in split[1:]: - if (room in rooms) == False: - self.msg(to, chr(3) + '5Error!' + chr(15) + ' Room does not exists (' + room + ')') - else: - users = self.functions[4](room) - for u in users: - if u['nick'] == nickFrom: - break - else: - self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick is not in the specified room') - continue + rooms = self.functions[1]() - self.functions[6](nickFrom, room, True) - else: - self.msg(to, chr(2) + 'Usage:' + chr(15) + ' !pause [room]') + for room in rooms: + users = self.functions[4](room) + for u in users: + if u['nick'] == nickFrom: + self.functions[6](nickFrom, True) + break + else: + self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') + return elif split[0].lower() == '!play': - if len(split) >= 2: - rooms = self.functions[1]() - for room in split[1:]: - if (room in rooms) == False: - self.msg(to, chr(3) + '5Error!' + chr(15) + ' Room does not exists (' + room + ')') - else: - users = self.functions[4](room) - for u in users: - if u['nick'] == nickFrom: - break - else: - self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick is not in the specified room') - continue - - self.functions[6](room, False) - else: - self.msg(to, chr(2) + 'Usage:' + chr(15) + ' !play [room]') + rooms = self.functions[1]() + + for room in rooms: + users = self.functions[4](room) + for u in users: + if u['nick'] == nickFrom: + self.functions[6](nickFrom, False) + break + else: + self.msg(to, chr(3) + '5Error!' + chr(15) + ' Your nick was not found on the server') + return elif split[0].lower() == '!help': self.msg(to, chr(2) + 'Available commands:' + chr(15) + ' !rooms / !roominfo [room] / !pause / !play') From 5d72d7cd89b34afb0c81669f211c67151fb3184c Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 19:15:47 -0200 Subject: [PATCH 2/4] [irc] remove extra variable passed to Bot.msg --- syncplay/ircBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 2d79729..cf20185 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -123,7 +123,7 @@ class Bot(object): else: out += chr(3) + '2' + user['nick'] + chr(15) + ', ' i += 1 - self.msg(nickFrom, to, out) + self.msg(to, out) else: self.msg(to, chr(2) + 'Usage:' + chr(15) + ' !roominfo [room]') elif split[0].lower() == '!pause': From cae753ec567cfaf0b58b55c3bf850e182e7520ba Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 19:20:21 -0200 Subject: [PATCH 3/4] [irc] sp_seek --- syncplay/ircBot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index cf20185..6b15e8b 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -64,6 +64,8 @@ class Bot(object): 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 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 + ')') ################################## def sockSend(self, s): From a45bb6858e057e55927235a2048a436fdcf11b03 Mon Sep 17 00:00:00 2001 From: HarHar Date: Thu, 24 Jan 2013 19:21:46 -0200 Subject: [PATCH 4/4] Small, inefficient (and maybe unnecessary) flood protection --- syncplay/ircBot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syncplay/ircBot.py b/syncplay/ircBot.py index 6b15e8b..4ea5e53 100644 --- a/syncplay/ircBot.py +++ b/syncplay/ircBot.py @@ -5,6 +5,7 @@ import socket import threading from syncplay import utils +from time import sleep class Bot(object): def __init__(self, server='irc.rizon.net', serverPassword='', port=6667, nick='SyncBot', nickservPass='', channel='', channelPassword='', functions=[]): @@ -85,6 +86,7 @@ class Bot(object): self.sockSend('NICK ' + newnick) self.nick = newnick def irc_onMsg(self, nickFrom, host, to, msg): + sleep(0.5) if to[0] == '#': #channel split = msg.split(' ')