1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

move stuff out of the way

This commit is contained in:
urlbot
2014-12-06 10:34:27 +01:00
parent bbee90f041
commit 8d31036e0d
3 changed files with 0 additions and 0 deletions

79
related/bot.py Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/python3
import logging
from sleekxmpp import ClientXMPP
try:
from local_config import conf
except ImportError:
import sys
sys.stderr.write('''
%s: E: local_config.py isn't tracked because of included secrets and
%s site specific configurations. Rename local_config.py.skel and
%s adjust to you needs.
'''[1:] % (
sys.argv[0],
' ' * len(sys.argv[0]),
' ' * len(sys.argv[0])
)
)
sys.exit(-1)
import time
t = -time.time()
class bot(ClientXMPP):
def __init__(self, jid, password, room, nick):
ClientXMPP.__init__(self, jid, password)
self.room = room
self.nick = nick
self.add_event_handler('session_start', self.session_start)
self.add_event_handler('groupchat_message', self.muc_message)
def session_start(self, event):
self.get_roster()
self.send_presence()
self.plugin['xep_0045'].joinMUC(
self.room,
self.nick,
wait=True
)
def muc_message(self, msg):
print(msg['mucnick'])
print(msg['body'])
print((msg['from'], msg['from'].bare))
print(conf('room') == msg['from'].bare)
# don't talk to yourself
if msg['mucnick'] == self.nick:
return
self.send_message(
mto=msg['from'].bare,
mbody='got[%s]' % msg['body'],
mtype='groupchat'
)
if '__main__' == __name__:
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)-8s %(message)s'
)
xmpp = bot(
jid=conf('jid'),
password=conf('password'),
room=conf('room'),
nick=conf('bot_user')
)
xmpp.connect()
xmpp.register_plugin('xep_0045')
xmpp.process(threaded=False)