From d19af13b972b7d07643ff49295beea5406da20ba Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 15 Oct 2023 18:49:15 +0530 Subject: [PATCH] Fix a bug which returns `KeyError` when modifying user level When the levelling db library attempts to add or remove levels from a user (through framework), it ends up failing and returning a `KeyError` exception. This was because in the levelling db library, the `add_levels()` and `remove_levels()` methods were attempting to modify the `levels` value (non-existant) instead of the `level` value (actual key name). This patch aims at resolving this issue. --- framework/isobot/db/levelling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/isobot/db/levelling.py b/framework/isobot/db/levelling.py index 2d3af1a3..14a8e1d1 100644 --- a/framework/isobot/db/levelling.py +++ b/framework/isobot/db/levelling.py @@ -45,14 +45,14 @@ def set_xp(self, user_id: int, count: int) -> int: def add_levels(self, user_id: int, count: int) -> int: """Adds a specified amount of levels to the specified user.""" levels = self.load() - levels[str(user_id)]["levels"] += count + levels[str(user_id)]["level"] += count self.save(levels) return 0 def remove_levels(self, user_id: int, count: int) -> int: """Removes a specified amount of levels from the specified user.""" levels = self.load() - levels[str(user_id)]["levels"] -= count + levels[str(user_id)]["level"] -= count self.save(levels) return 0