Send multiline XMPP msgs as multiple msgs in IRC

This commit is contained in:
Alexei Sorokin 2016-07-29 17:23:40 +03:00
parent 3d22bbe87d
commit 7da0839dc0

View File

@ -105,10 +105,11 @@ class XMPPBot(sleekxmpp.ClientXMPP):
fromjid = event['from'].bare fromjid = event['from'].bare
nick = event['mucnick'] nick = event['mucnick']
text = text.replace('\r', '').replace('\n', '') if text:
text = text.replace('\r\n', '\n').replace('\r', '\n').split('\n')
if text and nick != m_nick: if text and len(text) > 0 and nick != m_nick:
if text == '.users': if len(text) == 1 and text[0] == '.users':
users = self.chanmuc.chan_users() users = self.chanmuc.chan_users()
users = ', '.join(users) users = ', '.join(users)
@ -118,7 +119,7 @@ class XMPPBot(sleekxmpp.ClientXMPP):
self.jabber.send_message(mto=muc, mbody=users, self.jabber.send_message(mto=muc, mbody=users,
mtype='groupchat') mtype='groupchat')
elif text == '.help': elif len(text) == 1 and text[0] == '.help':
message = 'The only command I have is \'.users\''+ \ message = 'The only command I have is \'.users\''+ \
'. Also, my owner is ' + owner + '.' '. Also, my owner is ' + owner + '.'
@ -126,11 +127,16 @@ class XMPPBot(sleekxmpp.ClientXMPP):
mtype='groupchat') mtype='groupchat')
else: else:
text = '[' + nick + '] ' + text for i in range(0, len(text)):
m = '[' + nick + '] ' + text[i]
# Slow down a bit.
if i > 0:
time.sleep(0.5)
buffer = 460 buffer = 460
for i in range(0, len(text), buffer): for j in range(0, len(m), buffer):
inter.irc(text[i:i + buffer]) inter.irc(m[j:j + buffer])
except Exception as e: except Exception as e:
print(e) print(e)