C:/Program Files/Git/bk_week_approve command
This commit is contained in:
+11
-3
@@ -69,8 +69,8 @@ def read_data(bot: botPy.Bot):
|
||||
with open(data_path + "\\reddit_data_preset.json", "r") as f:
|
||||
data_preset_json = json.load(f)
|
||||
|
||||
data_preset_json["bk_weekly_art_posts"].pop("EXAMPLE VALUE", None)
|
||||
data_preset_json["bk_weekly_art_posts"].pop("EXAMPLE VALUE DELETED", None)
|
||||
data_preset_json[BK_WEEKLY].pop("EXAMPLE VALUE", None)
|
||||
data_preset_json[BK_WEEKLY].pop("EXAMPLE VALUE DELETED", None)
|
||||
|
||||
with open(data_path + "\\reddit_data.json", "w") as f:
|
||||
json.dump(data_preset_json, f, indent = 2)
|
||||
@@ -109,4 +109,12 @@ def add_post_to_data(bot: botPy.Bot, new_data: PostData, bypass_conditions: bool
|
||||
|
||||
else:
|
||||
py_print(f"Failed to add post \"{new_data.url}\": Already exists.")
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def set_approve_post(bot: botPy.Bot, approved: bool, url: str) -> bool:
|
||||
if not hasattr(bot.data[BK_WEEKLY][url], "removed"):
|
||||
bot.data[BK_WEEKLY][url]["approved"]["by_human"] = approved
|
||||
return True
|
||||
|
||||
return False
|
||||
+3
-3
@@ -102,7 +102,7 @@ def from_url(bot: botPy.Bot, url: str) -> tuple[bool, models.Submission]:
|
||||
return False, None
|
||||
|
||||
|
||||
def get_post_details(post: models.Submission):
|
||||
def get_post_details(post: models.Submission) -> data.PostData:
|
||||
media = has_media(post)
|
||||
|
||||
return data.PostData(
|
||||
@@ -116,11 +116,11 @@ def get_post_details(post: models.Submission):
|
||||
)
|
||||
|
||||
|
||||
async def add_post_url(bot, url: str) -> bool:
|
||||
def add_post_url(bot, url: str) -> bool:
|
||||
result, post = from_url(bot, url)
|
||||
|
||||
if not result:
|
||||
return result
|
||||
|
||||
post_data = get_post_details(post)
|
||||
data.add_post_to_data(bot, post_data, True)
|
||||
return data.add_post_to_data(bot, post_data, True)
|
||||
@@ -36,6 +36,7 @@ async def parse_json(response: str, bot: botPy.Bot):
|
||||
json_response = json.loads(json_str)
|
||||
result = await json_to_func(json_response, bot)
|
||||
await ws_global.ping()
|
||||
print(result)
|
||||
await send_message(f"json:{json.dumps(result)}")
|
||||
except json.JSONDecodeError as e:
|
||||
if bot.args["dev"]: py_print(f"failed to parse json: {json_str}\n reason: {e}")
|
||||
@@ -60,7 +61,8 @@ async def json_to_func(v: dict, bot: botPy.Bot) -> dict:
|
||||
|
||||
match v["value"]:
|
||||
case "update_data_file": result = {"type": "result", "value": data.write_data(bot)}
|
||||
case "add_post_url": result = {"type": "result", "value": await posts.add_post_url(bot, *v["args"])}
|
||||
case "add_post_url": result = {"type": "result", "value": posts.add_post_url(bot, *v["args"])}
|
||||
case "set_approve_post": result = {"type": "result", "value": data.set_approve_post(bot, *v["args"])}
|
||||
case _: value_supported = False
|
||||
|
||||
if bot.args["dev"] and not value_supported:
|
||||
|
||||
Reference in New Issue
Block a user