Relay highlighted and private messages over XMPP (Jabber).
Author: jpeddicord
— Version: 0.5
— License: GPL-3.0-or-later
For WeeChat ≥ 0.3.0, requires: sleekxmpp.
Tags: notify, py2
Added: 2009-09-16
— Updated: 2015-12-31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | # HighlightXMPP 0.5 for IRC. Requires WeeChat >= 0.3.0, # Python >= 2.6, and sleekxmpp. # Repo: https://github.com/jpeddicord/weechat-highlightxmpp # # Copyright (c) 2009-2015 Jacob Peddicord <jacob@peddicord.net> # # 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 # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ####### # # You must configure this plugin before using: # # JID messages are sent from: # /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: # /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 import sys import weechat as w import sleekxmpp if sys.version_info < (3, 0): from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding('utf8') info = ( 'highlightxmpp', 'Jacob Peddicord <jacob@peddicord.net>', '0.5', 'GPL3', "Relay highlighted & private IRC messages over XMPP (Jabber)", '', '' ) settings = { 'jid': '', 'password': '', 'to': '', } 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 send_xmpp(data, signal, message, trial=1): jid = w.config_get_plugin('jid') jid_to = w.config_get_plugin('to') if not jid_to: jid_to = jid password = w.config_get_plugin('password') xmpp = SendMsgBot(jid, password, jid_to, message) if not xmpp.connect(): w.prnt('', "Unable to connect to XMPP server.") return w.WEECHAT_RC_OK xmpp.process(block=True) return w.WEECHAT_RC_OK # register with weechat if w.register(*info): # add our settings for setting in settings: if not w.config_is_set_plugin(setting): w.config_set_plugin(setting, settings[setting]) # and finally our hooks w.hook_signal('weechat_highlight', 'send_xmpp', '') w.hook_signal('weechat_pv', 'send_xmpp', '') |