Check if msg index exists firstly: causes KeyError in logs (#114)

This commit is contained in:
Nameless 2020-07-05 16:53:59 +08:00 committed by GitHub
parent a053fdefec
commit 568e15aecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -351,7 +351,9 @@ class MsgModel:
}
def update_msg_content_opened(self, chat_id: int, msg_id: int) -> None:
index = self.msg_idx[chat_id][msg_id]
index = self.msg_idx[chat_id].get(msg_id)
if not index:
return
msg = MsgProxy(self.msgs[chat_id][index])
if msg.content_type == "voice":
msg.is_listened = True
@ -364,7 +366,9 @@ class MsgModel:
def update_msg(
self, chat_id: int, msg_id: int, **fields: Dict[str, Any]
) -> None:
index = self.msg_idx[chat_id][msg_id]
index = self.msg_idx[chat_id].get(msg_id)
if not index:
return
msg = self.msgs[chat_id][index]
msg.update(fields)