From 5a565caebaf1b0d85ec144712901bc5b98cd14a4 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Sun, 22 Apr 2018 21:46:02 +0200 Subject: [PATCH] Update channel topic with given prefix before | delimiter --- brmdoor_nfc_daemon.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index 3bd81d0..aef578f 100755 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -18,6 +18,8 @@ from nfc_smartcard import NFCDevice, NFCError from brmdoor_authenticator import UidAuthenticator, YubikeyHMACAuthenthicator, DesfireEd25519Authenthicator import unlocker +# Map request to change channel's topic to its new prefix. Prefix and rest are delimited with | +# Channel prefix must include the | character at end, e.g. "OPEN |" or "CLOSED |" channelPrefixMap = {} class BrmdoorConfigError(ConfigParser.Error): @@ -137,6 +139,7 @@ class NFCScanner(object): except Exception: logging.exception("Exception in main unlock thread") logging.info("Request topic") + channelPrefixMap[self.ircThread.channels[0]] = "OPEN |" self.ircThread.getTopic(self.ircThread.channels[0]) def sendIrcMessage(self, msg): @@ -275,6 +278,18 @@ class IrcThread(threading.Thread): topic = event.arguments[1] logging.info("Current topic: channel %s, topic %s", channel, topic) logging.info("Topic event - source %s, target: %s, type: %s", event.source, event.target, event.type) + # if change was requested, update channel topic + if channelPrefixMap.get(channel): + #update topic part before |, or replace entirely if | is not present + topicParts = topic.split("|", 1) + restOfTopic = "" + if (len(topicParts) > 1): + restOfTopic = topicParts[1] + + newTopic = channelPrefixMap[channel] + restOfTopic + logging.info("Setting new topic for channel %s: %s", channel, newTopic) + self.setTopic(channel, newTopic) + del channelPrefixMap[channel] # remove request def onNoTopic(self, connection, event): channel = event.arguments[0]