diff --git a/copy-all-stable.sh b/copy-all-stable.sh index 2ccbd72..0ced998 100755 --- a/copy-all-stable.sh +++ b/copy-all-stable.sh @@ -9,6 +9,7 @@ cp say.py ~/.local/share/profanity/plugins/. cp whoami.py ~/.local/share/profanity/plugins/. cp wikipedia-prof.py ~/.local/share/profanity/plugins/. cp clients.py ~/.local/share/profanity/plugins/. +cp presence_notify.py ~/.local/share/profanity/plugins/. cp tests/python-test.py ~/.local/share/profanity/plugins/. cd pid diff --git a/presence_notify.py b/presence_notify.py new file mode 100644 index 0000000..2fe5a18 --- /dev/null +++ b/presence_notify.py @@ -0,0 +1,76 @@ +import prof + + +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") + return + + if arg1 == "off": + prof.settings_set_boolean("presence_notify", "enabled", False) + 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 + + 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)) + + +def prof_init(version, status, account_name, fulljid): + synopsis = [ + "/presence_notify on|off", + "/presence_notify all " + ] + description = "Send a desktop notification on presence updates." + args = [ + [ "on|off", "Enable/disable presence notifications" ], + [ "all ", "Enable all presence notifications for contact "] + ] + examples = [ + "/presence_notify on", + "/presence_notify all bob@server.org" + ] + + prof.register_command("/presence_notify", 0, 2, synopsis, description, args, examples, _cmd_presence_notify) + + prof.completer_add("/presence_notify", + [ "on", "off", "all" ] + ) + + +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") + + +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 {presence}".format(barejid=barejid, presence=presence), 5000, "Presence")