Skip to content

Commit 30d9822

Browse files
authored
Data not storing (#116)
* remove: deprecated json saving of userHandle * fix: changed false response from bot about user creating * fix: no data from 'add' functions was written to db * version: 2.5.2 -> 2.5.3
1 parent 0907529 commit 30d9822

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

cogs/commandlistener.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def on_ready(self):
5252
# Sends message to mods, when bot is online
5353
print("Now Online")
5454
await self.utils.sendModsMessage(
55-
"Bot is now online.\nVersion:\tDiscordBot DataBot v2.5.2"
55+
"Bot is now online.\nVersion:\tDiscordBot DataBot v2.5.3"
5656
)
5757
# Sets the bot's presence to "Online" or "Do not Disturb" to indicate if it's logging or not.
5858
if self.ch.getFromConfig("log") == "True":
@@ -226,7 +226,6 @@ async def on_raw_reaction_add(self, payload):
226226
and self.ch.getFromConfig("log") == "True"
227227
):
228228
self.uh.addReactionXP(payload.user_id, self.xpf.randomRange(1, 5))
229-
self.uh.saveData()
230229

231230
# When a user changes his voice state
232231
@commands.Cog.listener()
@@ -391,7 +390,6 @@ async def on_message(self, message):
391390
if name.endswith("jpg") or name.endswith("png"):
392391
# Gives XP when picture is in message
393392
self.uh.addTextXP(userID, self.xpf.randomRange(20, 40))
394-
self.uh.saveData()
395393
return
396394

397395
# When Message is a String
@@ -403,7 +401,6 @@ async def on_message(self, message):
403401
# Give XP when message is not a command
404402
if self.ch.isInWhitelist(message.channel.id):
405403
self.uh.addTextXP(message.author.id, self.xpf.textXP(a))
406-
self.uh.saveData()
407404

408405
# Sends BotOwner commands, which are triggering the bot
409406
if len(a) > 0 and a[0] == self.ch.getFromConfig("command_prefix"):

cogs/commanduser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ async def getUserData(self, ctx, userID):
191191
+ f" VoiceXP: {voice} TextXP: {text} TextCount: {textCount}"
192192
)
193193
else:
194-
user = self.bot.get_user(int(userID))
195-
message = f"User was not found in data. Created user: {user.mention}"
194+
message = "User was not found in data."
196195
await ctx.send(message)
197196

198197
@userSetParent.command(name="voice", brief="Sets users voicexp")

datahandler/userHandle.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __new__(
3737
else:
3838
cls.db_path = db_file_path
3939

40-
cls.db = SqliteDict(cls.db_path, outer_stack=False, autocommit=True)
40+
cls.db = SqliteDict(cls.db_path, outer_stack=True, autocommit=True)
4141
if (
4242
load_from_json_if_not_init
4343
and not cls.db
@@ -50,7 +50,7 @@ def __new__(
5050
cls.db[key] = value
5151

5252
cls.ch = ConfigHandle()
53-
atexit.register(UserHandle._cleanup, cls.db)
53+
atexit.register(UserHandle._cleanup, cls.db)
5454
return cls._instance
5555

5656
"""
@@ -357,7 +357,7 @@ def addUserVoice(self, userID: int | str, voice: int | str = 1):
357357
"""
358358
self.addNewDataEntry(userID)
359359
entry = self.db[str(userID)]
360-
entry["Voice"] += int(voice)
360+
entry["Voice"] = int(entry["Voice"]) + int(voice)
361361
self.db[str(userID)] = entry
362362

363363
def addUserText(self, userID: int | str, text: str | int):
@@ -369,7 +369,7 @@ def addUserText(self, userID: int | str, text: str | int):
369369
"""
370370
self.addNewDataEntry(userID)
371371
entry = self.db[str(userID)]
372-
entry["Text"] += int(text)
372+
entry["Text"] = int(entry["Text"]) + int(text)
373373
self.db[str(userID)] = entry
374374

375375
def addUserTextCount(self, userID: int | str, count: int | str = 1):
@@ -382,7 +382,7 @@ def addUserTextCount(self, userID: int | str, count: int | str = 1):
382382
"""
383383
self.addNewDataEntry(userID)
384384
entry = self.db[str(userID)]
385-
entry["TextCount"] += int(count)
385+
entry["TextCount"] = int(entry["TextCount"]) + int(count)
386386
self.db[str(userID)] = entry
387387

388388
@classmethod
@@ -394,5 +394,6 @@ def _cleanup(cls, db):
394394
Keyword arguments:
395395
db -- SqliteDict database object, which should be closed.
396396
"""
397+
print("[UserHandle] Closing Databank")
397398
db.commit()
398399
db.close()

0 commit comments

Comments
 (0)