Merge pull request #3 from Et0h/master
Regex improvements, add rel offset
This commit is contained in:
commit
5496fc7ea9
@ -49,9 +49,9 @@ class ConsoleUI(threading.Thread):
|
|||||||
def showErrorMessage(self, message):
|
def showErrorMessage(self, message):
|
||||||
print("ERROR:\t" + message)
|
print("ERROR:\t" + message)
|
||||||
|
|
||||||
def _extractRegexSign(self, m):
|
def _extractSign(self, m):
|
||||||
if(m.group(1)):
|
if(m):
|
||||||
if(m.group(1) == "-"):
|
if(m == "-"):
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
@ -59,20 +59,22 @@ class ConsoleUI(threading.Thread):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _tryAdvancedCommands(self, data):
|
def _tryAdvancedCommands(self, data):
|
||||||
o = re.match(r"^(?:o|offset)\ ([+-])?\ ?(\d+[:\.]?)+$", data)
|
o = re.match(r"^(?:o|offset)\ ?(?P<sign>[/+-])?(?P<time>\d+(?:[^\d\.](?:\d+)){0,2}(?:\.(?:\d+))?)$", data)
|
||||||
s = re.match(r"^(?:s|seek)?\ ?([+-])?\ ?(\d+[:\.]?)+$", data) #careful! s will match o as well
|
s = re.match(r"^(?:s|seek)?\ ?(?P<sign>[+-])?(?P<time>\d+(?:[^\d\.](?:\d+)){0,2}(?:\.(?:\d+))?)$", data)
|
||||||
if(o):
|
if(o):
|
||||||
sign = self._extractRegexSign(o)
|
sign = self._extractSign(o.group('sign'))
|
||||||
t = utils.parseTime(o.group(2))
|
t = utils.parseTime(o.group('time'))
|
||||||
if(t is None):
|
if(t is None):
|
||||||
return
|
return
|
||||||
if(sign):
|
if (o.group('sign') == "/"):
|
||||||
t = self._syncplayClient.getUserOffset() + sign * t
|
t = self._syncplayClient.getPlayerPosition() - t
|
||||||
|
elif(sign):
|
||||||
|
t = self._syncplayClient.getUserOffset() + sign * t
|
||||||
self._syncplayClient.setUserOffset(t)
|
self._syncplayClient.setUserOffset(t)
|
||||||
return True
|
return True
|
||||||
elif s:
|
elif s:
|
||||||
sign = self._extractRegexSign(s)
|
sign = self._extractSign(s.group('sign'))
|
||||||
t = utils.parseTime(s.group(2))
|
t = utils.parseTime(s.group('time'))
|
||||||
if(t is None):
|
if(t is None):
|
||||||
return
|
return
|
||||||
if(sign):
|
if(sign):
|
||||||
@ -82,19 +84,19 @@ class ConsoleUI(threading.Thread):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _executeCommand(self, data):
|
def _executeCommand(self, data):
|
||||||
command = re.match(r"^([^\ ]+)(?:\ (.+))?", data)
|
command = re.match(r"^(?P<command>[^\ ]+)(?:\ (?P<parameter>.+))?", data)
|
||||||
if(not command):
|
if(not command):
|
||||||
return
|
return
|
||||||
if(command.group(1) in ["u", "undo", "revert"]):
|
if(command.group('command') in ["u", "undo", "revert"]):
|
||||||
tmp_pos = self._syncplayClient.getPlayerPosition()
|
tmp_pos = self._syncplayClient.getPlayerPosition()
|
||||||
self._syncplayClient.setPosition(self._syncplayClient.playerPositionBeforeLastSeek)
|
self._syncplayClient.setPosition(self._syncplayClient.playerPositionBeforeLastSeek)
|
||||||
self._syncplayClient.playerPositionBeforeLastSeek = tmp_pos
|
self._syncplayClient.playerPositionBeforeLastSeek = tmp_pos
|
||||||
elif (command.group(1) in ["l", "list", "users"]):
|
elif (command.group('command') in ["l", "list", "users"]):
|
||||||
self._syncplayClient.getUserList()
|
self._syncplayClient.getUserList()
|
||||||
elif (command.group(1) in ["p", "play", "pause"]):
|
elif (command.group('command') in ["p", "play", "pause"]):
|
||||||
self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused())
|
self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused())
|
||||||
elif (command.group(1) in ["r", "room"]):
|
elif (command.group('command') in ["r", "room"]):
|
||||||
room = command.group(2)
|
room = command.group('parameter')
|
||||||
if room == None:
|
if room == None:
|
||||||
if self._syncplayClient.userlist.currentUser.file:
|
if self._syncplayClient.userlist.currentUser.file:
|
||||||
room = self._syncplayClient.userlist.currentUser.file["name"]
|
room = self._syncplayClient.userlist.currentUser.file["name"]
|
||||||
@ -106,7 +108,7 @@ class ConsoleUI(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
if(self._tryAdvancedCommands(data)):
|
if(self._tryAdvancedCommands(data)):
|
||||||
return
|
return
|
||||||
if (command.group(1) not in ['help', 'h', '?', '/?', '\?']):
|
if (command.group('command') not in ['help', 'h', '?', '/?', '\?']):
|
||||||
self.showMessage("Unrecognized command")
|
self.showMessage("Unrecognized command")
|
||||||
self.showMessage("Available commands:", True)
|
self.showMessage("Available commands:", True)
|
||||||
self.showMessage("\tr [name] - change room", True)
|
self.showMessage("\tr [name] - change room", True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user