Added ignore list to presence_notify.py
This commit is contained in:
@@ -6,20 +6,14 @@ def _show_settings():
|
|||||||
mode = prof.settings_get_string("presence_notify", "mode", "all")
|
mode = prof.settings_get_string("presence_notify", "mode", "all")
|
||||||
prof.cons_show("Mode: {mode}".format(mode=mode))
|
prof.cons_show("Mode: {mode}".format(mode=mode))
|
||||||
|
|
||||||
# all_list = prof.settings_get_string_list("presence_notify", "all")
|
ignored_list = prof.settings_get_string_list("presence_notify", "ignored")
|
||||||
# if all_list and len(all_list) > 0:
|
if ignored_list and len(ignored_list) > 0:
|
||||||
# prof.cons_show("All:")
|
prof.cons_show("Ignored:")
|
||||||
# for item in all_list:
|
for contact in ignored_list:
|
||||||
# prof.cons_show(" {barejid}".format(barejid=item))
|
prof.cons_show(" {barejid}".format(barejid=contact))
|
||||||
|
|
||||||
# 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):
|
def _cmd_presence_notify(arg1=None, arg2=None, arg3=None):
|
||||||
if arg1 == "all":
|
if arg1 == "all":
|
||||||
prof.settings_set_string("presence_notify", "mode", "all")
|
prof.settings_set_string("presence_notify", "mode", "all")
|
||||||
prof.cons_show("Notifying on all presence changes")
|
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")
|
prof.cons_show("Presence notifications disabled")
|
||||||
return
|
return
|
||||||
|
|
||||||
# if arg1 == "all":
|
if arg1 == "ignored":
|
||||||
# if not arg2:
|
if arg2 == "clear":
|
||||||
# prof.cons_bad_cmd_usage("/presence_notify")
|
prof.settings_string_list_remove_all("presence_notify", "ignored")
|
||||||
# return
|
prof.cons_show("Removed all ignored contacts for presence notifications")
|
||||||
# prof.settings_string_list_add("presence_notify", "all", arg2)
|
return
|
||||||
# prof.settings_string_list_remove("presence_notify", "online", arg2)
|
|
||||||
# prof.cons_show("Enabled all presence notifications for {barejid}".format(barejid=arg2))
|
|
||||||
# return
|
|
||||||
|
|
||||||
# if arg1 == "online":
|
if arg2 == "add":
|
||||||
# if not arg2:
|
if not arg3:
|
||||||
# prof.cons_bad_cmd_usage("/presence_notify")
|
prof.cons_bad_cmd_usage("/presence_notify")
|
||||||
# return
|
return
|
||||||
# prof.settings_string_list_add("presence_notify", "online", arg2)
|
prof.settings_string_list_add("presence_notify", "ignored", arg3)
|
||||||
# prof.settings_string_list_remove("presence_notify", "all", arg2)
|
prof.cons_show("Added {contact} to ignored contacts for presence notifications".format(contact=arg3))
|
||||||
# prof.cons_show("Enabled online/offline presence notifications for {barejid}".format(barejid=arg2))
|
return
|
||||||
# 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()
|
_show_settings()
|
||||||
|
|
||||||
|
|
||||||
def prof_init(version, status, account_name, fulljid):
|
def prof_init(version, status, account_name, fulljid):
|
||||||
synopsis = [
|
synopsis = [
|
||||||
"/presence_notify all|online|off",
|
"/presence_notify all|online|off",
|
||||||
"/presence_notify all <barejid>",
|
"/presence_notify ignored add|remove|clear [<barejid>]"
|
||||||
"/presence_notify online <barejid>"
|
|
||||||
]
|
]
|
||||||
description = "Send a desktop notification on presence updates."
|
description = "Send a desktop notification on presence updates."
|
||||||
args = [
|
args = [
|
||||||
[ "all", "Enable all presence notifications" ],
|
[ "all", "Enable all presence notifications" ],
|
||||||
[ "online", "Enable only online/offline presence notifications" ],
|
[ "online", "Enable only online/offline presence notifications" ],
|
||||||
[ "off", "Disable presence notifications" ],
|
[ "off", "Disable presence notifications" ],
|
||||||
[ "all <barejid>", "Enable all presence notifications for contact <barejid>"],
|
[ "ignored add|remove <barejid>", "Add or remove a contact from the list excluded from presence notifications"],
|
||||||
[ "online <barejid>", "Enable only online/offline presence notifications for contact <barejid>"]
|
[ "ignored clear", "Clear the list of excluded contacts"]
|
||||||
]
|
]
|
||||||
examples = [
|
examples = [
|
||||||
"/presence_notify on",
|
"/presence_notify all",
|
||||||
"/presence_notify all bob@server.org"
|
"/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",
|
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):
|
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")
|
mode = prof.settings_get_string("presence_notify", "mode", "all")
|
||||||
if mode == "all":
|
if mode == "all":
|
||||||
return True
|
return True
|
||||||
@@ -93,16 +104,6 @@ def _do_notify(barejid, presence):
|
|||||||
else: # off
|
else: # off
|
||||||
return False
|
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):
|
def prof_on_contact_presence(barejid, resource, presence, status, priority):
|
||||||
if _do_notify(barejid, presence):
|
if _do_notify(barejid, presence):
|
||||||
|
|||||||
Reference in New Issue
Block a user