From 16e6d7257a2f726c1691a10e994b2c0acafa46fe Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Sep 2016 21:58:38 +0100 Subject: [PATCH] Add on|off setting to sounds.py --- sounds.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/sounds.py b/sounds.py index 8c3c211..9d7c7cc 100644 --- a/sounds.py +++ b/sounds.py @@ -21,12 +21,15 @@ def _play_sound(soundfile): def _cmd_sounds(arg1=None, arg2=None, arg3=None): if not arg1: + 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) - if chatsound or roomsound or privatesound: - prof.cons_show("Sounds:") + if enabled: + prof.cons_show("Sounds: ON") + else: + prof.cons_show("Sounds: OFF") if chatsound: prof.cons_show(" Chat : " + chatsound) if roomsound: @@ -38,6 +41,16 @@ def _cmd_sounds(arg1=None, arg2=None, arg3=None): return + if arg1 == "on": + prof.settings_boolean_set("sounds", "enabled", True) + prof.cons_show("Sounds enabled") + return + + if arg1 == "off": + prof.settings_boolean_set("sounds", "enabled", False) + prof.cons_show("Sounds disabled") + return + if arg1 == "set": if arg2 == "chat": prof.settings_string_set("sounds", "chat", arg3) @@ -74,6 +87,7 @@ def _cmd_sounds(arg1=None, arg2=None, arg3=None): def prof_init(version, status, account_name, fulljid): synopsis = [ "/sounds", + "/sounds on|off", "/sounds set chat ", "/sounds set room ", "/sounds set private ", @@ -83,6 +97,7 @@ def prof_init(version, status, account_name, fulljid): ] description = "Play mp3 sounds on various Profanity events. Calling with no args shows current sound files." args = [ + [ "on|off", "Enable or disable playing sounds." ], [ "set chat ", "Path to mp3 file to play on chat messages." ], [ "set room ", "Path to mp3 file to play on room messages." ], [ "set private ", "Path to mp3 file to play on private room messages." ], @@ -94,29 +109,42 @@ def prof_init(version, status, account_name, fulljid): "/sounds set chat ~/sounds/woof.mp3", "/sounds set room ~/sounds/meow.mp3", "/sounds set private ~/sounds/shhh.mp3", - "/sounds remove private" + "/sounds remove private", + "/sounds on", ] prof.register_command("/sounds", 0, 3, synopsis, description, args, examples, _cmd_sounds) - prof.completer_add("/sounds", [ "set", "clear" ]) + prof.completer_add("/sounds", [ "set", "clear", "on", "off" ]) prof.completer_add("/sounds set", [ "chat", "room", "private" ]) prof.completer_add("/sounds clear", [ "chat", "room", "private" ]) def prof_post_chat_message_display(barejid, resource, message): + enabled = prof.settings_boolean_get("sounds", "enabled", False) + if not enabled: + return + soundfile = prof.settings_string_get("sounds", "chat", None) if soundfile: _play_sound(soundfile) def prof_post_room_message_display(barejid, nick, message): + enabled = prof.settings_boolean_get("sounds", "enabled", False) + if not enabled: + return + soundfile = prof.settings_string_get("sounds", "room", None) if soundfile: _play_sound(soundfile) def prof_post_priv_message_display(barejid, nick, message): + enabled = prof.settings_boolean_get("sounds", "enabled", False) + if not enabled: + return + soundfile = prof.settings_string_get("sounds", "private", None) if soundfile: _play_sound(soundfile)