implement 'record' hooking including vanishing
This commit is contained in:
@@ -832,7 +832,7 @@ def command_record(argv, **args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
target_user = argv[1]
|
target_user = argv[1]
|
||||||
message = 'Message from %s (%s): ' % (args['reply_user'], time.strftime('%F.%T'))
|
message = '%s (%s): ' % (args['reply_user'], time.strftime('%F.%T'))
|
||||||
message += ' '.join(argv[2:])
|
message += ' '.join(argv[2:])
|
||||||
|
|
||||||
if conf('persistent_locked'):
|
if conf('persistent_locked'):
|
||||||
|
|||||||
66
urlbot.py
66
urlbot.py
@@ -225,7 +225,7 @@ def handle_msg(msg_obj):
|
|||||||
return
|
return
|
||||||
|
|
||||||
arg_user = msg_obj['mucnick']
|
arg_user = msg_obj['mucnick']
|
||||||
blob_userpref = conf_load().get('user_pref',[])
|
blob_userpref = conf_load().get('user_pref', [])
|
||||||
nospoiler = False
|
nospoiler = False
|
||||||
|
|
||||||
if arg_user in blob_userpref:
|
if arg_user in blob_userpref:
|
||||||
@@ -284,36 +284,50 @@ class bot(ClientXMPP):
|
|||||||
|
|
||||||
def muc_online(self, msg_obj):
|
def muc_online(self, msg_obj):
|
||||||
# don't react to yourself
|
# don't react to yourself
|
||||||
if msg_obj['mucnick'] == self.nick:
|
if msg_obj['muc']['nick'] == self.nick:
|
||||||
return
|
return
|
||||||
|
|
||||||
# XXX: this is the 'foo has joined' message hook. Be careful: After joining,
|
arg_user = msg_obj['muc']['nick']
|
||||||
# the bot user sees a single message for each existing user. E.g. the
|
blob_userrecords = conf_load().get('user_records', {})
|
||||||
# bot will likely highlight all users. Not good.
|
|
||||||
#
|
if arg_user in blob_userrecords:
|
||||||
# XXX: example code:
|
records = blob_userrecords[arg_user]
|
||||||
#
|
|
||||||
# self.send_message(
|
if not records:
|
||||||
# mto=msg_obj['from'].bare,
|
return
|
||||||
# mbody='hello, %s %s' % (
|
|
||||||
# msg_obj['muc']['role'],
|
self.send_message(
|
||||||
# msg_obj['muc']['nick']
|
mto=msg_obj['from'].bare,
|
||||||
# ),
|
mbody='%s, there %s %d message%s for you:\n%s' % (
|
||||||
# mtype='groupchat'
|
arg_user,
|
||||||
# )
|
'is' if 1 == len(records) else 'are',
|
||||||
#
|
len(records),
|
||||||
# log.info('sent greeting to %s in %s' % (
|
'' if 1 == len(records) else 's',
|
||||||
# msg_obj['muc']['nick'],
|
'\n'.join(blob_userrecords[arg_user])
|
||||||
# msg_obj['from'].bare
|
),
|
||||||
# ))
|
mtype='groupchat'
|
||||||
|
)
|
||||||
|
log.info('sent %d offline records to room %s' % (
|
||||||
|
len(records), msg_obj['from'].bare
|
||||||
|
))
|
||||||
|
|
||||||
|
if conf('persistent_locked'):
|
||||||
|
log.warn("couldn't get exclusive lock")
|
||||||
|
return False
|
||||||
|
|
||||||
|
set_conf('persistent_locked', True)
|
||||||
|
blob = conf_load()
|
||||||
|
|
||||||
|
if 'user_records' not in blob:
|
||||||
|
blob['user_records'] = {}
|
||||||
|
|
||||||
|
blob['user_records'][arg_user] = []
|
||||||
|
|
||||||
|
conf_save(blob)
|
||||||
|
set_conf('persistent_locked', False)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# plugins.data_parse_commands(msg_obj)
|
|
||||||
# plugins.data_parse_other(msg_obj)
|
|
||||||
|
|
||||||
print('msg from %s: %s' % (msg_obj['from'].bare, msg_obj))
|
|
||||||
|
|
||||||
# def set_presence(self, msg):
|
# def set_presence(self, msg):
|
||||||
# for room in self.rooms:
|
# for room in self.rooms:
|
||||||
# self.send_presence(pto=room, pstatus=msg)
|
# self.send_presence(pto=room, pstatus=msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user