From d5dcd54ec8171bbb577e5533a68f9e902653e2ee Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 3 Aug 2016 22:37:51 +0100 Subject: [PATCH] Add status to presense_notify.py --- presence_notify.py | 130 ++++++++++++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 42 deletions(-) diff --git a/presence_notify.py b/presence_notify.py index ef3ff6b..d8fbbdd 100644 --- a/presence_notify.py +++ b/presence_notify.py @@ -1,48 +1,73 @@ import prof +def _show_settings(): + prof.cons_show("Presence notify plugin 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)) + + def _cmd_presence_notify(arg1=None, arg2=None): - if arg1 == "on": - prof.settings_set_boolean("presence_notify", "enabled", True) - prof.cons_show("Presence notifications enabled") + if arg1 == "all": + prof.settings_set_string("presence_notify", "mode", "all") + prof.cons_show("Notifying on all presence changes") + return + + if arg1 == "online": + prof.settings_set_string("presence_notify", "mode", "online") + prof.cons_show("Notifying on online/offline presence changes only") return if arg1 == "off": - prof.settings_set_boolean("presence_notify", "enabled", False) + prof.settings_set_string("presence_notify", "mode", "off") 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 == "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 - prof.cons_show("Presence notify plugin settings:") - enabled = prof.settings_get_boolean("presence_notify", "enabled", False) - if enabled: - prof.cons_show("Enabled: ON") - else: - prof.cons_show("Enabled: OFF") - all_res = prof.settings_get_string_list("presence_notify", "all") - if all_res and len(all_res) > 0: - prof.cons_show("All:") - for item in all_res: - prof.cons_show(" {barejid}".format(barejid=item)) + # 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 + _show_settings() def prof_init(version, status, account_name, fulljid): synopsis = [ - "/presence_notify on|off", - "/presence_notify all " + "/presence_notify all|online|off", + "/presence_notify all ", + "/presence_notify online " ] description = "Send a desktop notification on presence updates." args = [ - [ "on|off", "Enable/disable presence notifications" ], - [ "all ", "Enable all presence notifications for contact "] + [ "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 "] ] examples = [ "/presence_notify on", @@ -52,25 +77,46 @@ def prof_init(version, status, account_name, fulljid): prof.register_command("/presence_notify", 0, 2, synopsis, description, args, examples, _cmd_presence_notify) prof.completer_add("/presence_notify", - [ "on", "off", "all" ] + [ "all", "online", "off" ] ) +def _do_notify(barejid, presence): + mode = prof.settings_get_string("presence_notify", "mode", "all") + if mode == "all": + return True + elif mode == "online": + if presence == "online" or presence == "offline": + return True + else: + return False + 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): - enabled = prof.settings_get_boolean("presence_notify", "enabled", False) - if enabled: - all_res = prof.settings_get_string_list("presence_notify", "all") - if not all_res or len(all_res) == 0: - prof.notify("{barejid} is {presence}".format(barejid=barejid, presence=presence), 5000, "Presence") - elif barejid in all_res: - prof.notify("{barejid} is {presence}".format(barejid=barejid, presence=presence), 5000, "Presence") + if _do_notify(barejid, presence): + message = "{barejid} is {presence}".format(barejid=barejid, presence=presence) + if status: + message = message + ", \"{status}\"".format(status=status) + prof.notify(message, 5000, "Presence") + return def prof_on_contact_offline(barejid, resource, status): - enabled = prof.settings_get_boolean("presence_notify", "enabled", False) - if enabled: - all_res = prof.settings_get_string_list("presence_notify", "all") - if not all_res or len(all_res) == 0: - prof.notify("{barejid} is offline".format(barejid=barejid), 5000, "Presence") - elif barejid in all_res: - prof.notify("{barejid} is offline".format(barejid=barejid), 5000, "Presence") + if _do_notify(barejid, "offline"): + message = "{barejid} is offline".format(barejid=barejid) + if status: + message = message + ", \"{status}\"".format(status=status) + prof.notify(message, 5000, "Presence") + return \ No newline at end of file