aboutsummaryrefslogtreecommitdiffstats
path: root/pycrctrl.pyp
diff options
context:
space:
mode:
Diffstat (limited to 'pycrctrl.pyp')
-rw-r--r--pycrctrl.pyp45
1 files changed, 27 insertions, 18 deletions
diff --git a/pycrctrl.pyp b/pycrctrl.pyp
index e0c393b..7dc4a5b 100644
--- a/pycrctrl.pyp
+++ b/pycrctrl.pyp
@@ -15,6 +15,10 @@
import sys
+if sys.version_info < (3,6):
+ class ModuleNotFoundError(ImportError):
+ pass
+
import socket
import subprocess
import urllib.request
@@ -30,7 +34,13 @@ import supybot.ircmsgs as ircmsgs
from pickle import Unpickler
from PyQt5.QtCore import *
-from iostream import *
+try:
+ from iostream import *
+except ModuleNotFoundError:
+ with open("iostream.py","wb") as fobj:
+ fobj.write(urllib.request.urlopen("https://raw.githubusercontent.com/Fulgen301/pythonprograms/master/iostream/iostream.py").read())
+
+ from iostream import *
from random import randint
from time import sleep
@@ -236,14 +246,15 @@ class PyCRCtrl(object):
part = output[output.find(self.prefix)+len(self.prefix):].split(" ",1)
found = False
x = None
- for key in self.commands.keys():
- if key == part[0].splitlines()[0]:
- found = True
- try:
- x = self.commands[key](part[1])
- except IndexError:
- x = self.commands[key]()
- break
+ if len(part) > 0:
+ for key in self.commands.keys():
+ if key == part[0].splitlines()[0]:
+ found = True
+ try:
+ x = self.commands[key](part[1])
+ except IndexError:
+ x = self.commands[key]()
+ break
if not found:
self.writeToServer('Unbekannter Befehl: "' + part[0] + '"!')
@@ -256,10 +267,10 @@ class PyCRCtrl(object):
elif bool(re.match(self.RegExps["startExp"], output)):
self.state = "Läuft"
- #try:
- cout << output << endl
- #except:
- #pass
+ try:
+ cout << output << endl
+ except (UnicodeDecodeError, UnicodeEncodeError):
+ pass
# RegExps are from CRSM ((c) DerTod)
if self.irc:
@@ -344,7 +355,6 @@ class PyCRCtrl(object):
self.writeToServer("/start {}".format(time))
else:
self.writeToServer(b"/start")
- self.clonk.stdin.flush()
return (CmdResult.Success, "")
@@ -374,10 +384,9 @@ class PyCRCtrl(object):
def displayQueue(self, prm=None):
self.writeToServer(b"Warteschlange:")
- i = 1
- for scen in self.queue.queue:
- self.writeToServer("{}. {}".format(i, scen))
- i += 1
+
+ for i,scen in enumerate(self.queue.queue):
+ self.writeToServer("{}. {}".format(i+1, scen))
return (CmdResult.Success, "")