contrib_bots: Clean up and document virtual_fs bot.
This commit is contained in:
parent
63efed5c73
commit
194ba1367b
44
contrib_bots/bots/virtual_fs/readme.md
Normal file
44
contrib_bots/bots/virtual_fs/readme.md
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# Virtual fs bot
|
||||||
|
|
||||||
|
This bot allows users to store information in a virtual file system,
|
||||||
|
for a given stream or private chat.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Run this bot as described in
|
||||||
|
[here](http://zulip.readthedocs.io/en/latest/bots-guide.html#how-to-deploy-a-bot).
|
||||||
|
|
||||||
|
Use this bot with any of the following commands:
|
||||||
|
|
||||||
|
`@fs mkdir` : create a directory
|
||||||
|
`@fs ls` : list a directory
|
||||||
|
`@fs cd` : change directory
|
||||||
|
`@fs pwd` : show current path
|
||||||
|
`@fs write` : write text
|
||||||
|
`@fs read` : read text
|
||||||
|
`@fs rm` : remove a file
|
||||||
|
`@fs rmdir` : remove a directory
|
||||||
|
|
||||||
|
where `fs` may be the name of the bot you registered in the zulip system.
|
||||||
|
|
||||||
|
### Usage examples
|
||||||
|
|
||||||
|
`@fs ls` - Initially shows nothing (with a warning)
|
||||||
|
`@fs pwd` - Show which directory we are in: we start in /
|
||||||
|
`@fs mkdir foo` - Make directory foo
|
||||||
|
`@fs ls` - Show that foo is now created
|
||||||
|
`@fs cd foo` - Change into foo (and do a pwd, automatically)
|
||||||
|
`@fs write test hello world` - Write "hello world" to the file 'test'
|
||||||
|
`@fs read test` - Check the text was written
|
||||||
|
`@fs ls` - Show that the new file exists
|
||||||
|
`@fs rm test` - Remove that file
|
||||||
|
`@fs cd /` - Change back to root directory
|
||||||
|
`@fs rmdir foo` - Remove foo
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
* In a stream, the bot must be mentioned; in a private chat, the bot
|
||||||
|
will assume every message is a command and so does not require this,
|
||||||
|
though doing so will still work.
|
||||||
|
|
||||||
|
* Use commands like `@fs help write` for more details on a command.
|
|
@ -9,7 +9,7 @@ class VirtualFsHandler(object):
|
||||||
|
|
||||||
def handle_message(self, message, client, state_handler):
|
def handle_message(self, message, client, state_handler):
|
||||||
command = message['content']
|
command = message['content']
|
||||||
stream = message['display_recipient']
|
if command == "": return
|
||||||
topic = message['subject']
|
topic = message['subject']
|
||||||
sender = message['sender_email']
|
sender = message['sender_email']
|
||||||
|
|
||||||
|
@ -17,23 +17,22 @@ class VirtualFsHandler(object):
|
||||||
if state is None:
|
if state is None:
|
||||||
state = {}
|
state = {}
|
||||||
|
|
||||||
if stream not in state:
|
recipient = message['display_recipient']
|
||||||
state[stream] = fs_new()
|
if isinstance(recipient, list): # If not a stream, then hash on list of emails
|
||||||
fs = state[stream]
|
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']:
|
if sender not in fs['user_paths']:
|
||||||
fs['user_paths'][sender] = '/'
|
fs['user_paths'][sender] = '/'
|
||||||
fs, msg = fs_command(fs, sender, command)
|
fs, msg = fs_command(fs, sender, command)
|
||||||
prependix = '{}:\n'.format(sender)
|
prependix = '{}:\n'.format(sender)
|
||||||
msg = prependix + msg
|
msg = prependix + msg
|
||||||
state[stream] = fs
|
state[recipient] = fs
|
||||||
state_handler.set_state(state)
|
state_handler.set_state(state)
|
||||||
|
|
||||||
client.send_message(dict(
|
client.send_reply(message, msg)
|
||||||
type='stream',
|
|
||||||
to=stream,
|
|
||||||
subject=topic,
|
|
||||||
content=msg,
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
def get_help():
|
def get_help():
|
||||||
|
|
Loading…
Reference in a new issue