introduce direct message support, add back fixed event loop

This commit is contained in:
Thorsten
2015-12-26 23:06:46 +01:00
parent 92b2bf6447
commit d4741a55ea
3 changed files with 36 additions and 12 deletions

View File

@@ -110,6 +110,19 @@ def start(botclass, active=False):
config.runtimeconf_set('start_time', -time.time())
while 1:
try:
# print("hangup: %s" % got_hangup)
if not plugins.event_trigger():
bot.hangup()
if bot.state.current_state() == 'disconnected':
exit(0)
time.sleep(EVENTLOOP_DELAY)
except KeyboardInterrupt:
print('')
exit(130)
if '__main__' == __name__:
start(IdleBot)

View File

@@ -77,8 +77,6 @@ def command_source(argv, **_):
@pluginfunction('dice', 'rolls a dice, optional N times', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
def command_dice(argv, **args):
if 'dice' != argv[0]:
return
try:
count = 1 if len(argv) < 2 else int(argv[1])
except ValueError as e:
@@ -753,7 +751,7 @@ def show_runtimeconfig(argv, **args):
return
else:
msg = json.dumps(config.runtime_config_store, indent=4)
return {'msg': msg}
return {'priv_msg': msg}
@pluginfunction('reload-runtimeconfig', "reload the runtimeconfig", ptypes_COMMAND, ratelimit_class=RATE_NO_LIMIT)

View File

@@ -58,9 +58,11 @@ class UrlBot(IdleBot):
:param msg_obj:
"""
if msg_obj['type'] == 'groupchat':
self.logger.info("Got the following MUC message: %s", str(msg_obj))
return
else:
self.logger.info("Got the following PM: %s", str(msg_obj))
self.handle_msg(msg_obj)
def muc_online(self, msg_obj):
"""
@@ -161,14 +163,21 @@ class UrlBot(IdleBot):
# message = _prevent_panic(message, msg_obj['from'].bare)
# if get_bots_present(msg_obj['from'].bare):
# return
if msg_obj['type'] == 'groupchat':
if msg_obj['mucnick'] in config.runtimeconf_get("other_bots", ()):
self.logger.debug("not talking to the other bot named {}".format( msg_obj['mucnick']))
self.logger.debug("not talking to the other bot named {}".format(msg_obj['mucnick']))
return False
self.send_message(
mto=msg_obj['from'].bare,
mbody=message,
mtype='groupchat'
)
elif msg_obj['type'] == 'chat':
self.send_message(
mto=msg_obj['from'],
mbody=message,
mtype='chat'
)
else:
for room in self.rooms:
# message = _prevent_panic(message, room)
@@ -231,7 +240,7 @@ class UrlBot(IdleBot):
self.hangup()
sys.exit(1)
reply_user = msg_obj['mucnick']
reply_user = msg_obj['mucnick'] or msg_obj['from']._jid[2]
# TODO: check how several commands/plugins
# in a single message behave (also with rate limiting)
@@ -298,6 +307,10 @@ class UrlBot(IdleBot):
if 'msg' in action and rate_limit(RATE_CHAT | plugin.ratelimit_class):
self.send_reply(action['msg'], msg_obj)
if 'priv_msg' in action and rate_limit(RATE_CHAT | plugin.ratelimit_class):
msg_obj['type'] = 'chat'
self.send_reply(action['priv_msg'], msg_obj)
if 'presence' in action:
presence = action['presence']
runtimeconf_set('presence', presence)