Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
better command args and fix commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RealistikDash committed Oct 15, 2020
1 parent b380ae3 commit 80f18b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions gdpys/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ def decorator(coro):
raise Exception("Function is not a coroutine function!")
if name is None: # noqa
name = coro.__name__.lower() # noqa
loop = asyncio.get_event_loop()
loop.create_task(self.create_command(name, coro, permission)) # noqa
self.create_command(name, coro, permission) # noqa

return decorator

async def create_command(self, name: str, coro: asyncio.coroutine, permission: Permissions):
def create_command(self, name: str, coro: asyncio.coroutine, permission: Permissions):
"""Create a command"""
COMMANDS[name]= {
"handler": coro,
Expand Down Expand Up @@ -108,10 +107,12 @@ async def _execute_command(self, command_obj : Comment):
command = COMMANDS[command_args[0].lower()]
ctx = await self._create_context(command_obj)
account = await user_helper.get_object(await user_helper.accid_userid(command_obj.user_id)) # SHOULD be already cached.
# Create command args
passed_args = command_args[1:]
if not user_helper.has_privilege(account, command["permission"]):
return False
try:
await command["handler"](ctx)
await command["handler"](ctx, *passed_args)
except GDPySCommandError as e:
return CommentBan(
0, # /shrug
Expand All @@ -121,3 +122,11 @@ async def _execute_command(self, command_obj : Comment):
return True

client = Client()

# Testing commands
# If this isnt removed and youre reading this i did forgot this. kindly mass tag me on discord https://discord.gg/Un42FEV RealistikDash#0077
async def rate(ctx : CommandContext, level : int, star : str):
"""Rates a level right??"""
print(f"Level: {level}, stars: {star}")

client.create_command("rate", rate, None)
4 changes: 2 additions & 2 deletions handlers/levelextras.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ async def post_comment_handler(request : aiohttp.web.Request) -> aiohttp.web.Res
None # No comment ID yet.
)
# TODO : Command stuff
if comment_obj.comment.startswith(user_config["command_prefix"]) and commands._command_exists(comment_obj.comment):
result = await commands.execute_command(comment_obj)
if comment_obj.comment.startswith(user_config["command_prefix"]) and client._command_exists(comment_obj.comment):
result = await client._execute_command(comment_obj)
logging.debug(result)
if type(result) == bool:
result = ResponseCodes.generic_success if result else ResponseCodes.generic_fail
Expand Down
2 changes: 1 addition & 1 deletion helpers/filterhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
USERNAME_CHAR_LIMIT = 16

COMMENT_CHAR_LIMIT = 100
COMMENT_ALLOWED_CHARS = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/")
COMMENT_ALLOWED_CHARS = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/ ")

def check_username(username: str) -> bool:
"""Checks if a given username can be made inside GD."""
Expand Down

0 comments on commit 80f18b3

Please sign in to comment.