Re-introduce timeouts
This commit is contained in:
parent
17674bb7fc
commit
8e9811e87e
@ -16,7 +16,7 @@ To set them use _`/set plugins.var.python.gotify.foo bar`_ or through the [iset.
|
|||||||
- `priority`
|
- `priority`
|
||||||
- priority of the message (default: 2)
|
- priority of the message (default: 2)
|
||||||
- `timeout`
|
- `timeout`
|
||||||
- timeout for the message sending in seconds (>= 1) (default: 30)
|
- timeout for the message sending in seconds (default: 5)
|
||||||
- `separator`
|
- `separator`
|
||||||
- separator between nick and message in notifications (default: ": ")
|
- separator between nick and message in notifications (default: ": ")
|
||||||
- `notify_on_highlight`
|
- `notify_on_highlight`
|
||||||
|
19
gotify.py
19
gotify.py
@ -31,6 +31,9 @@ SETTINGS = {
|
|||||||
'separator': (
|
'separator': (
|
||||||
': ',
|
': ',
|
||||||
'separator between nick and message in notifications'),
|
'separator between nick and message in notifications'),
|
||||||
|
'timeout': (
|
||||||
|
'5',
|
||||||
|
'timeout for the message sending in seconds'),
|
||||||
'notify_on_highlight': (
|
'notify_on_highlight': (
|
||||||
'on',
|
'on',
|
||||||
'push notifications for highlights in buffers (on/off)'),
|
'push notifications for highlights in buffers (on/off)'),
|
||||||
@ -50,16 +53,24 @@ SETTINGS = {
|
|||||||
|
|
||||||
def send_message(title, message):
|
def send_message(title, message):
|
||||||
token = weechat.config_get_plugin('token')
|
token = weechat.config_get_plugin('token')
|
||||||
if token != '':
|
host = weechat.config_get_plugin('host')
|
||||||
host = weechat.config_get_plugin('host').rstrip('/') + '/message?token=' + token
|
|
||||||
|
if token != '' and host != '':
|
||||||
|
timeout = float(weechat.config_get_plugin('timeout'))
|
||||||
|
priority = int(weechat.config_get_plugin('priority'))
|
||||||
|
|
||||||
|
api = host.rstrip('/') + '/message?token=' + token
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"message": message,
|
"message": message,
|
||||||
"title": title,
|
"title": title,
|
||||||
"priority": int(weechat.config_get_plugin('priority'))
|
"priority": priority
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(host, json=data)
|
try:
|
||||||
|
resp = requests.post(api, json=data, timeout=timeout)
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
weechat.prnt("", "{0:s}failed to send notification, the request to the Gotify API timed out".format(weechat.prefix("error")))
|
||||||
|
|
||||||
def get_sender(tags, prefix):
|
def get_sender(tags, prefix):
|
||||||
# attempt to find sender from tags
|
# attempt to find sender from tags
|
||||||
|
Loading…
Reference in New Issue
Block a user