Compare commits

5 Commits

Author SHA1 Message Date
Jacob Peddicord
6c7c37f0c3 Update headers and add sleekxmpp note. 2015-10-18 14:08:59 -07:00
Jacob Peddicord
4278e196c3 Merge pull request #2 from Mic92/master
switch to better maintained sleekxmpp
2015-10-18 13:35:13 -07:00
Jörg Thalheim
9dc1c1c01f switch to better maintained sleekxmpp 2015-10-11 08:43:02 +02:00
Jacob Peddicord
ccdd39151c Bump version 2012-03-25 11:10:20 -04:00
Jacob Peddicord
5ed160cdba Actually fix XML appearing in message.
This would happen on first send and after reconnecing.
I was re-using msg accidentally, and the XML was being re-packed.
2012-03-25 11:05:27 -04:00
2 changed files with 44 additions and 58 deletions

8
README
View File

@@ -2,7 +2,15 @@ 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.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

View File

@@ -1,7 +1,8 @@
# HighlightXMPP 0.3 for IRC. Requires WeeChat >= 0.3.0 and Python >= 2.6. # HighlightXMPP 0.5 for IRC. Requires WeeChat >= 0.3.0,
# Python >= 2.6, and sleekxmpp.
# 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
@@ -31,19 +32,18 @@
# JID messages are sent *to* (if not set, defaults to the same jid as above): # 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
from time import sleep import sys
import warnings
import weechat as w import weechat as w
import sleekxmpp
# the XMPP module currently has a lot of deprecations if sys.version_info < (3, 0):
with warnings.catch_warnings(): from sleekxmpp.util.misc_ops import setdefaultencoding
warnings.simplefilter("ignore") setdefaultencoding('utf8')
import xmpp
info = ( info = (
'highlightxmpp', 'highlightxmpp',
'Jacob Peddicord <jpeddicord@ubuntu.com>', 'Jacob Peddicord <jacob@peddicord.net>',
'0.3', '0.5',
'GPL3', 'GPL3',
"Relay highlighted & private IRC messages over XMPP (Jabber)", "Relay highlighted & private IRC messages over XMPP (Jabber)",
'', '',
@@ -56,58 +56,36 @@ settings = {
'to': '', 'to': '',
} }
client = None class SendMsgBot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, recipient, message):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.jid = jid
self.recipient = recipient
self.msg = message
self.add_event_handler("session_start", self.start, threaded=True)
def start(self, event):
self.send_presence()
self.get_roster()
self.send_message(mto=self.recipient,
mbody=self.msg,
mtype='chat')
self.disconnect(wait=True)
def connect_xmpp():
global client def send_xmpp(data, signal, message, trial=1):
# connected if not connected jid = w.config_get_plugin('jid')
# & if we were disconnected, try to connect again jid_to = w.config_get_plugin('to')
if client and client.isConnected(): if not jid_to:
return True jid_to = jid
w.prnt('', "XMPP: Connecting")
jid_name = w.config_get_plugin('jid')
password = w.config_get_plugin('password') password = w.config_get_plugin('password')
try:
jid = xmpp.protocol.JID(jid_name)
client = xmpp.Client(jid.getDomain(), debug=[])
client.connect()
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): xmpp = SendMsgBot(jid, password, jid_to, message)
global client if not xmpp.connect():
w.prnt('', "Unable to connect to XMPP server.")
# 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:
client.send(msg)
except IOError:
# every now and then the connection will still exist but a send will
# fail. catch that here and try to reconnect. isConnected() should
# start to realize that once this exception is triggered.
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 return w.WEECHAT_RC_OK
xmpp.process(block=True)
return w.WEECHAT_RC_OK
# register with weechat # register with weechat
if w.register(*info): if w.register(*info):