Disable MUC history and remove lines ignore

This commit is contained in:
Alexei Sorokin 2016-07-28 18:57:34 +03:00
parent 0c69f961c3
commit 002fd865c4
2 changed files with 30 additions and 34 deletions

View File

@ -10,4 +10,3 @@ jid = becario@daemons.cf
password = goodPassword password = goodPassword
muc = testeando@salas.daemons.cf muc = testeando@salas.daemons.cf
nick = pasarelita nick = pasarelita
lines = 20

View File

@ -77,12 +77,10 @@ class IRCBot(SingleServerIRCBot):
class XMPPBot: class XMPPBot:
def __init__(self, jabber, remotejid, chanmuc, lines): def __init__(self, jabber, remotejid, chanmuc):
self.jabber = jabber self.jabber = jabber
self.remotejid = remotejid self.remotejid = remotejid
self.chanmuc = chanmuc self.chanmuc = chanmuc
self.lines = lines
self.counter = 0
def register_handlers(self): def register_handlers(self):
self.jabber.RegisterHandler('message', self.xmpp_message) self.jabber.RegisterHandler('message', self.xmpp_message)
@ -97,40 +95,37 @@ class XMPPBot:
if type in ['message', 'groupchat', None] and \ if type in ['message', 'groupchat', None] and \
fromjid == self.remotejid: fromjid == self.remotejid:
if self.counter >= self.lines: m = text.replace('\r', '')
m = text.replace('\r', '') m = m.replace('\n', '')
m = m.replace('\n', '') n = event.getFrom().getResource()
n = event.getFrom().getResource()
if text and n != m_nick: if text and n != m_nick:
if m == '.users': if m == '.users':
users = self.chanmuc.chan_users() users = self.chanmuc.chan_users()
users = ', '.join(users) users = ', '.join(users)
if users: if users:
users = '[ IRC Users ] ' + users users = '[ IRC Users ] ' + users
m = xmpp.protocol.Message(to=muc, body=users, m = xmpp.protocol.Message(to=muc, body=users,
typ='groupchat') typ='groupchat')
inter.xmpp(m)
elif m == '.help':
message = 'The only command I have is \'.users\''+ \
'. Also, my owner is ' + owner + '.'
m = xmpp.protocol.Message(to=muc, body=message,
typ='groupchat')
inter.xmpp(m) inter.xmpp(m)
else: elif m == '.help':
m = '[' + n + '] ' + m message = 'The only command I have is \'.users\''+ \
'. Also, my owner is ' + owner + '.'
buffer = 460 m = xmpp.protocol.Message(to=muc, body=message,
for i in range(0, len(m), buffer): typ='groupchat')
inter.irc(m[i:i + buffer].encode('latin-1', inter.xmpp(m)
'replace'))
self.counter += 1 else:
m = '[' + n + '] ' + m
buffer = 460
for i in range(0, len(m), buffer):
inter.irc(m[i:i + buffer].encode('latin-1',
'replace'))
except Exception as e: except Exception as e:
print e print e
@ -186,7 +181,10 @@ class XMPPBot:
'mismatch!\n') 'mismatch!\n')
sys.exit(1) sys.exit(1)
cl.send(xmpp.Presence(to='%s/%s' % (muc, m_nick))) p = xmpp.Presence(to='%s/%s' % (muc, m_nick))
p.setTag('x', namespace=xmpp.NS_MUC).addChild('history', {'maxchars': '0','maxstanzas': '0'})
cl.send(p)
while cl.Process(1): while cl.Process(1):
pass pass
@ -248,7 +246,6 @@ if __name__ == '__main__':
cl = xmpp.Client(jid.getDomain(), debug=[]) cl = xmpp.Client(jid.getDomain(), debug=[])
muc = parser.get('XMPP', 'muc') muc = parser.get('XMPP', 'muc')
m_nick = parser.get('XMPP', 'nick') m_nick = parser.get('XMPP', 'nick')
lines = int(parser.get('XMPP', 'lines'))
channel = str(parser.get('IRC', 'channel')) channel = str(parser.get('IRC', 'channel'))
i_nick = parser.get('IRC', 'nick') i_nick = parser.get('IRC', 'nick')
@ -260,7 +257,7 @@ if __name__ == '__main__':
try: try:
ircb0t = IRCBot(channel, i_nick, server, port, chanmuc) ircb0t = IRCBot(channel, i_nick, server, port, chanmuc)
xmppbot = XMPPBot(cl, muc, chanmuc, lines) xmppbot = XMPPBot(cl, muc, chanmuc)
inter = Intermedia() inter = Intermedia()
z = Thread(target=ircb0t.start, args=()) z = Thread(target=ircb0t.start, args=())
w = Thread(target=xmppbot.start, args=(cl,)) w = Thread(target=xmppbot.start, args=(cl,))