Fix !karma for users with no karma
This commit is contained in:
parent
43efe08e84
commit
27fe50d65c
2 changed files with 4 additions and 4 deletions
|
@ -219,7 +219,7 @@ class KarmaBot(Plugin):
|
||||||
return
|
return
|
||||||
mxid = UserID(f"@{localpart}:{server_name}")
|
mxid = UserID(f"@{localpart}:{server_name}")
|
||||||
karma = self.karma.get_karma(mxid)
|
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 :(")
|
await evt.reply(f"[{localpart}](https://matrix.to/#/{mxid}) has no karma :(")
|
||||||
return
|
return
|
||||||
index = self.karma.find_index_from_top(mxid)
|
index = self.karma.find_index_from_top(mxid)
|
||||||
|
@ -243,7 +243,7 @@ class KarmaBot(Plugin):
|
||||||
|
|
||||||
async def view_own_karma(self, evt: MessageEvent) -> None:
|
async def view_own_karma(self, evt: MessageEvent) -> None:
|
||||||
karma = self.karma.get_karma(evt.sender)
|
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 :(")
|
await evt.reply("You don't have any karma :(")
|
||||||
return
|
return
|
||||||
index = self.karma.find_index_from_top(evt.sender)
|
index = self.karma.find_index_from_top(evt.sender)
|
||||||
|
|
|
@ -80,8 +80,8 @@ class Karma:
|
||||||
select([c.given_to,
|
select([c.given_to,
|
||||||
func.sum(c.value).label("total"),
|
func.sum(c.value).label("total"),
|
||||||
func.sum(case([(c.value > 0, c.value)], else_=0)).label("positive"),
|
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")])
|
func.abs(func.sum(case([(c.value < 0, c.value)], else_=0))).label("negative")]
|
||||||
.where(c.given_to == user_id))
|
).where(c.given_to == user_id))
|
||||||
try:
|
try:
|
||||||
return UserKarmaStats(*next(rows))
|
return UserKarmaStats(*next(rows))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
|
Loading…
Reference in a new issue