Gotify
This commit is contained in:
parent
b9dbbf314f
commit
17674bb7fc
32
README.md
32
README.md
@ -1,29 +1,20 @@
|
|||||||
# weechat-pushjet
|
# weechat-gotify
|
||||||
|
|
||||||
A [WeeChat](https://weechat.org/) plugin that sends highlights and/or private message notifications through [Pushjet](https://pushjet.io/).
|
A [WeeChat](https://weechat.org/) plugin that sends highlights and/or private message notifications through [Gotify](https://github.com/gotify/).
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
In WeeChat install the script by typing the following:
|
|
||||||
```
|
|
||||||
/script install pushjet.py
|
|
||||||
```
|
|
||||||
|
|
||||||
If you're using the public push server, all you have to do is set the _`secret`_ option in the configuration.
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
The plugin allows you to set a few options through the normal WeeChat settings system.
|
The plugin allows you to set a few options through the normal WeeChat settings system.
|
||||||
You'll find all of them under _`plugins.var.python.pushjet`_, and all of them have helpful descriptions.
|
You'll find all of them under _`plugins.var.python.gotify`_, and all of them have helpful descriptions.
|
||||||
|
|
||||||
To set them use _`/set plugins.var.python.pushjet.foo bar`_ or through the [iset.pl](https://weechat.org/scripts/source/iset.pl.html) plugin.
|
To set them use _`/set plugins.var.python.gotify.foo bar`_ or through the [iset.pl](https://weechat.org/scripts/source/iset.pl.html) plugin.
|
||||||
|
|
||||||
- `host`
|
- `host`
|
||||||
- host for the pushjet api (default: "https://api.pushjet.io")
|
- host for the gotify api (default: "")
|
||||||
- `secret`
|
- `token`
|
||||||
- secret for the pushjet api (default: "")
|
- app token for the gotify api (default: "")
|
||||||
- `level`
|
- `priority`
|
||||||
- severity level for the message, from 1 to 5 (low to high) (default: 4)
|
- 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 (>= 1) (default: 30)
|
||||||
- `separator`
|
- `separator`
|
||||||
@ -39,8 +30,3 @@ To set them use _`/set plugins.var.python.pushjet.foo bar`_ or through the [iset
|
|||||||
- `ignore_nicks`
|
- `ignore_nicks`
|
||||||
- comma-separated list of users to not push notifications from (default: "")
|
- comma-separated list of users to not push notifications from (default: "")
|
||||||
|
|
||||||
### Issues
|
|
||||||
|
|
||||||
- The currently available version of Pushjet is sending the wrong error codes for errors.
|
|
||||||
This means that if your settings are invalid it's very hard to find out exactly what is wrong.
|
|
||||||
- Away status can't be checked when receiving private messages
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# https://github.com/p3lim/weechat-pushjet
|
# https://github.com/flocke/weechat-gotify
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import weechat
|
import weechat
|
||||||
@ -10,26 +10,24 @@ except ImportError:
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
import requests
|
||||||
|
|
||||||
SCRIPT_NAME = 'pushjet'
|
SCRIPT_NAME = 'gotify'
|
||||||
SCRIPT_AUTHOR = 'p3lim'
|
SCRIPT_AUTHOR = 'flocke'
|
||||||
SCRIPT_VERSION = '0.1.1'
|
SCRIPT_VERSION = '0.1.0'
|
||||||
SCRIPT_LICENSE = 'MIT'
|
SCRIPT_LICENSE = 'MIT'
|
||||||
SCRIPT_DESC = 'Send highlights and mentions through Pushjet.io'
|
SCRIPT_DESC = 'Send highlights and mentions through Gotify'
|
||||||
|
|
||||||
SETTINGS = {
|
SETTINGS = {
|
||||||
'host': (
|
'host': (
|
||||||
'https://api.pushjet.io',
|
|
||||||
'host for the pushjet api'),
|
|
||||||
'secret': (
|
|
||||||
'',
|
'',
|
||||||
'secret for the pushjet api'),
|
'host for the gotify api'),
|
||||||
'level': (
|
'token': (
|
||||||
'4',
|
'',
|
||||||
'severity level for the message, from 1 to 5 (low to high)'),
|
'app token for the gotify api'),
|
||||||
'timeout': (
|
'priority': (
|
||||||
'30',
|
'2',
|
||||||
'timeout for the message sending in seconds (>= 1)'),
|
'priority of the message'),
|
||||||
'separator': (
|
'separator': (
|
||||||
': ',
|
': ',
|
||||||
'separator between nick and message in notifications'),
|
'separator between nick and message in notifications'),
|
||||||
@ -51,31 +49,17 @@ SETTINGS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def send_message(title, message):
|
def send_message(title, message):
|
||||||
secret = weechat.config_get_plugin('secret')
|
token = weechat.config_get_plugin('token')
|
||||||
if secret != '':
|
if token != '':
|
||||||
|
host = weechat.config_get_plugin('host').rstrip('/') + '/message?token=' + token
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'secret': secret,
|
"message": message,
|
||||||
'level': int(weechat.config_get_plugin('level')),
|
"title": title,
|
||||||
'title': title,
|
"priority": int(weechat.config_get_plugin('priority'))
|
||||||
'message': message,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
host = weechat.config_get_plugin('host').rstrip('/') + '/message'
|
resp = requests.post(host, json=data)
|
||||||
timeout = int(weechat.config_get_plugin('timeout')) * 1000
|
|
||||||
|
|
||||||
if timeout <= 0:
|
|
||||||
timeout = 1
|
|
||||||
|
|
||||||
data = urlencode(data)
|
|
||||||
cmd = 'python2 -c \'from urllib2 import Request, urlopen; r = urlopen(Request("%s", "%s")); print r.getcode()\'' % (host, data)
|
|
||||||
weechat.hook_process(cmd, timeout, 'send_message_callback', '')
|
|
||||||
|
|
||||||
def send_message_callback(data, command, return_code, out, err):
|
|
||||||
if return_code != 0:
|
|
||||||
# something went wrong
|
|
||||||
return weechat.WEECHAT_RC_ERROR
|
|
||||||
|
|
||||||
return weechat.WEECHAT_RC_OK
|
|
||||||
|
|
||||||
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