Skip to content

Commit

Permalink
Add description to kaasino command, add message link in kasino list
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Nov 5, 2024
1 parent ba690ea commit e639b6f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions extensions/karma.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ async def post_check(self, ctx: commands.Context, post_id: str):
if not ctx.interaction:
await ctx.message.delete()

async def _create_post_leaderboard(self, posts: list[Record]):
async def _create_post_leaderboard(self, posts: list[Record]) -> str:
if not posts:
return "No posts found."
leaderboard = ""
Expand All @@ -725,12 +725,18 @@ async def _create_post_leaderboard(self, posts: list[Record]):
username = self.bot.get_user(post["discord_user_id"]) or await self.bot.fetch_user(post["discord_user_id"])
leaderboard += f"**{index}.** [{username} ({post['upvotes']})]({jump_url})\n"
return leaderboard

def _create_kasino_message_url(self, kasino: Record) -> str:
return self._create_message_url(kasino["discord_server_id"], kasino["discord_channel_id"], kasino["discord_message_id"])

def _create_message_url(self, server_id, channel_id, message_id):
def _create_message_url(self, server_id, channel_id, message_id) -> str:
return f"https://discordapp.com/channels/{server_id}/{channel_id}/{message_id}"

@commands.hybrid_group(name="kasino", aliases=["kas"], invoke_without_command=True)
async def kasino(self, ctx: commands.Context):
"""Karma kasino which allows people to bet on a question with two options.
If you want to open a kasino, use the subcommand `kasino open`.
"""
await ctx.send_help(ctx.command)

@kasino.command(name="open", aliases=["o"], usage='open "<question>" "<option1>" "<option2>"')
Expand Down Expand Up @@ -806,8 +812,8 @@ async def kasino_list(self, ctx: commands.Context):
"""Lists all open kasinos on the server."""
embed = discord.Embed(title="Open kasinos")
stmt_kasinos = "SELECT * FROM kasino WHERE locked = False AND discord_server_id = $1 ORDER BY id ASC;"
all_kasinos = await self.bot.db.pool.fetch(stmt_kasinos, ctx.guild.id)
embed_kasinos = "".join(f'`{entry["id"]}` - {entry["question"]}\n' for entry in all_kasinos)
all_kasinos: list[Record] = await self.bot.db.pool.fetch(stmt_kasinos, ctx.guild.id)
embed_kasinos = "".join(f'`{entry["id"]}` - [{entry["question"]}]({self._create_kasino_message_url(entry)})\n' for entry in all_kasinos)
embed.description = embed_kasinos or "No open kasinos found."
await ctx.send(embed=embed, delete_after=300)
if not ctx.interaction:
Expand Down

0 comments on commit e639b6f

Please sign in to comment.