From c0ca446fd44711ac02e4a81b69ab4a5ebc78c219 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Sun, 18 Jun 2017 20:29:51 +0200 Subject: Fix regexps and other stuff Fixes #2 --- pycrctrl/pycrctrl.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pycrctrl/pycrctrl.py b/pycrctrl/pycrctrl.py index 37c95b5..6daef34 100644 --- a/pycrctrl/pycrctrl.py +++ b/pycrctrl/pycrctrl.py @@ -357,19 +357,19 @@ class PyCRCtrl(object): def setupConfig(self, config): #commandline sep = ":" if config["Clonk"]["commandlinePrefix"] == "/" else "=" - config["Clonk"]["commandline"] = " ".join("{}{}".format(config["Clonk"]["commandlinePrefix"], (sep.join(str(entry)) if isinstance(entry, list) else str(entry))) for entry in config["Clonk"]["commandline"]) + config["Clonk"]["commandline"] = " ".join("{}{}".format(config["Clonk"]["commandlinePrefix"], (sep.join(entry) if isinstance(entry, list) else str(entry))) for entry in config["Clonk"]["commandline"]) #regexps config["Clonk"]["RegExps"] = { - i:re.compile(self.decodeRegExp(config["Clonk"]["RegExps"][i])) for i in config["Clonk"]["RegExps"] + i:re.compile(self.decodeRegExp(config["Clonk"]["RegExps"][i], config["Clonk"]["encoding"])) for i in config["Clonk"]["RegExps"] } self.ingamechat = config["Clonk"]["IRC"]["ingamechat"] return config - def decodeRegExp(self, regexp): - return base64.b64decode(regexp).decode(self.config["Clonk"]["encoding"]) + def decodeRegExp(self, regexp, encoding=None): + return base64.b64decode(regexp).decode(encoding or self.config["Clonk"]["encoding"]) def host(self, scenario=None, user=None) -> str: if scenario == None: @@ -409,7 +409,7 @@ class PyCRCtrl(object): self.scenario = random.choice(self.scenlist) self.clonk = subprocess.Popen( - './{} {} "{}"'.format(self.config["Clonk"]["engine"], self.config["Clonk"]["commandline"] + self.config["Clonk"]["commandlinePrefix"] + ("league" if self.scenario in self.league_scenlist() else "noleague"),self.scenario), + './{} {} "{}"'.format(self.config["Clonk"]["engine"], self.config["Clonk"]["commandline"] + " " + self.config["Clonk"]["commandlinePrefix"] + ("league" if self.scenario in self.league_scenlist() else "noleague"), self.scenario), 0, None, subprocess.PIPE, @@ -454,7 +454,7 @@ class PyCRCtrl(object): if output[0] == ">": output = output[1:] - part = re.match("<(.*)> ({})(.*)".format(self.config["Clonk"]["prefix"], output)) + part = re.match("<(.*)> ({})(.*)".format(self.config["Clonk"]["prefix"]), output) if part and part.group(0) != self.irc.nick: cmd = part.group(3).split(" ", 1) found = False @@ -478,7 +478,7 @@ class PyCRCtrl(object): if self.config["Clonk"]["RegExps"]["lobbyStartExp"].match(output): self.state = "Lädt" - elif self.config["Clonk"]["RegExps"]["lobbyStartExp"].match(output): + elif self.config["Clonk"]["RegExps"]["startExp"].match(output): self.state = "Läuft" try: cout << output << endl @@ -517,7 +517,7 @@ class PyCRCtrl(object): return (CmdResult.RuntimeError, "") elif type(text) not in [str, QString]: try: - text = text.decode(self.config["Clonk"]["encoding"] + text = text.decode(self.config["Clonk"]["encoding"]) except: raise IOError("Cannot write anything else to the server except the following data types: QString, bytes, str, QByteArray (got {})".format(type(text).__name__)) @@ -532,7 +532,7 @@ class PyCRCtrl(object): if type(text) not in [str, QString]: try: - text = text.decode(self.config["Clonk"]["encoding"] + text = text.decode(self.config["Clonk"]["encoding"]) except: raise TypeError("text must be a string!") @@ -541,7 +541,7 @@ class PyCRCtrl(object): else: self.topic = text - return bool(self.irc.sendMsg(ircmsgs.topic(self.config.get["Clonk"]["IRC"]["Channels"]["ingame"], text))) + return bool(self.irc.sendMsg(ircmsgs.topic(self.config["Clonk"]["IRC"]["Channels"]["ingame"], text))) def start(self, time=None, user=""): -- cgit v1.2.3-54-g00ecf