Added help command
parent
7f45f78d62
commit
6b426b348e
|
@ -1,5 +1,6 @@
|
|||
from discord import Game
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands.formatter import HelpFormatter
|
||||
from discord.utils import oauth_url
|
||||
import requests
|
||||
import logging
|
||||
|
@ -13,17 +14,9 @@ description = '''
|
|||
Geoffrey (pronounced JOFF-ree) started his life as an inside joke none of you will understand.
|
||||
At some point, she was to become an airhorn discord_bot. Now, they know where your stuff is.
|
||||
|
||||
Please respect Geoffrey, the discord_bot is very sensitive.
|
||||
|
||||
All commands must be prefaced with '?'
|
||||
|
||||
If have a suggestion or if something is borked, you can PM my ding dong of a creator ZeroHD.
|
||||
|
||||
*You must use ?register before adding things to Geoffrey*
|
||||
|
||||
For a better a explanation on how this discord_bot works go the following link:
|
||||
https://github.com/joeyahines/Geoffrey/blob/master/README.md
|
||||
|
||||
'''
|
||||
|
||||
bad_error_message = 'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The admins at our ' \
|
||||
|
@ -35,12 +28,14 @@ class GeoffreyBot(commands.Bot):
|
|||
self.base_url = base_url
|
||||
self.api_token = api_token
|
||||
|
||||
URL = base_url + '/api/settings/'
|
||||
settings_url = base_url + '/api/settings/'
|
||||
command_list_url = base_url + '/api/command/commands'
|
||||
|
||||
logger.info("Connecting to the Geoffrey API... ")
|
||||
while True:
|
||||
try:
|
||||
setting = requests.get(url=URL, params={"api": self.api_token}).json()
|
||||
setting = requests.get(url=settings_url, params={"api": self.api_token}).json()
|
||||
self.command_list = requests.get(url=command_list_url, params={"api": self.api_token}).json()
|
||||
break
|
||||
except Exception:
|
||||
time.sleep(1)
|
||||
|
@ -51,11 +46,14 @@ class GeoffreyBot(commands.Bot):
|
|||
self.special_users = []
|
||||
self.default_status = setting['STATUS']
|
||||
|
||||
super().__init__(command_prefix=self.prefix, description=description, pm_help=True,
|
||||
case_insensitive=True)
|
||||
super().__init__(command_prefix=self.prefix, description=description, case_insensitive=True)
|
||||
|
||||
self.remove_command("help")
|
||||
self.load_extension('GeoffreyBot.geoffrey_api')
|
||||
|
||||
self.help_page = self.build_help_page()
|
||||
self.help_dict = self.build_help_dict()
|
||||
|
||||
async def on_ready(self):
|
||||
logger.info("%s Online, ID: %s", self.user.name, self.user.id)
|
||||
info = await self.application_info()
|
||||
|
@ -135,3 +133,45 @@ class GeoffreyBot(commands.Bot):
|
|||
|
||||
if len(msg) > 0:
|
||||
await ctx.send(msg)
|
||||
|
||||
def build_help_page(self):
|
||||
help_list = ["```"]
|
||||
|
||||
largest_command_size = 0
|
||||
for command in self.command_list:
|
||||
if largest_command_size < len(command["command"]):
|
||||
largest_command_size = len(command["command"])
|
||||
|
||||
for line in self.description.split("\n"):
|
||||
help_list.append(line)
|
||||
|
||||
help_list.append("\nCommands:")
|
||||
for command in self.command_list:
|
||||
name = command["command"].ljust(largest_command_size + 2)
|
||||
help_list.append(" {}{}{}".format(self.prefix, name, command["help"]))
|
||||
|
||||
help_list.append("\nDo ?help <command name> to get more info on any of thee commands above")
|
||||
help_list.append("```")
|
||||
|
||||
return help_list
|
||||
|
||||
def build_help_dict(self):
|
||||
help_dict = {}
|
||||
for command in self.command_list:
|
||||
command_name = command["command"]
|
||||
|
||||
help_list = ['```']
|
||||
|
||||
help_list.append(command["help"] + "\n")
|
||||
|
||||
help_msg = self.get_command(command_name).help
|
||||
help_list.append(help_msg.format(self.prefix))
|
||||
|
||||
help_list.append('```')
|
||||
|
||||
help_dict[command_name] = help_list
|
||||
|
||||
return help_dict
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def add_base(self, ctx, x_pos: int, z_pos: int, *args):
|
||||
'''
|
||||
{}add_base <x_pos> <z_pos> <Name>
|
||||
The name parameter is optional.
|
||||
'''
|
||||
name = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -65,6 +69,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def add_item(self, ctx, item_name, quantity: int, diamond_price: int, *args):
|
||||
'''
|
||||
{}add_item <item name> <quantity> <diamond price> <Shop Name>
|
||||
The name parameter is optional.
|
||||
'''
|
||||
shop_name = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -87,6 +95,11 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def add_shop(self, ctx, x_pos: int, z_pos: int, *args):
|
||||
'''
|
||||
{}add_shop <x_pos> <z_pos> <Name>
|
||||
The name parameter is optional.
|
||||
'''
|
||||
|
||||
name = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -109,6 +122,11 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def add_tunnel(self, ctx, tunnel_direction, tunnel_number: int, *args):
|
||||
'''
|
||||
{}add_tunnel <tunnel_direction> <tunnel_number> <Location Name>
|
||||
The name parameter is optional.
|
||||
'''
|
||||
|
||||
name = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -134,6 +152,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def delete(self, ctx, *args):
|
||||
'''
|
||||
{}delete <Location Name>
|
||||
'''
|
||||
|
||||
name = get_name(args)
|
||||
try:
|
||||
location = run_command(self.base_url, self.api_token, "POST", "delete", name=name,
|
||||
|
@ -152,6 +174,11 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def delete_item(self, ctx, item_name: str, *args):
|
||||
'''
|
||||
{}delete_item <Item Name> <Location Name>
|
||||
The name parameter is optional.
|
||||
'''
|
||||
|
||||
shop_name = get_name(args)
|
||||
try:
|
||||
shop = run_command(self.base_url, self.api_token, "POST", "delete_item", item=item_name,
|
||||
|
@ -177,6 +204,11 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_conext=True)
|
||||
async def edit_name(self, ctx, new_name: str, old_name: str):
|
||||
'''
|
||||
{}edit_name <New Name> <Old Name>
|
||||
If the name has spaces in it, it must be wrapped in quotes. eg "Cool Shop 123"
|
||||
'''
|
||||
|
||||
try:
|
||||
location = run_command(self.base_url, self.api_token, "POST", "edit_name", loc_name=old_name,
|
||||
new_name=new_name, discord_uuid=ctx.message.author.id)
|
||||
|
@ -198,6 +230,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_conext=True)
|
||||
async def edit_pos(self, ctx, new_x: int, new_z: int, *args):
|
||||
'''
|
||||
{}edit_post <New X Coord> <New Z Coord> <Location Name>
|
||||
'''
|
||||
|
||||
loc_name = get_name(args)
|
||||
try:
|
||||
location = run_command(self.base_url, self.api_token, "POST", "edit_pos", x=new_x, z=new_z,
|
||||
|
@ -217,6 +253,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_conext=True)
|
||||
async def edit_tunnel(self, ctx, new_tunnel_direction: str, new_tunnel_number: int, *args):
|
||||
'''
|
||||
{}edit_tunnel <New Tunnel Direction> <New Tunnel Number> <Location Name>
|
||||
'''
|
||||
|
||||
loc_name = get_name(args)
|
||||
try:
|
||||
location = run_command(self.base_url, self.api_token, "POST", "edit_tunnel",
|
||||
|
@ -242,6 +282,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def find_around(self, ctx, x_pos, z_pos, *args):
|
||||
'''
|
||||
{}find_around <X Position> <Z Position> <radius>
|
||||
'''
|
||||
|
||||
try:
|
||||
if len(args) > 0:
|
||||
radius = int(args[0])
|
||||
|
@ -273,8 +317,12 @@ class GeoffreyCommands:
|
|||
msg = check_error(e, error_list)
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def find(self, ctx, *args):
|
||||
@commands.command(pass_context=True, aliases=["find"])
|
||||
async def find_location(self, ctx, *args):
|
||||
'''
|
||||
{}find_location <Location or Player Name>
|
||||
'''
|
||||
|
||||
search = get_name(args)
|
||||
try:
|
||||
locations = run_command(self.base_url, self.api_token, "GET", "find_location", search=search)
|
||||
|
@ -296,8 +344,24 @@ class GeoffreyCommands:
|
|||
msg = check_error(e, error_list)
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def help(self, ctx, *args):
|
||||
if len(args) > 0:
|
||||
command = args[0].lower()
|
||||
try:
|
||||
await self.bot.send_list(ctx.message.author, self.bot.help_dict[command])
|
||||
except KeyError:
|
||||
await ctx.message.author.send("{}, no command named **{}** exists. Try {}help".format(
|
||||
ctx.message.author.mention, command, self.bot.prefix))
|
||||
else:
|
||||
await self.bot.send_list(ctx.message.author, self.bot.help_page)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def info(self, ctx, *args):
|
||||
'''
|
||||
{}info <Location Name>
|
||||
'''
|
||||
|
||||
location_name = get_name(args)
|
||||
try:
|
||||
location = run_command(self.base_url, self.api_token, "GET", "info", location_name=location_name)
|
||||
|
@ -319,6 +383,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def me(self, ctx):
|
||||
'''
|
||||
{}me
|
||||
'''
|
||||
|
||||
locations = run_command(self.base_url, self.api_token, "GET", "me", discord_uuid=ctx.message.author.id)
|
||||
|
||||
message = ["{}, you have the following locations:".format(ctx.message.author.mention)]
|
||||
|
@ -330,6 +398,9 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def register(self, ctx):
|
||||
'''
|
||||
{}register
|
||||
'''
|
||||
try:
|
||||
run_command(self.base_url, self.api_token, "POST", "register", player_name=ctx.message.author.display_name,
|
||||
discord_uuid=ctx.message.author.id)
|
||||
|
@ -348,6 +419,9 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def selling(self, ctx, *args):
|
||||
'''
|
||||
{}selling <item name>
|
||||
'''
|
||||
item = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -372,6 +446,11 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def restock(self, ctx, item_name, *args):
|
||||
'''
|
||||
{}restock <Item name> <Shop Name>
|
||||
The shop name is optional
|
||||
'''
|
||||
|
||||
shop_name = get_name(args)
|
||||
|
||||
try:
|
||||
|
@ -397,6 +476,10 @@ class GeoffreyCommands:
|
|||
|
||||
@commands.command(pass_context=True)
|
||||
async def tunnel(self, ctx, *args):
|
||||
'''
|
||||
{}tunnel <Player Name>
|
||||
'''
|
||||
|
||||
player_name = get_name(args)
|
||||
try:
|
||||
tunnels = run_command(self.base_url, self.api_token, "GET", "tunnel", player_name=player_name)
|
||||
|
|
Loading…
Reference in New Issue