bots: Add a new command 'sample_conversation' in virtual_fs bot.
The previous test function in virtual_Bot made use of another function called a 'sample_conversation' which had stateful example conversation with virtual_fs bot. The function sample_conversation is really useful, so made it accessible to the users too.
This commit is contained in:
parent
fd7bbf0098
commit
5d5865fe5e
|
@ -43,6 +43,7 @@ running, and if you rename a stream, you will lose the info.
|
||||||
Example commands:
|
Example commands:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
fs sample_conversation: sample conversation with the bot
|
||||||
fs mkdir: create a directory
|
fs mkdir: create a directory
|
||||||
fs ls: list a directory
|
fs ls: list a directory
|
||||||
fs cd: change directory
|
fs cd: change directory
|
||||||
|
@ -58,54 +59,54 @@ commands.
|
||||||
|
|
||||||
def sample_conversation():
|
def sample_conversation():
|
||||||
return [
|
return [
|
||||||
('cd /', 'Current path: /'),
|
('cd /\nCurrent path: /\n\n'),
|
||||||
('cd /home', 'ERROR: invalid path'),
|
('cd /home\nERROR: invalid path\n\n'),
|
||||||
('cd .', 'ERROR: invalid path'),
|
('cd .\nERROR: invalid path\n\n'),
|
||||||
('mkdir home', 'directory created'),
|
('mkdir home\ndirectory created\n\n'),
|
||||||
('cd home', 'Current path: /home/'),
|
('cd home\nCurrent path: /home/\n\n'),
|
||||||
('cd /home/', 'Current path: /home/'),
|
('cd /home/\nCurrent path: /home/\n\n'),
|
||||||
('mkdir stuff/', 'ERROR: stuff/ is not a valid name'),
|
('mkdir stuff/\nERROR: stuff/ is not a valid name\n\n'),
|
||||||
('mkdir stuff', 'directory created'),
|
('mkdir stuff\ndirectory created\n\n'),
|
||||||
('write stuff/file1 something', 'file written'),
|
('write stuff/file1 something\nfile written\n\n'),
|
||||||
('read stuff/file1', 'something'),
|
('read stuff/file1\nsomething\n\n'),
|
||||||
('read /home/stuff/file1', 'something'),
|
('read /home/stuff/file1\nsomething\n\n'),
|
||||||
('read home/stuff/file1', 'ERROR: file does not exist'),
|
('read home/stuff/file1\nERROR: file does not exist\n\n'),
|
||||||
('pwd ', '/home/'),
|
('pwd \n/home/\n\n'),
|
||||||
('pwd bla', 'ERROR: syntax: pwd'),
|
('pwd bla\nERROR: syntax: pwd\n\n'),
|
||||||
('ls bla foo', 'ERROR: syntax: ls <optional_path>'),
|
('ls bla foo\nERROR: syntax: ls <optional_path>\n\n'),
|
||||||
('cd /', 'Current path: /'),
|
('cd /\nCurrent path: /\n\n'),
|
||||||
('rm home', 'ERROR: /home/ is a directory, file required'),
|
('rm home\nERROR: /home/ is a directory, file required\n\n'),
|
||||||
('rmdir home', 'removed'),
|
('rmdir home\nremoved\n\n'),
|
||||||
('ls ', 'WARNING: directory is empty'),
|
('ls \nWARNING: directory is empty\n\n'),
|
||||||
('cd home', 'ERROR: invalid path'),
|
('cd home\nERROR: invalid path\n\n'),
|
||||||
('read /home/stuff/file1', 'ERROR: file does not exist'),
|
('read /home/stuff/file1\nERROR: file does not exist\n\n'),
|
||||||
('cd /', 'Current path: /'),
|
('cd /\nCurrent path: /\n\n'),
|
||||||
('write /foo contents of /foo', 'file written'),
|
('write /foo contents of /foo\nfile written\n\n'),
|
||||||
('read /foo', 'contents of /foo'),
|
('read /foo\ncontents of /foo\n\n'),
|
||||||
('write /bar Contents: bar bar', 'file written'),
|
('write /bar Contents: bar bar\nfile written\n\n'),
|
||||||
('read /bar', 'Contents: bar bar'),
|
('read /bar\nContents: bar bar\n\n'),
|
||||||
('write /bar invalid', 'ERROR: file already exists'),
|
('write /bar invalid\nERROR: file already exists\n\n'),
|
||||||
('rm /bar', 'removed'),
|
('rm /bar\nremoved\n\n'),
|
||||||
('rm /bar', 'ERROR: file does not exist'),
|
('rm /bar\nERROR: file does not exist\n\n'),
|
||||||
('write /bar new bar', 'file written'),
|
('write /bar new bar\nfile written\n\n'),
|
||||||
('read /bar', 'new bar'),
|
('read /bar\nnew bar\n\n'),
|
||||||
('write /yo/invalid whatever', 'ERROR: /yo is not a directory'),
|
('write /yo/invalid whatever\nERROR: /yo is not a directory\n\n'),
|
||||||
('mkdir /yo', 'directory created'),
|
('mkdir /yo\ndirectory created\n\n'),
|
||||||
('read /yo', 'ERROR: /yo/ is a directory, file required'),
|
('read /yo\nERROR: /yo/ is a directory, file required\n\n'),
|
||||||
('ls /yo', 'WARNING: directory is empty'),
|
('ls /yo\nWARNING: directory is empty\n\n'),
|
||||||
('read /yo/nada', 'ERROR: file does not exist'),
|
('read /yo/nada\nERROR: file does not exist\n\n'),
|
||||||
('write /yo whatever', 'ERROR: file already exists'),
|
('write /yo whatever\nERROR: file already exists\n\n'),
|
||||||
('write /yo/apple red', 'file written'),
|
('write /yo/apple red\nfile written\n\n'),
|
||||||
('read /yo/apple', 'red'),
|
('read /yo/apple\nred\n\n'),
|
||||||
('mkdir /yo/apple', 'ERROR: file already exists'),
|
('mkdir /yo/apple\nERROR: file already exists\n\n'),
|
||||||
('ls /invalid', 'ERROR: file does not exist'),
|
('ls /invalid\nERROR: file does not exist\n\n'),
|
||||||
('ls /foo', 'ERROR: /foo is not a directory'),
|
('ls /foo\nERROR: /foo is not a directory\n\n'),
|
||||||
('ls /', '* /*bar*\n* /*foo*\n* /yo/'),
|
('ls /\n* /*bar*\n* /*foo*\n* /yo/\n\n'),
|
||||||
('invalid command', 'ERROR: unrecognized command'),
|
('invalid command\nERROR: unrecognized command\n\n'),
|
||||||
('write', 'ERROR: syntax: write <path> <some_text>'),
|
('write\nERROR: syntax: write <path> <some_text>\n\n'),
|
||||||
('help', get_help()),
|
('help' + get_help() + '\n\n'),
|
||||||
('help ls', 'syntax: ls <optional_path>'),
|
('help ls\nsyntax: ls <optional_path>\n\n'),
|
||||||
('help invalid_command', get_help()),
|
('help invalid_command' + get_help() + '\n\n'),
|
||||||
]
|
]
|
||||||
|
|
||||||
REGEXES = dict(
|
REGEXES = dict(
|
||||||
|
@ -118,6 +119,7 @@ REGEXES = dict(
|
||||||
def get_commands():
|
def get_commands():
|
||||||
return {
|
return {
|
||||||
'help': (fs_help, ['command']),
|
'help': (fs_help, ['command']),
|
||||||
|
'sample_conversation': (fs_sample_conversation, ['command']),
|
||||||
'ls': (fs_ls, ['optional_path']),
|
'ls': (fs_ls, ['optional_path']),
|
||||||
'mkdir': (fs_mkdir, ['path']),
|
'mkdir': (fs_mkdir, ['path']),
|
||||||
'read': (fs_read, ['path']),
|
'read': (fs_read, ['path']),
|
||||||
|
@ -132,6 +134,8 @@ def fs_command(fs, user, cmd):
|
||||||
cmd = cmd.strip()
|
cmd = cmd.strip()
|
||||||
if cmd == 'help':
|
if cmd == 'help':
|
||||||
return fs, get_help()
|
return fs, get_help()
|
||||||
|
if cmd == 'sample_conversation':
|
||||||
|
return fs, (''.join(sample_conversation()))
|
||||||
cmd_name = cmd.split()[0]
|
cmd_name = cmd.split()[0]
|
||||||
cmd_args = cmd[len(cmd_name):].strip()
|
cmd_args = cmd[len(cmd_name):].strip()
|
||||||
commands = get_commands()
|
commands = get_commands()
|
||||||
|
@ -170,6 +174,9 @@ def fs_new():
|
||||||
def fs_help(fs, user, cmd_name):
|
def fs_help(fs, user, cmd_name):
|
||||||
return fs, syntax_help(cmd_name)
|
return fs, syntax_help(cmd_name)
|
||||||
|
|
||||||
|
def fs_sample_conversation(fs, user, cmd_name):
|
||||||
|
return fs, syntax_help(cmd_name)
|
||||||
|
|
||||||
def fs_mkdir(fs, user, fn):
|
def fs_mkdir(fs, user, fn):
|
||||||
path, msg = make_path(fs, user, fn)
|
path, msg = make_path(fs, user, fn)
|
||||||
if msg:
|
if msg:
|
||||||
|
|
Loading…
Reference in a new issue