From 409c38393774bf9303e830e0862af6a5d387ade6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Sep 2016 23:36:26 +0100 Subject: [PATCH] sounds.py allow for certain rooms --- sounds.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/sounds.py b/sounds.py index 9d7c7cc..8694a34 100644 --- a/sounds.py +++ b/sounds.py @@ -21,10 +21,12 @@ def _play_sound(soundfile): def _cmd_sounds(arg1=None, arg2=None, arg3=None): if not arg1: + prof.cons_show("") enabled = prof.settings_boolean_get("sounds", "enabled", False) chatsound = prof.settings_string_get("sounds", "chat", None) roomsound = prof.settings_string_get("sounds", "room", None) privatesound = prof.settings_string_get("sounds", "private", None) + roomlist = prof.settings_string_list_get("sounds", "rooms") if chatsound or roomsound or privatesound: if enabled: prof.cons_show("Sounds: ON") @@ -34,8 +36,14 @@ def _cmd_sounds(arg1=None, arg2=None, arg3=None): prof.cons_show(" Chat : " + chatsound) if roomsound: prof.cons_show(" Room : " + roomsound) + if roomlist and len(roomlist) > 0: + for room in roomlist: + prof.cons_show(" " + room) + else: + prof.cons_show(" All rooms") if privatesound: prof.cons_show(" Private : " + privatesound) + else: prof.cons_show("No sounds set.") @@ -81,6 +89,31 @@ def _cmd_sounds(arg1=None, arg2=None, arg3=None): return + if arg1 == "rooms": + if arg2 == "add": + if not arg3: + prof.cons_bad_cmd_usage("/sounds") + else: + prof.settings_string_list_add("sounds", "rooms", arg3) + prof.cons_show("Sounds enabled for room: " + arg3) + elif arg2 == "remove": + if not arg3: + prof.cons_bad_cmd_usage("/sounds") + else: + prof.settings_string_list_remove("sounds", "rooms", arg3) + roomlist = prof.settings_string_list_get("sounds", "rooms") + if roomlist and len(roomlist) > 0: + prof.cons_show("Sounds disabled for room: " + arg3) + else: + prof.cons_show("Empty room list for sounds, playing in all rooms.") + elif arg2 == "clear": + prof.settings_string_list_clear("sounds", "rooms") + prof.cons_show("Cleared sounds room list, playing in all rooms.") + else: + prof.cons_bad_cmd_usage("/sounds") + + return + prof.cons_bad_cmd_usage("/sounds") @@ -93,7 +126,8 @@ def prof_init(version, status, account_name, fulljid): "/sounds set private ", "/sounds clear chat", "/sounds clear room", - "/sounds clear private" + "/sounds clear private", + "/sounds rooms add " ] description = "Play mp3 sounds on various Profanity events. Calling with no args shows current sound files." args = [ @@ -103,21 +137,26 @@ def prof_init(version, status, account_name, fulljid): [ "set private ", "Path to mp3 file to play on private room messages." ], [ "clear chat", "Remove the sound for chat messages." ], [ "clear room", "Remove the sound for room messages." ], - [ "clear private", "Remove the sound for private messages." ] + [ "clear private", "Remove the sound for private messages." ], + [ "rooms add ", "Add the room to the list that will play the room sound."], + [ "rooms remove ", "Remove the room from the list that will play the room sound."], + [ "rooms clear", "Clear the room list, all rooms will play sounds on new messages."] ] examples = [ "/sounds set chat ~/sounds/woof.mp3", "/sounds set room ~/sounds/meow.mp3", "/sounds set private ~/sounds/shhh.mp3", "/sounds remove private", - "/sounds on", + "/sounds rooms add myroom@conference.server.org", + "/sounds on" ] prof.register_command("/sounds", 0, 3, synopsis, description, args, examples, _cmd_sounds) - prof.completer_add("/sounds", [ "set", "clear", "on", "off" ]) + prof.completer_add("/sounds", [ "set", "clear", "on", "off", "rooms" ]) prof.completer_add("/sounds set", [ "chat", "room", "private" ]) prof.completer_add("/sounds clear", [ "chat", "room", "private" ]) + prof.completer_add("/sounds rooms", [ "add", "remove", "clear" ]) def prof_post_chat_message_display(barejid, resource, message): @@ -126,8 +165,10 @@ def prof_post_chat_message_display(barejid, resource, message): return soundfile = prof.settings_string_get("sounds", "chat", None) - if soundfile: - _play_sound(soundfile) + if not soundfile: + return + + _play_sound(soundfile) def prof_post_room_message_display(barejid, nick, message): @@ -136,8 +177,14 @@ def prof_post_room_message_display(barejid, nick, message): return soundfile = prof.settings_string_get("sounds", "room", None) - if soundfile: - _play_sound(soundfile) + if not soundfile: + return + + roomlist = prof.settings_string_list_get("sounds", "rooms") + if roomlist and (barejid not in roomlist): + return + + _play_sound(soundfile) def prof_post_priv_message_display(barejid, nick, message):