mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 08:34:00 +02:00
Update channel topic with given prefix before | delimiter
This commit is contained in:
parent
4ab81c8740
commit
5a565caeba
1 changed files with 15 additions and 0 deletions
|
@ -18,6 +18,8 @@ from nfc_smartcard import NFCDevice, NFCError
|
||||||
from brmdoor_authenticator import UidAuthenticator, YubikeyHMACAuthenthicator, DesfireEd25519Authenthicator
|
from brmdoor_authenticator import UidAuthenticator, YubikeyHMACAuthenthicator, DesfireEd25519Authenthicator
|
||||||
import unlocker
|
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 = {}
|
channelPrefixMap = {}
|
||||||
|
|
||||||
class BrmdoorConfigError(ConfigParser.Error):
|
class BrmdoorConfigError(ConfigParser.Error):
|
||||||
|
@ -137,6 +139,7 @@ class NFCScanner(object):
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Exception in main unlock thread")
|
logging.exception("Exception in main unlock thread")
|
||||||
logging.info("Request topic")
|
logging.info("Request topic")
|
||||||
|
channelPrefixMap[self.ircThread.channels[0]] = "OPEN |"
|
||||||
self.ircThread.getTopic(self.ircThread.channels[0])
|
self.ircThread.getTopic(self.ircThread.channels[0])
|
||||||
|
|
||||||
def sendIrcMessage(self, msg):
|
def sendIrcMessage(self, msg):
|
||||||
|
@ -275,6 +278,18 @@ class IrcThread(threading.Thread):
|
||||||
topic = event.arguments[1]
|
topic = event.arguments[1]
|
||||||
logging.info("Current topic: channel %s, topic %s", channel, topic)
|
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)
|
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):
|
def onNoTopic(self, connection, event):
|
||||||
channel = event.arguments[0]
|
channel = event.arguments[0]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue