Custom command parsing fix

This commit is contained in:
Abhorrent_Anger 2019-10-29 16:16:13 +02:00
parent ab380cd297
commit dab9493d9c
2 changed files with 19 additions and 10 deletions

View File

@ -1,7 +1,11 @@
# Profanity LED notification # Profanity LED notification
Sends new message notifications to a predefined LED. Inspired by a similar [Pidgin plugin](https://sites.google.com/site/simohmattila/led-notification). Sends new message notifications to a predefined LED by running an user-set command. Inspired by a similar [Pidgin plugin](https://sites.google.com/site/simohmattila/led-notification). LED turns off once the chat or room window receives focus.
## Install: ## Install:
As with other Profanity plugins, simply clone the repository and run: As with other Profanity plugins, simply clone the repository and run:
``` ```
/plugins install ~/profanity-led-notification/lednotification.py /plugins install ~/profanity-led-notification/lednotification.py
``` ```
For further configuration check:
```
/help lednotification
```

View File

@ -15,7 +15,7 @@ def call_command(state_on=True):
def enable_led(state_on=True): # Can be expanded for different ways to call LED changes def enable_led(state_on=True): # Can be expanded for different ways to call LED changes
call_command(state_on) call_command(state_on)
def led_notify(sender): def led_notify():
global focused global focused
focused = False focused = False
blink = prof.settings_string_get("lednotification", "blink", "off") blink = prof.settings_string_get("lednotification", "blink", "off")
@ -44,23 +44,24 @@ def on_focus():
def prof_post_chat_message_display(barejid, resource, message): def prof_post_chat_message_display(barejid, resource, message):
enabled = prof.settings_string_get("lednotification", "enabled", "on") enabled = prof.settings_string_get("lednotification", "enabled", "on")
if enabled == "on": if enabled == "on":
led_notify(barejid) led_notify()
return message return message
def prof_post_room_message_display(barejid, nick, message): def prof_post_room_message_display(barejid, nick, message):
enabled = prof.settings_string_get("lednotification", "enabled", "on") enabled = prof.settings_string_get("lednotification", "enabled", "on")
rooms = prof.settings_string_get("lednotification", "rooms", "off") rooms = prof.settings_string_get("lednotification", "rooms", "off")
if enabled == "on" and rooms == "on": user = prof.get_room_nick(barejid)
led_notify(barejid) if enabled == "on" and rooms == "on" and user != nick:
led_notify()
return message return message
def prof_post_priv_message_display(barejid, nick, message): def prof_post_priv_message_display(barejid, nick, message):
enabled = prof.settings_string_get("lednotification", "enabled", "on") enabled = prof.settings_string_get("lednotification", "enabled", "on")
if enabled == "on": if enabled == "on":
led_notify(barejid) led_notify()
return message return message
def _cmd_say(arg1=None, arg2=None, arg3=None): def _cmd_say(arg1=None, arg2=None):
if arg1 == "on": if arg1 == "on":
prof.settings_string_set("lednotification", "enabled", "on") prof.settings_string_set("lednotification", "enabled", "on")
prof.cons_show("LED notifications enabled") prof.cons_show("LED notifications enabled")
@ -68,6 +69,10 @@ def _cmd_say(arg1=None, arg2=None, arg3=None):
prof.settings_string_set("lednotification", "enabled", "off") prof.settings_string_set("lednotification", "enabled", "off")
prof.cons_show("LED notifications disabled") prof.cons_show("LED notifications disabled")
elif arg1 == "command": elif arg1 == "command":
split = arg2.split()
mode = split[0]
arg3 = arg2.replace(mode, '', 1)[1:]
arg2 = mode
if arg2 == None or arg3 == None: if arg2 == None or arg3 == None:
prof.cons_bad_cmd_usage("/lednotification") prof.cons_bad_cmd_usage("/lednotification")
elif arg2 == "on": elif arg2 == "on":
@ -104,8 +109,8 @@ def _cmd_say(arg1=None, arg2=None, arg3=None):
def prof_init(version, status, account_name, fulljid): def prof_init(version, status, account_name, fulljid):
synopsis = [ synopsis = [
"/lednotification on|off", "/lednotification on|off",
"/lednotification command on 'command'", "/lednotification command on command",
"/lednotification command off 'command'", "/lednotification command off command",
"/lednotification blink on|off|interval", "/lednotification blink on|off|interval",
"/lednotification rooms on|off"] "/lednotification rooms on|off"]
description = "Show new notifications with LEDs" description = "Show new notifications with LEDs"
@ -117,7 +122,7 @@ def prof_init(version, status, account_name, fulljid):
["rooms <args>", "Turn notifications for rooms on or off"]] ["rooms <args>", "Turn notifications for rooms on or off"]]
examples = [ examples = [
"/lednotification on", "/lednotification on",
"/lednotification command on 'xset led 3'", "/lednotification command on xset led 3",
"/lednotification rooms off", "/lednotification rooms off",
"/lednotification blink on", "/lednotification blink on",
"/lednotification blink 0.5"] "/lednotification blink 0.5"]