partially made /bk_week_add command

This commit is contained in:
2025-02-09 21:22:44 +01:00
parent 9a723a2332
commit 99215d17e2
9 changed files with 233 additions and 57 deletions
+8 -2
View File
@@ -85,13 +85,19 @@ def read_data(bot: botPy.Bot):
raise Exception("reddit_data.json file wasn't created properly. Delete the file and retry.")
def write_data(bot: botPy.Bot):
def write_data(bot: botPy.Bot) -> bool:
bot.data_f.seek(0)
json.dump(bot.data, bot.data_f, indent=2)
bot.data_f.truncate()
return True
def add_post_to_data(bot: botPy.Bot, new_data: PostData) -> bool:
def add_post_to_data(bot: botPy.Bot, new_data: PostData, bypass_conditions: bool = False) -> bool:
if bypass_conditions:
bot.data[BK_WEEKLY][new_data.url] = new_data.to_json()
py_print(f"Added post \"{new_data.url}\" (Conditions bypassed)")
return True
if new_data.url not in bot.data[BK_WEEKLY]:
bot.data[BK_WEEKLY][new_data.url] = new_data.to_json()
py_print(f"Added post \"{new_data.url}\"")