mirror of
https://github.com/gryf/weechat-highlightxmpp.git
synced 2026-02-08 14:25:45 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e78873a71 | ||
| 16f60ee26d | |||
|
|
6c7c37f0c3 | ||
|
|
4278e196c3 | ||
|
|
9dc1c1c01f | ||
|
|
ccdd39151c | ||
|
|
5ed160cdba |
13
README
13
README
@@ -2,7 +2,20 @@ When loaded, this plugin will send you a message over XMPP (Jabber) when a
|
|||||||
highlighted message or a private message is received. Great for running under
|
highlighted message or a private message is received. Great for running under
|
||||||
a detatched terminal where you're not always looking at your IRC window.
|
a detatched terminal where you're not always looking at your IRC window.
|
||||||
|
|
||||||
|
Requires SleekXMPP (`pip install sleekxmpp`)
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
* 0.6:
|
||||||
|
- switch from sleekxmpp to commandline utility sendxmpp
|
||||||
|
(https://github.com/lhost/sendxmpp) or go-sendxmpp
|
||||||
|
(https://salsa.debian.org/mdosch/go-sendxmpp).
|
||||||
|
|
||||||
|
* 0.5:
|
||||||
|
- switch to sleekxmpp as xmpp library (http://github.com/fritzy/SleekXMPP)
|
||||||
|
|
||||||
|
* 0.4:
|
||||||
|
- Actually fixed random XML appearing in messages.
|
||||||
|
|
||||||
* 0.3:
|
* 0.3:
|
||||||
- Fixed message type to 'chat'; should fix problems with offline send
|
- Fixed message type to 'chat'; should fix problems with offline send
|
||||||
and XML embedded in the message on some receivers
|
and XML embedded in the message on some receivers
|
||||||
|
|||||||
162
highlightxmpp.py
162
highlightxmpp.py
@@ -1,120 +1,96 @@
|
|||||||
# HighlightXMPP 0.3 for IRC. Requires WeeChat >= 0.3.0 and Python >= 2.6.
|
# HighlightXMPP 0.6 for IRC. Requires WeeChat >= 0.3.0,
|
||||||
|
# Python >= 2.6, and sendxmpp (https://github.com/lhost/sendxmpp) or
|
||||||
|
# equivalent.
|
||||||
# Repo: https://github.com/jpeddicord/weechat-highlightxmpp
|
# Repo: https://github.com/jpeddicord/weechat-highlightxmpp
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2011 Jacob Peddicord <jpeddicord@ubuntu.com>
|
# Copyright (c) 2009-2015 Jacob Peddicord <jacob@peddicord.net>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation; either version 3 of the License, or
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
#######
|
#######
|
||||||
#
|
#
|
||||||
# You must configure this plugin before using:
|
# You must configure sendxmpp before using this plugin, so you'll be able to
|
||||||
|
# send message from commandline using format:
|
||||||
#
|
#
|
||||||
# JID messages are sent from:
|
# echo "message" | sendxmpp someid@jabber.org
|
||||||
# /set plugins.var.python.highlightxmpp.jid someid@jabber.org
|
|
||||||
# alternatively, to use a specific resource:
|
|
||||||
# /set plugins.var.python.highlightxmpp.jid someid@jabber.org/resource
|
|
||||||
#
|
#
|
||||||
# Password for the above JID:
|
# also you will need to provide JID to send messages:
|
||||||
# /set plugins.var.python.highlightxmpp.password abcdef
|
|
||||||
#
|
#
|
||||||
# JID messages are sent *to* (if not set, defaults to the same jid as above):
|
# /set plugins.var.python.highlightxmpp.to myid@jabber.org
|
||||||
# /set plugins.var.python.highlightxmpp.to myid@jabber.org
|
#
|
||||||
|
# finally, you might want to change the sendxmpp binary to some other
|
||||||
|
# implementation (like https://salsa.debian.org/mdosch/go-sendxmpp) and/or
|
||||||
|
# provide some additional parameters, i.e.:
|
||||||
|
#
|
||||||
|
# /set plugins.var.python.highlightxmpp.command "/path/to/go-sendxmpp -t"
|
||||||
|
#
|
||||||
|
# You can set debug option to "on" if you experience issues regarding sending
|
||||||
|
# messages via sendxmpp:
|
||||||
|
#
|
||||||
|
# /set plugins.var.python.highlightxmpp.debug off
|
||||||
|
#
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from time import sleep
|
import weechat
|
||||||
import warnings
|
|
||||||
import weechat as w
|
|
||||||
|
|
||||||
# the XMPP module currently has a lot of deprecations
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
import xmpp
|
|
||||||
|
|
||||||
info = (
|
SETTINGS = {'command': 'sendxmpp',
|
||||||
'highlightxmpp',
|
'to': '',
|
||||||
'Jacob Peddicord <jpeddicord@ubuntu.com>',
|
'debug': 'off'}
|
||||||
'0.3',
|
INFO = ('highlightxmpp',
|
||||||
'GPL3',
|
'Jacob Peddicord <jacob@peddicord.net>',
|
||||||
"Relay highlighted & private IRC messages over XMPP (Jabber)",
|
'0.6',
|
||||||
'',
|
'GPL3',
|
||||||
''
|
"Relay highlighted & private IRC messages over XMPP (Jabber)",
|
||||||
)
|
'',
|
||||||
|
'')
|
||||||
|
|
||||||
settings = {
|
|
||||||
'jid': '',
|
|
||||||
'password': '',
|
|
||||||
'to': '',
|
|
||||||
}
|
|
||||||
|
|
||||||
client = None
|
def send_xmpp(data, signal, message):
|
||||||
|
"""Send XMPP message using external commandline tool."""
|
||||||
|
jid = weechat.config_get_plugin('to')
|
||||||
|
command = weechat.config_get_plugin('command').split(' ')
|
||||||
|
debug = weechat.config_get_plugin('debug') == 'on'
|
||||||
|
|
||||||
def connect_xmpp():
|
if not jid:
|
||||||
global client
|
weechat.prnt('', 'You need to provide destination JID to use this '
|
||||||
# connected if not connected
|
'plugin.')
|
||||||
# & if we were disconnected, try to connect again
|
return weechat.WEECHAT_RC_OK
|
||||||
if client and client.isConnected():
|
|
||||||
return True
|
command.append(jid)
|
||||||
w.prnt('', "XMPP: Connecting")
|
|
||||||
jid_name = w.config_get_plugin('jid')
|
pipe = subprocess.Popen(command, stdin=subprocess.PIPE,
|
||||||
password = w.config_get_plugin('password')
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
try:
|
try:
|
||||||
jid = xmpp.protocol.JID(jid_name)
|
message = message.encode()
|
||||||
client = xmpp.Client(jid.getDomain(), debug=[])
|
except UnicodeDecodeError:
|
||||||
client.connect()
|
pass
|
||||||
client.auth(jid.getNode(), password)
|
|
||||||
except:
|
|
||||||
w.prnt('', "XMPP: Could not connect or authenticate to server.")
|
|
||||||
client = None
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def send_xmpp(data, signal, msg, trial=1):
|
_, stderr = pipe.communicate(input=message)
|
||||||
global client
|
if pipe.returncode != 0 and debug:
|
||||||
|
|
||||||
# ignore XMPP's deprecation warnings
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
|
|
||||||
# connect to xmpp if we need to
|
|
||||||
if not connect_xmpp():
|
|
||||||
return w.WEECHAT_RC_OK
|
|
||||||
jid_to = w.config_get_plugin('to')
|
|
||||||
|
|
||||||
# send to self if no target set
|
|
||||||
if not jid_to:
|
|
||||||
jid_to = w.config_get_plugin('jid')
|
|
||||||
|
|
||||||
# send the message
|
|
||||||
msg = xmpp.protocol.Message(jid_to, msg, typ='chat')
|
|
||||||
try:
|
try:
|
||||||
client.send(msg)
|
stderr = stderr.decode()
|
||||||
except IOError:
|
except UnicodeDecodeError:
|
||||||
# every now and then the connection will still exist but a send will
|
pass
|
||||||
# fail. catch that here and try to reconnect. isConnected() should
|
weechat.prnt('', 'Error sending message to %s:\n%s' % (jid, stderr))
|
||||||
# start to realize that once this exception is triggered.
|
return weechat.WEECHAT_RC_OK
|
||||||
if trial > 3:
|
|
||||||
w.prnt('', "XMPP: Could not send to server.")
|
|
||||||
else:
|
|
||||||
sleep(0.5)
|
|
||||||
send_xmpp(data, signal, msg, trial + 1)
|
|
||||||
return w.WEECHAT_RC_OK
|
|
||||||
|
|
||||||
# register with weechat
|
|
||||||
if w.register(*info):
|
if weechat.register(*INFO):
|
||||||
# add our settings
|
for setting in SETTINGS:
|
||||||
for setting in settings:
|
if not weechat.config_is_set_plugin(setting):
|
||||||
if not w.config_is_set_plugin(setting):
|
weechat.config_set_plugin(setting, SETTINGS[setting])
|
||||||
w.config_set_plugin(setting, settings[setting])
|
|
||||||
# and finally our hooks
|
weechat.hook_signal('weechat_highlight', 'send_xmpp', '')
|
||||||
w.hook_signal('weechat_highlight', 'send_xmpp', '')
|
weechat.hook_signal('weechat_pv', 'send_xmpp', '')
|
||||||
w.hook_signal('weechat_pv', 'send_xmpp', '')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user