diff --git a/karma/bot.py b/karma/bot.py index 7d09ab3..9f70ca8 100644 --- a/karma/bot.py +++ b/karma/bot.py @@ -208,7 +208,7 @@ class KarmaBot(Plugin): else: return None message += "\n".join( - f"{index + 1}. [Event](https://matrix.to/#/{event.event_id}) by " + f"{index + 1}. [Event](https://matrix.to/#/{event.room_id}/{event.event_id}) by " f"[{self.denotify(event.sender)}](https://matrix.to/#/{event.sender}) with " f"{self.sign(event.total)} karma (+{event.positive}/-{event.negative})\n" f" > {event.content}" diff --git a/karma/db.py b/karma/db.py index dc84a70..463989f 100644 --- a/karma/db.py +++ b/karma/db.py @@ -24,8 +24,8 @@ from sqlalchemy.ext.declarative import declarative_base from mautrix.types import Event, UserID, EventID, RoomID -EventKarmaStats = NamedTuple("EventKarmaStats", event_id=EventID, sender=UserID, content=str, - total=int, positive=int, negative=int) +EventKarmaStats = NamedTuple("EventKarmaStats", room_id=RoomID, event_id=EventID, sender=UserID, + content=str, total=int, positive=int, negative=int) UserKarmaStats = NamedTuple("UserKarmaStats", user_id=UserID, total=int, positive=int, negative=int) @@ -57,7 +57,7 @@ class Karma: def get_event_stats(cls, direction, limit: int = 10) -> Iterable['EventKarmaStats']: c = cls.c return (EventKarmaStats(*row) for row in cls.db.execute( - select([c.given_for, c.given_to, c.content, + select([c.given_in, c.given_for, c.given_to, c.content, 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")])