Switch from SleekXMPP to Slixmpp

This commit is contained in:
imShara 2019-05-07 16:22:59 +03:00
parent 5670c92519
commit 5b8f1b9648
1 changed files with 13 additions and 16 deletions

View File

@ -19,12 +19,11 @@ import configparser
import os.path import os.path
import sys import sys
import sleekxmpp import slixmpp
from sleekxmpp.thirdparty import GPG from slixmpp.thirdparty import GPG
from slixmpp.stanza import Message
from sleekxmpp.stanza import Message from slixmpp.xmlstream import register_stanza_plugin, ElementBase
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase
class PGPEncrypted(ElementBase): class PGPEncrypted(ElementBase):
name = 'x' name = 'x'
@ -43,10 +42,10 @@ class PGPEncrypted(ElementBase):
else: else:
del parent['encrypted'] del parent['encrypted']
class SendMsgBot(sleekxmpp.ClientXMPP): class SendMsgBot(slixmpp.ClientXMPP):
def __init__(self, jid, password, recipients, message, subject, force_pgp, attempt_pgp): def __init__(self, jid, password, recipients, message, subject, force_pgp, attempt_pgp):
sleekxmpp.ClientXMPP.__init__(self, jid, password) slixmpp.ClientXMPP.__init__(self, jid, password)
self.recipients = recipients self.recipients = recipients
self.msg = message self.msg = message
self.subject = subject self.subject = subject
@ -109,7 +108,7 @@ def FirstOf(*types, error='argument "{}" is not valid'):
return f return f
file_or_jid = FirstOf(argparse.FileType('r'), file_or_jid = FirstOf(argparse.FileType('r'),
sleekxmpp.basexmpp.JID, slixmpp.basexmpp.JID,
error='"{}" is neither a file nor a valid JID') error='"{}" is neither a file nor a valid JID')
if __name__ == '__main__': if __name__ == '__main__':
@ -154,18 +153,16 @@ if __name__ == '__main__':
r = [] r = []
for recipient in global_args.recipients: for recipient in global_args.recipients:
if isinstance(recipient, sleekxmpp.basexmpp.JID): if isinstance(recipient, slixmpp.basexmpp.JID):
r.append(recipient) r.append(recipient)
else: else:
r.extend(map(sleekxmpp.basexmpp.JID, filter(None, recipient.read().split('\n')))) r.extend(map(slixmpp.basexmpp.JID, filter(None, recipient.read().split('\n'))))
global_args.recipients = r global_args.recipients = r
jid = sleekxmpp.basexmpp.JID(jid_conf) jid = slixmpp.basexmpp.JID(jid_conf)
jid.resource = jid.resource or 'sendxmpp.py' jid.resource = jid.resource or 'sendxmpp.py'
xmpp = SendMsgBot(jid, pass_conf, global_args.recipients, msg, global_args.subject, global_args.force_pgp, global_args.attempt_pgp) xmpp = SendMsgBot(jid, pass_conf, global_args.recipients, msg, global_args.subject, global_args.force_pgp, global_args.attempt_pgp)
if xmpp.connect(): # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.process(block=True) xmpp.connect()
else: xmpp.process(forever=False)
print('Unable to connect.')
exit(1)