diff --git a/presence_notify.py b/presence_notify.py index d8fbbdd..55c85b8 100644 --- a/presence_notify.py +++ b/presence_notify.py @@ -6,20 +6,14 @@ def _show_settings(): mode = prof.settings_get_string("presence_notify", "mode", "all") prof.cons_show("Mode: {mode}".format(mode=mode)) - # all_list = prof.settings_get_string_list("presence_notify", "all") - # if all_list and len(all_list) > 0: - # prof.cons_show("All:") - # for item in all_list: - # prof.cons_show(" {barejid}".format(barejid=item)) - - # online_list = prof.settings_get_string_list("presence_notify", "online") - # if online_list and len(online_list) > 0: - # prof.cons_show("Online/offline:") - # for item in online_list: - # prof.cons_show(" {barejid}".format(barejid=item)) + ignored_list = prof.settings_get_string_list("presence_notify", "ignored") + if ignored_list and len(ignored_list) > 0: + prof.cons_show("Ignored:") + for contact in ignored_list: + prof.cons_show(" {barejid}".format(barejid=contact)) -def _cmd_presence_notify(arg1=None, arg2=None): +def _cmd_presence_notify(arg1=None, arg2=None, arg3=None): if arg1 == "all": prof.settings_set_string("presence_notify", "mode", "all") prof.cons_show("Notifying on all presence changes") @@ -35,53 +29,70 @@ def _cmd_presence_notify(arg1=None, arg2=None): prof.cons_show("Presence notifications disabled") return - # if arg1 == "all": - # if not arg2: - # prof.cons_bad_cmd_usage("/presence_notify") - # return - # prof.settings_string_list_add("presence_notify", "all", arg2) - # prof.settings_string_list_remove("presence_notify", "online", arg2) - # prof.cons_show("Enabled all presence notifications for {barejid}".format(barejid=arg2)) - # return + if arg1 == "ignored": + if arg2 == "clear": + prof.settings_string_list_remove_all("presence_notify", "ignored") + prof.cons_show("Removed all ignored contacts for presence notifications") + return - # if arg1 == "online": - # if not arg2: - # prof.cons_bad_cmd_usage("/presence_notify") - # return - # prof.settings_string_list_add("presence_notify", "online", arg2) - # prof.settings_string_list_remove("presence_notify", "all", arg2) - # prof.cons_show("Enabled online/offline presence notifications for {barejid}".format(barejid=arg2)) - # return + if arg2 == "add": + if not arg3: + prof.cons_bad_cmd_usage("/presence_notify") + return + prof.settings_string_list_add("presence_notify", "ignored", arg3) + prof.cons_show("Added {contact} to ignored contacts for presence notifications".format(contact=arg3)) + return + + if arg2 == "remove": + if not arg3: + prof.cons_bad_cmd_usage("/presence_notify") + return + res = prof.settings_string_list_remove("presence_notify", "ignored", arg3) + if res: + prof.cons_show("Removed {contact} from ignored contacts for presence notifications".format(contact=arg3)) + else: + prof.cons_show("{contact} not in ignore list for presence notiications".format(contact=arg3)) + return + + prof.cons_bad_cmd_usage("/presence_notify") + return _show_settings() + def prof_init(version, status, account_name, fulljid): synopsis = [ "/presence_notify all|online|off", - "/presence_notify all ", - "/presence_notify online " + "/presence_notify ignored add|remove|clear []" ] description = "Send a desktop notification on presence updates." args = [ - [ "all", "Enable all presence notifications" ], - [ "online", "Enable only online/offline presence notifications" ], - [ "off", "Disable presence notifications" ], - [ "all ", "Enable all presence notifications for contact "], - [ "online ", "Enable only online/offline presence notifications for contact "] + [ "all", "Enable all presence notifications" ], + [ "online", "Enable only online/offline presence notifications" ], + [ "off", "Disable presence notifications" ], + [ "ignored add|remove ", "Add or remove a contact from the list excluded from presence notifications"], + [ "ignored clear", "Clear the list of excluded contacts"] ] examples = [ - "/presence_notify on", - "/presence_notify all bob@server.org" + "/presence_notify all", + "/presence_notify ignored add bob@server.org" ] - - prof.register_command("/presence_notify", 0, 2, synopsis, description, args, examples, _cmd_presence_notify) + + prof.register_command("/presence_notify", 0, 3, synopsis, description, args, examples, _cmd_presence_notify) prof.completer_add("/presence_notify", - [ "all", "online", "off" ] + [ "all", "online", "off", "ignored" ] + ) + prof.completer_add("/presence_notify ignored", + [ "add", "remove", "clear" ] ) def _do_notify(barejid, presence): + ignored = prof.settings_get_string_list("presence_notify", "ignored") + if ignored and barejid in ignored: + return False + mode = prof.settings_get_string("presence_notify", "mode", "all") if mode == "all": return True @@ -93,16 +104,6 @@ def _do_notify(barejid, presence): else: # off return False - # all_list = prof.settings_get_string_list("presence_notify", "all") - # if not all_list: - # return True - # elif len(all_list) == 0: - # return True - # elif barejid in settings_list: - # return True - # else: - # return False - def prof_on_contact_presence(barejid, resource, presence, status, priority): if _do_notify(barejid, presence):