Skip to content

Commit

Permalink
added ability to see score of karma
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Oct 31, 2023
1 parent 880a4ce commit 7d09c7b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions cogs/commands/karma.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ async def most(self, ctx: Context):

await ctx.send(result)

@karma.command(help="Gives the karma of an item", ignore_extra=True)
async def score(self, ctx: Context, item: str):
item = await clean_content().convert(ctx, item)
karma_item = self.get_karma_item(item)
if not karma_item:
return await ctx.reply(f"\"{item}\" hasn't been karma'd yet. :cry:")

await ctx.reply(f'"{item}" has a score of {karma_item.net_score}.')

def get_karma_item(self, item: str):
karma_stripped = item.lstrip("@")
karma_item = (
db_session.query(KarmaModel)
.filter(func.lower(KarmaModel.name) == func.lower(karma_stripped))
.first()
)
return karma_item

@karma.command(
help="Gives information about the specified karma topic", ignore_extra=True
)
Expand All @@ -294,13 +312,8 @@ async def info(self, ctx: Context, item: str):
await ctx.typing()

t_start = current_milli_time()
# Strip any leading @s and get the item from the DB
karma_stripped = item.lstrip("@")
karma_item = (
db_session.query(KarmaModel)
.filter(func.lower(KarmaModel.name) == func.lower(karma_stripped))
.first()
)
karma_item = self.get_karma_item(item)

# If the item doesn't exist then raise an error
if not karma_item:
Expand Down Expand Up @@ -349,7 +362,7 @@ async def info(self, ctx: Context, item: str):
)
embed_colour = Color.from_rgb(61, 83, 255)
embed_title = f'Statistics for "{karma_stripped}"'
embed_description = f'"{karma_stripped}" has been karma\'d {len(all_changes)} {pluralise(all_changes, "time")} by {len(user_changes.keys())} {pluralise(user_changes.keys(), "user")}.'
embed_description = f'"{karma_stripped}" has a karma of {karma_item.net_score} and has been karma\'d {len(all_changes)} {pluralise(all_changes, "time")} by {len(user_changes.keys())} {pluralise(user_changes.keys(), "user")}.'

embed = Embed(
title=embed_title, description=embed_description, color=embed_colour
Expand Down

0 comments on commit 7d09c7b

Please sign in to comment.