Jid checking

This commit is contained in:
Abhorrent_Anger 2019-10-29 23:41:06 +02:00
parent dab9493d9c
commit 27db038ca6
2 changed files with 45 additions and 29 deletions

View File

@ -1,5 +1,7 @@
# Profanity LED notification # Profanity 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. 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).
Emulates "/tray on" "/tray read off" behaviour.
## Install: ## Install:
As with other Profanity plugins, simply clone the repository and run: As with other Profanity plugins, simply clone the repository and run:
``` ```

View File

@ -1,66 +1,80 @@
import subprocess import subprocess
from time import sleep from time import sleep
import prof import prof
focused = False led_thread = None
last_window_jid = None
unfocused_jid = {}
def call_command(state_on=True): def call_command(state_on=True):
if state_on: if state_on:
command = prof.settings_string_get("lednotification", "command_on", "xset led 3") command = prof.settings_string_get("lednotification", "command_on", "xset led 3")
else: else:
command = prof.settings_string_get("lednotification", "command_off", "xset -led 3") command = prof.settings_string_get("lednotification", "command_off", "xset -led 3")
subprocess.call(command) subprocess.call(command, shell=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(): def led_notify():
global focused
focused = False
blink = prof.settings_string_get("lednotification", "blink", "off")
if blink != "off":
sleep_interval = 0.5 if blink == "on" else blink
while not focused:
enable_led(True)
sleep(sleep_interval)
enable_led(False)
else:
enable_led(True) enable_led(True)
def prof_on_chat_win_focus(): def prof_on_chat_win_focus(barejid):
on_focus() on_focus(barejid)
return None
def prof_on_room_win_focus(): def prof_on_room_win_focus(barejid):
rooms = prof.settings_string_get("lednotification", "rooms", "off") rooms = prof.settings_string_get("lednotification", "rooms", "off")
if rooms == "on": if rooms == "on":
on_focus() on_focus(barejid)
return None
def on_focus(): def on_focus(jid):
global focused global focused
global last_window_jid
global unfocused_jid
prof.cons_show("!!!" + unfocused_jid + " ; " + bool(unfocused_jid))
focused = True focused = True
last_window_jid = jid
unfocused_jid.pop(jid, None)
if led_thread:
led_thread.join()
led_thread = None
if not unfocused_jid:
enable_led(False) enable_led(False)
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") prof.cons_show('test1234')
if enabled == "on": prof.cons_show("##!!!" + unfocused_jid + " ; " + bool(unfocused_jid))
if check_chat_notify(barejid):
led_notify() 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") if check_chat_notify(barejid) and check_room_notify(barejid, nick):
rooms = prof.settings_string_get("lednotification", "rooms", "off")
user = prof.get_room_nick(barejid)
if enabled == "on" and rooms == "on" and user != nick:
led_notify() 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") if check_chat_notify(barejid):
if enabled == "on":
led_notify() led_notify()
return message return message
def check_chat_notify(barejid):
global unfocused_jid
is_console = prof.current_win_is_console()
if last_window_jid != barejid or is_console:
unfocused_jid[barejid] = True
prof.cons_show("CCC##!!!" + unfocused_jid + " ; " + bool(unfocused_jid))
enabled = prof.settings_string_get("lednotification", "enabled", "on")
return enabled == "on" and is_console
def check_room_notify(barejid, nick):
rooms = prof.settings_string_get("lednotification", "rooms", "off")
user = prof.get_room_nick(barejid)
return rooms == "on" and user != nick
def _cmd_say(arg1=None, arg2=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")