Compare commits

...

2 commits

Author SHA1 Message Date
2a05edf78d remove entries for users no longer found on pnut.io
Some checks failed
thrrgilag/partybot/pipeline/head This commit looks good
git.dreamfall.space/partybot/pipeline/head There was a failure building this commit
2023-11-19 16:36:30 -08:00
b0ad45e935 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.
2023-11-19 16:18:49 -08:00

View file

@ -154,8 +154,18 @@ 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:
user, meta = pnutpy.api.get_user(entry.userid)
reply += user.username + ": " + str(entry.karma) + "\n"
try:
user, meta = pnutpy.api.get_user(entry.userid)
reply += user.username + ": " + str(entry.karma) + "\n"
except pnutpy.errors.PnutMissing:
del_karma = Karma.query.filter(Karma.userid == entry.userid).one_or_none()
if del_karma:
db_session.delete(del_karma)
del_counter = MdnpRequests.query.filter(MdnpRequests.userid == entry.userid).one_or_none()
if del_counter:
db_session.delete(del_counter)
db_session.commit()
send(room, reply)
def chimpnut(msg):