Handle 404 response when a user with karma no longer exists

When a user which has karma deletes there account on pnut.io a 404
is generated on user lookup. This will handle the error gracefully
and allow the !karma command to complete which resolves issue #2.

A more complete for this should be to delete the karma entry for
the now invalid user, to be done in another commit.
This commit is contained in:
Morgan McMillian 2023-11-19 16:18:49 -08:00
parent 57f591d0a2
commit b0ad45e935

View file

@ -154,8 +154,12 @@ def karma(room):
reply = "Karma standings\n\n"
results = Karma.query.filter(Karma.chanid == room).order_by(Karma.karma.desc()).all()
for entry in results:
try:
user, meta = pnutpy.api.get_user(entry.userid)
reply += user.username + ": " + str(entry.karma) + "\n"
except pnutpy.errors.PnutMissing:
continue
send(room, reply)
def chimpnut(msg):