Skip to content

Commit

Permalink
Add description for commands which acts as help message when calling …
Browse files Browse the repository at this point in the history
…help command
  • Loading branch information
J3y0 committed Jul 30, 2023
1 parent 85b0dd9 commit 089148e
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/bot/root_pythia_cogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class RootPythiaCommands(commands.Cog, name=NAME):
"""
Define the commands that the bot will respond to, prefixed with the `command_prefix` defined at
the bot init
Define the commands that the bot will respond to, prefixed with '!' \
defined at the bot init
"""

def __init__(self, bot, dbmanager):
Expand All @@ -36,6 +36,9 @@ async def log_command_call(self, ctx):
@commands.before_invoke(log_command_call)
@commands.command(name="status")
async def status(self, ctx):
"""
Give info on bot status
"""
rate_limiter = self.dbmanager.api_manager.rate_limiter
check = ":white_check_mark:"
cross = ":x:"
Expand All @@ -55,6 +58,9 @@ async def status(self, ctx):

@commands.command(name="resume")
async def resume(self, ctx):
"""
The bot leaves its idle state
"""
rate_limiter = self.dbmanager.api_manager.rate_limiter
if not rate_limiter.is_idle():
await ctx.message.channel.send("The Rate Limiter isn't idle, no need to resume.")
Expand All @@ -65,27 +71,31 @@ async def resume(self, ctx):
"Resumed successfully from idle state, requests can be sent again."
)

async def base_add_one_user(self, ctx, idx: int):
async def base_add_one_user(self, ctx, user_id: int):
# TODO: except 404 error -> if the request in add_user fails
# try:
# user = await self.dbmanager.add_user(idx)
# except 404Error as 404_err: # Error coming from add_user() method
# pass
user = await self.dbmanager.add_user(idx)
user = await self.dbmanager.add_user(user_id)

if user is None:
await ctx.message.channel.send(f"UserID {idx} already exists in database")
self.logger.warning("UserID '%s' already exists in database", idx)
await ctx.message.channel.send(f"UserID {user_id} already exists in database")
self.logger.warning("UserID '%s' already exists in database", user_id)
return

self.logger.info("Add user '%s'", user)
await ctx.message.channel.send(f"{user} added!\nPoints: {user.score}")

@commands.before_invoke(log_command_call)
@commands.command(name="addusers")
async def addusers(self, ctx, *args):
self.logger.info("command `addusers` received '%s' arguments: '%s'", len(args), args)
for user_id in args:
async def addusers(self, ctx, *user_ids):
"""
Add several rootme users with [user_ids...] to the tracked users
(each id is separated by a whitespace when using the command)
"""
self.logger.info("command `addusers` received '%s' arguments: '%s'", len(user_ids), user_ids)
for user_id in user_ids:
try:
user_id = int(user_id)
except ValueError as value_err: # Error coming from the int() cast
Expand All @@ -101,22 +111,28 @@ async def addusers(self, ctx, *args):

@commands.before_invoke(log_command_call)
@commands.command(name="adduser")
async def adduser(self, ctx, idx: int):
await self.base_add_one_user(ctx, idx)
async def adduser(self, ctx, user_id: int):
"""
Add rootme user with <user_id> to the tracked users
"""
await self.base_add_one_user(ctx, user_id)

@commands.before_invoke(log_command_call)
@commands.command(name="getuser")
async def getuser(self, ctx, idx: int):
user = self.dbmanager.get_user(idx)
async def getuser(self, ctx, user_id: int):
"""
Get rootme user info with <user_id>
"""
user = self.dbmanager.get_user(user_id)

if user is None:
self.logger.debug("DB Manager returned 'None' for UserID '%s'", idx)
self.logger.debug("DB Manager returned 'None' for UserID '%s'", user_id)
await ctx.message.channel.send(
f"User id '{idx}' isn't in the database, you must add it first"
f"User id '{user_id}' isn't in the database, you must add it first"
)
return

self.logger.debug("Get user '%s' for id=%d", repr(user), idx)
self.logger.debug("Get user '%s' for id=%d", repr(user), user_id)
await ctx.message.channel.send(
f"{user} \nPoints: {user.score}\nRank: {user.rank}\nLast Solves: <TO BE COMPLETED>"
)
Expand Down

0 comments on commit 089148e

Please sign in to comment.