From 2ae3c5f701083314bc07af9fbaad608a25e5e065 Mon Sep 17 00:00:00 2001 From: Nyo Date: Tue, 20 Dec 2016 21:22:25 +0100 Subject: [PATCH] .BANCHO. Add redis notifications pubsub handler --- pep.py | 2 ++ pubSubHandlers/notificationHandler.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 pubSubHandlers/notificationHandler.py diff --git a/pep.py b/pep.py index 9e44058..2d3d32a 100644 --- a/pep.py +++ b/pep.py @@ -36,6 +36,7 @@ from pubSubHandlers import changeUsernameHandler from pubSubHandlers import disconnectHandler from pubSubHandlers import banHandler +from pubSubHandlers import notificationHandler from pubSubHandlers import updateSilenceHandler from pubSubHandlers import updateStatsHandler @@ -275,6 +276,7 @@ if __name__ == "__main__": "peppy:update_cached_stats": updateStatsHandler.handler(), "peppy:silence": updateSilenceHandler.handler(), "peppy:ban": banHandler.handler(), + "peppy:notification": notificationHandler.handler(), }).start() # Start tornado diff --git a/pubSubHandlers/notificationHandler.py b/pubSubHandlers/notificationHandler.py new file mode 100644 index 0000000..b6ab450 --- /dev/null +++ b/pubSubHandlers/notificationHandler.py @@ -0,0 +1,19 @@ +from common.redis import generalPubSubHandler +from objects import glob +from constants import serverPackets + +class handler(generalPubSubHandler.generalPubSubHandler): + def __init__(self): + super().__init__() + self.structure = { + "userID": 0, + "message": "" + } + + def handle(self, data): + data = super().parseData(data) + if data is None: + return + targetToken = glob.tokens.getTokenFromUserID(data["userID"]) + if targetToken is not None: + targetToken.enqueue(serverPackets.notification(data["message"])) \ No newline at end of file