introduce direct message support, add back fixed event loop
This commit is contained in:
13
idlebot.py
13
idlebot.py
@@ -110,6 +110,19 @@ def start(botclass, active=False):
|
|||||||
|
|
||||||
config.runtimeconf_set('start_time', -time.time())
|
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__:
|
if '__main__' == __name__:
|
||||||
start(IdleBot)
|
start(IdleBot)
|
||||||
|
|||||||
@@ -77,8 +77,6 @@ def command_source(argv, **_):
|
|||||||
|
|
||||||
@pluginfunction('dice', 'rolls a dice, optional N times', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
@pluginfunction('dice', 'rolls a dice, optional N times', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
||||||
def command_dice(argv, **args):
|
def command_dice(argv, **args):
|
||||||
if 'dice' != argv[0]:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
count = 1 if len(argv) < 2 else int(argv[1])
|
count = 1 if len(argv) < 2 else int(argv[1])
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@@ -753,7 +751,7 @@ def show_runtimeconfig(argv, **args):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
msg = json.dumps(config.runtime_config_store, indent=4)
|
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)
|
@pluginfunction('reload-runtimeconfig', "reload the runtimeconfig", ptypes_COMMAND, ratelimit_class=RATE_NO_LIMIT)
|
||||||
|
|||||||
31
urlbot.py
31
urlbot.py
@@ -58,9 +58,11 @@ class UrlBot(IdleBot):
|
|||||||
:param msg_obj:
|
:param msg_obj:
|
||||||
"""
|
"""
|
||||||
if msg_obj['type'] == 'groupchat':
|
if msg_obj['type'] == 'groupchat':
|
||||||
|
self.logger.info("Got the following MUC message: %s", str(msg_obj))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.logger.info("Got the following PM: %s", str(msg_obj))
|
self.logger.info("Got the following PM: %s", str(msg_obj))
|
||||||
|
self.handle_msg(msg_obj)
|
||||||
|
|
||||||
def muc_online(self, msg_obj):
|
def muc_online(self, msg_obj):
|
||||||
"""
|
"""
|
||||||
@@ -161,14 +163,21 @@ class UrlBot(IdleBot):
|
|||||||
# message = _prevent_panic(message, msg_obj['from'].bare)
|
# message = _prevent_panic(message, msg_obj['from'].bare)
|
||||||
# if get_bots_present(msg_obj['from'].bare):
|
# if get_bots_present(msg_obj['from'].bare):
|
||||||
# return
|
# return
|
||||||
if msg_obj['mucnick'] in config.runtimeconf_get("other_bots", ()):
|
if msg_obj['type'] == 'groupchat':
|
||||||
self.logger.debug("not talking to the other bot named {}".format( msg_obj['mucnick']))
|
if msg_obj['mucnick'] in config.runtimeconf_get("other_bots", ()):
|
||||||
return False
|
self.logger.debug("not talking to the other bot named {}".format(msg_obj['mucnick']))
|
||||||
self.send_message(
|
return False
|
||||||
mto=msg_obj['from'].bare,
|
self.send_message(
|
||||||
mbody=message,
|
mto=msg_obj['from'].bare,
|
||||||
mtype='groupchat'
|
mbody=message,
|
||||||
)
|
mtype='groupchat'
|
||||||
|
)
|
||||||
|
elif msg_obj['type'] == 'chat':
|
||||||
|
self.send_message(
|
||||||
|
mto=msg_obj['from'],
|
||||||
|
mbody=message,
|
||||||
|
mtype='chat'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
for room in self.rooms:
|
for room in self.rooms:
|
||||||
# message = _prevent_panic(message, room)
|
# message = _prevent_panic(message, room)
|
||||||
@@ -231,7 +240,7 @@ class UrlBot(IdleBot):
|
|||||||
self.hangup()
|
self.hangup()
|
||||||
sys.exit(1)
|
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
|
# TODO: check how several commands/plugins
|
||||||
# in a single message behave (also with rate limiting)
|
# 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):
|
if 'msg' in action and rate_limit(RATE_CHAT | plugin.ratelimit_class):
|
||||||
self.send_reply(action['msg'], msg_obj)
|
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:
|
if 'presence' in action:
|
||||||
presence = action['presence']
|
presence = action['presence']
|
||||||
runtimeconf_set('presence', presence)
|
runtimeconf_set('presence', presence)
|
||||||
|
|||||||
Reference in New Issue
Block a user