contrib_bots: Clean up and document virtual_fs bot.
This commit is contained in:
parent
63efed5c73
commit
194ba1367b
2 changed files with 54 additions and 11 deletions
|
@ -9,7 +9,7 @@ class VirtualFsHandler(object):
|
|||
|
||||
def handle_message(self, message, client, state_handler):
|
||||
command = message['content']
|
||||
stream = message['display_recipient']
|
||||
if command == "": return
|
||||
topic = message['subject']
|
||||
sender = message['sender_email']
|
||||
|
||||
|
@ -17,23 +17,22 @@ class VirtualFsHandler(object):
|
|||
if state is None:
|
||||
state = {}
|
||||
|
||||
if stream not in state:
|
||||
state[stream] = fs_new()
|
||||
fs = state[stream]
|
||||
recipient = message['display_recipient']
|
||||
if isinstance(recipient, list): # If not a stream, then hash on list of emails
|
||||
recipient = " ".join([x['email'] for x in recipient])
|
||||
|
||||
if recipient not in state:
|
||||
state[recipient] = fs_new()
|
||||
fs = state[recipient]
|
||||
if sender not in fs['user_paths']:
|
||||
fs['user_paths'][sender] = '/'
|
||||
fs, msg = fs_command(fs, sender, command)
|
||||
prependix = '{}:\n'.format(sender)
|
||||
msg = prependix + msg
|
||||
state[stream] = fs
|
||||
state[recipient] = fs
|
||||
state_handler.set_state(state)
|
||||
|
||||
client.send_message(dict(
|
||||
type='stream',
|
||||
to=stream,
|
||||
subject=topic,
|
||||
content=msg,
|
||||
))
|
||||
client.send_reply(message, msg)
|
||||
|
||||
|
||||
def get_help():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue