Add !help command

This commit is contained in:
Tanner Collin 2021-04-19 04:18:40 +00:00
parent bdfec0f9a4
commit 87bb638270
3 changed files with 35 additions and 14 deletions

View File

@ -36,7 +36,11 @@ Use prefix (in this case, "1") to call to attention before giving command. (EX.
### Public Commands
These can be ran by anyone, all bots will reply
These can be ran by anyone, all bots will reply.
`!help` - prints this whole help message to console
`!help [command]` - replies in-game explaining command
`!ping` - replies with "pong"
@ -86,7 +90,7 @@ These can be ran by anyone, all bots will reply
### Bot-specific Commands
These will only run for the bot they are addressed to
These will only run for the bot they are addressed to.
`1respawn` - respawns the bot if it's dead
@ -132,7 +136,7 @@ These will only run for the bot they are addressed to
### Authorized Commands
These dangerous commands can only be ran by the bot owner
These dangerous commands can only be ran by the bot owner.
`1print [expression]` - replies with Python eval(expression)

23
game.py
View File

@ -25,6 +25,7 @@ from protocol.packets import (
)
from protocol.types import Slot
import print_help
import utils
importlib.reload(utils)
@ -492,7 +493,23 @@ class Game:
try:
## ### Public Commands
## These can be ran by anyone, all bots will reply
## These can be ran by anyone, all bots will reply.
## !help - prints this whole help message to console
## !help [command] - replies in-game explaining command
if command == 'help':
if data:
for line in print_help.HELP_LINES:
if line[1:].startswith(data) or line[1:].startswith(data[1:]):
reply = 'command ' + line
break
else: # for
reply = 'command not found'
else:
for line in print_help.HELP_LINES:
print(line)
reply = 'check console'
## !ping - replies with "pong"
if command == 'ping':
@ -653,7 +670,7 @@ class Game:
################# Specific commands ##########################
## ### Bot-specific Commands
## These will only run for the bot they are addressed to
## These will only run for the bot they are addressed to.
if for_me:
pass
@ -897,7 +914,7 @@ class Game:
################# Authorized commands ##########################
## ### Authorized Commands
## These dangerous commands can only be ran by the bot owner
## These dangerous commands can only be ran by the bot owner.
if authed:

View File

@ -6,11 +6,11 @@ with open('game.py', 'r') as f:
HELP_LINES.append(line.strip()[3:])
for line in HELP_LINES:
if ' - ' in line:
command, doc = line.split(' - ')
print('`{}` - {}\n'.format(command, doc))
else:
print(line)
print()
if __name__ == '__main__':
for line in HELP_LINES:
if ' - ' in line:
command, doc = line.split(' - ')
print('`{}` - {}\n'.format(command, doc))
else:
print(line)
print()