aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pycrctrl.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/pycrctrl.py b/pycrctrl.py
index 2f5d381..ae637a2 100644
--- a/pycrctrl.py
+++ b/pycrctrl.py
@@ -29,7 +29,10 @@ from io import BytesIO
import logging
import urllib.request
-import supybot.ircmsgs as ircmsgs
+try:
+ import supybot.ircmsgs as ircmsgs
+except ImportError:
+ ircmsgs = None
import random
@@ -205,8 +208,9 @@ class PyCRCtrl(object):
self.__ingamechat = text
self.state = self.state
- def __init__(self, irc, path, config="pycrctrl.ini"):
- self.irc = irc
+ def __init__(self, irc=None, path=".", config="pycrctrl.ini"):
+ if ircmsgs is not None:
+ self.irc = irc
self.path = path
self.loadConfigFile(config)
self.setupLog()
@@ -222,10 +226,10 @@ class PyCRCtrl(object):
raise OSError("No path specified")
with open(os.path.join(self.path,"scenarios.lst"), "r") as fobj:
- self.scenlist = fobj.readlines()
+ self.scenlist = [line.strip() for line in fobj.readlines()]
with open(os.path.join(self.path, "scenarios_league.lst"), "r") as fobj:
- self.league_scenlist = fobj.readlines()
+ self.league_scenlist = [line.strip() for line in fobj.readlines()]
self.log.debug("Scenario lists loaded.")
@@ -236,7 +240,7 @@ class PyCRCtrl(object):
self.log = logging.getLogger(type(self).__name__)
self.log.setLevel(getattr(logging, self.config["Logging"]["Level"], logging.INFO))
- if not hasattr(self.log, "handler_set"):
+ if not self.log.handlers:
ch = logging.FileHandler(
os.path.join(self.path, self.config["Logging"]["File"])
)
@@ -244,7 +248,7 @@ class PyCRCtrl(object):
ch.setFormatter(logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s"))
self.log.addHandler(ch)
- self.log.info("PyCRCtrl started.")
+ self.log.info("PyCRCtrl started.")
def loadConfigFile(self, config) -> None:
if self.path == None:
@@ -279,11 +283,6 @@ Ingamechat=true
[Updater]
Enabled=false
- [Addresses]
- snapshotList=http://openclonk.org/nightly-builds
- snapshotDownload=http://openclonk.org/builds/nightly/snapshots/{}
- autobuildList=https://autobuild.openclonk.org/api/v1/jobs
- autobuildAddress=https://autobuild.openclonk.org/static/binaries/{}
[RegExps]
LobbyStart=((?:Los geht's!|Action go!)\\s*)
@@ -336,11 +335,11 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-."""
while True:
try:
output = self.clonk.stdout.readline()
-
if re.match(self.config["RegExps"]["Shutdown"], output):
self.clonk.stdin.close()
elif output == "" and self.clonk.poll() is not None:
if self.clonk:
+ self.log.debug("poll() is not None, shutting down")
self.clonk.stdin.close()
self.clonk = None
self.scenario = ""
@@ -354,9 +353,10 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-."""
if output[0] == ">":
output = output[1:]
+ self.log.info(output)
part = self.isMessage(output)
if part and part.group(0) != self.irc.nick:
- self.log.info(output)
+ #self.log.info(output)
cmd = part.group(3).split(" ", 1)
found = False
x = None
@@ -386,7 +386,7 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-."""
if self.irc and self.ingamechat == "aktiviert":
if output.find("<" + self.irc.nick + ">") == -1:
- if self.isMessage(output) and output.find("[IRC]") == -1 and output.find(self.config["General"]["Prefix"]) == -1:
+ if self.isMessage(output) and "[IRC]" not in output and self.config["General"]["Prefix"] not in output:
self.irc.reply("[Clonk]{}".format(output), to=self.config["Channels"]["Ingame"])
elif any((re.match(self.config["RegExps"]["PlayerJoin"], output), re.match(self.config["RegExps"]["PlayerLeave"], output))):
@@ -419,7 +419,7 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-."""
return (CmdResult.SyntaxFail, "Bitte gib einen Szenarionamen an!")
if hasattr(scenario, "decode"):
try:
- scenario = scenario.decode(self.config["Clonk"]["Encoding"], "replace")
+ scenario = scenario.decode(self.config["Clonk"]["Encoding"])
except:
self.log.warning("Unable to decode {}".format(scenario))
return (CmdResult.RuntimeError, "Dekodierfehler. Bitte kontaktiere den Hoster dieses Servers.")