Fix !karma for users with no karma

This commit is contained in:
Tulir Asokan 2018-10-27 01:43:43 +03:00
parent 43efe08e84
commit 27fe50d65c
2 changed files with 4 additions and 4 deletions

View file

@ -219,7 +219,7 @@ class KarmaBot(Plugin):
return
mxid = UserID(f"@{localpart}:{server_name}")
karma = self.karma.get_karma(mxid)
if karma is None:
if karma is None or karma.total is None:
await evt.reply(f"[{localpart}](https://matrix.to/#/{mxid}) has no karma :(")
return
index = self.karma.find_index_from_top(mxid)
@ -243,7 +243,7 @@ class KarmaBot(Plugin):
async def view_own_karma(self, evt: MessageEvent) -> None:
karma = self.karma.get_karma(evt.sender)
if karma is None:
if karma is None or karma.total is None:
await evt.reply("You don't have any karma :(")
return
index = self.karma.find_index_from_top(evt.sender)

View file

@ -80,8 +80,8 @@ class Karma:
select([c.given_to,
func.sum(c.value).label("total"),
func.sum(case([(c.value > 0, c.value)], else_=0)).label("positive"),
func.abs(func.sum(case([(c.value < 0, c.value)], else_=0))).label("negative")])
.where(c.given_to == user_id))
func.abs(func.sum(case([(c.value < 0, c.value)], else_=0))).label("negative")]
).where(c.given_to == user_id))
try:
return UserKarmaStats(*next(rows))
except StopIteration: