From 509ede3b0d7f3b6d2cb61c78fe18383a021d834f Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Sat, 22 Jun 2013 12:36:42 +0200 Subject: [PATCH] Added a DND-list for "!all" messages --- modules/active/notify_all.py | 54 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/modules/active/notify_all.py b/modules/active/notify_all.py index 865f583..f3c2a58 100644 --- a/modules/active/notify_all.py +++ b/modules/active/notify_all.py @@ -2,30 +2,52 @@ # -*- coding: utf-8 -*- import brathuhn - +from persistent import PersistentContainer +import config ############################################## +container = PersistentContainer(__name__+'_data',config.PCACHE) +if not "dnd" in container: + container["dnd"] = {} def notify_all(msg, args): - message = ""; - userJID = brathuhn.getUsers().items() - for a in userJID: - message += "{0}, ".format(a[0].getResource()); - - message = message[:-2]; - - if len(args)>=2 and args[1] != "": - message += ": "; - for a in args[1:]: - message += "{0} ".format(a); - - brathuhn.sendMsg(brathuhn.ROOM, message,'groupchat') - + message = ""; + arg1 = "" + if len(args)>=2: + arg1 = args[1] + userJID = brathuhn.getUsers().items() + dnd = container["dnd"] + + res = msg.getFrom().getResource() #TODO ugly + if arg1 == "dnd": + if not res in dnd: + dnd[res] = True + brathuhn.sendMsg(brathuhn.ROOM, "You won't be disturbed by \"!all\" anymore",'groupchat') + else: + del dnd[res] + brathuhn.sendMsg(brathuhn.ROOM, "You will be notified by \"!all\" messages",'groupchat') + container["dnd"] = dnd + return + + for a in userJID: + res = a[0].getResource() + if not res in dnd: + message += "{0}, ".format(res) + + message = message[:-2]; + + if len(args)>=2 and args[1] != "": + message += ": "; + for a in args[1:]: + message += "{0} ".format(a); + + brathuhn.sendMsg(brathuhn.ROOM, message,'groupchat') + ############################################## -brathuhn.addCommand("all","Usage: !all [msg]; Notify everyone in Channel", notify_all) +brathuhn.addCommand("all","Usage: !all [(dnd|message)]; Notify everyone in Channel, dnd-sets and unsets notification", notify_all) ##############################################