hotfixes & QOL

This commit is contained in:
2025-06-14 14:09:46 +02:00
parent e53b5ba677
commit 2a951723b1
10 changed files with 98 additions and 61 deletions
+6 -3
View File
@@ -37,12 +37,13 @@ class Bot:
password = self.password,
user_agent = self.useragent
)
self.sr_list: list[str] = ["bytedicetesting"]
self.sr = None
self.data_f: TextIOWrapper = None
self.data: dict = {}
async def initialize(self):
self.sr = await self.r.subreddit("bytedicetesting")
self.sr = await self.r.subreddit("+".join(self.sr_list))
async def set_args(self, args: dict):
self.args = args
@@ -57,11 +58,13 @@ class Bot:
async def update_cfg_str(self, new_cfg: str) -> bool:
json_cfg = toml.loads(new_cfg)
self.sr = await self.r.subreddit(json_cfg[CFG_DATA_RE]["subreddits"])
self.sr_list = json_cfg[CFG_DATA_RE]["subreddits"].split("+")
self.sr = await self.r.subreddit("+".join(self.sr_list))
self.fetch_limit = json_cfg[CFG_DATA_RE]["fetch_limit"]
return True
async def update_cfg(self, new_cfg: dict) -> bool:
self.sr = await self.r.subreddit(new_cfg[CFG_DATA_RE]["subreddits"])
self.sr_list = new_cfg[CFG_DATA_RE]["subreddits"].split("+")
self.sr = await self.r.subreddit("+".join(self.sr_list))
self.fetch_limit = new_cfg[CFG_DATA_RE]["fetch_limit"]
return True
+15 -18
View File
@@ -19,7 +19,7 @@ async def is_cmd(cmd: str, text: str, bot: botPy.Bot) -> bool:
async def respond_to_mention(bot: botPy.Bot) -> bool:
async for mention in bot.r.inbox.mentions(limit=25):
async for mention in bot.r.inbox.mentions(limit=100):
if not mention.new:
continue
@@ -33,13 +33,15 @@ async def respond_to_mention(bot: botPy.Bot) -> bool:
await bk_week_add(mention, bot)
else:
py_print("Mention was not a command.")
await mention.mark_read()
return True
async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
if not mention.subreddit.display_name not in bot.sr:
if bot.args["dev"]: py_print("Mention was a command: add_post")
if not mention.subreddit.display_name not in bot.sr_list:
await mention.mark_read()
return
@@ -58,23 +60,18 @@ async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
r = ""
bd = bot.data[botPy.RE_DATA_POSTS]
if short_url not in bd:
posts.add_post_url(bot, short_url)
r = "Successfully added this post to the data!"
if not is_mod: r = "Successfully added your post to the weekly art submissions!"
if is_mod: r = "[MOD ACTION] Successfully added this post to the weekly art submissions!"
else:
if bd[short_url]["removed"]["removed"] and is_mod:
r = "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!"
elif not bd[short_url]["removed"]["removed"]:
r = "Couldn't add this post to the submissions! Luckily, it's already there!"
if short_url in bd and is_mod:
if "removed" in bd[short_url]:
r = "[MOD ACTION] Successfully un-removed this post from the data!"
else:
r = "[MOD ACTION] Successfully added this post to the data!"
await posts.add_post_url(bot, short_url)
post = await posts.from_url(bot, short_url)
post_data = posts.get_post_details(post[1])
data.add_post_to_data(bot, post_data, True)
elif short_url in bd:
r = "Could not add this post to the data. Luckily, it's already there, so there's nothing to worry about!"
await mention.reply(r + " Thank you for participating!" + "\n\n" + BOT_ACTION_POSTFIX)
if r != "":
await mention.reply(r + " Thank you for participating!" + "\n\n" + BOT_ACTION_POSTFIX)
await mention.mark_read()
+9 -3
View File
@@ -9,7 +9,7 @@ from macros import *
DATA_PATH = os.path.join(os.path.join(os.getcwd(), "data"))
DB_PATH = os.path.join(DATA_PATH, "db")
DEFAULT_PATH = os.path.join(DATA_PATH, "default")
DEFAULT_PATH = os.path.join(DATA_PATH, "defaults")
CFG_PATH = os.path.join(os.path.join(os.getcwd(), "cfg"))
@@ -91,7 +91,7 @@ def read_data(bot: botPy.Bot) -> bool:
return False
py_print("re_data.json not found, creating new from preset...")
with open(os.path.join(DATA_PATH, "re_data_preset.json", "r")) as f:
with open(os.path.join(DEFAULT_PATH, "re_data_preset.json"), "r") as f:
data_preset_json = json.load(f)
data_preset_json[botPy.RE_DATA_POSTS].pop("EXAMPLE VALUE", None)
@@ -150,7 +150,7 @@ def add_post_to_data(bot: botPy.Bot, new_data: PostData, bypass_conditions: bool
if bot.args["dev"]: py_print(f"Added post \"{new_data.url}\" (Conditions bypassed)")
return True
if new_data.url not in bot.data[botPy.RE_DATA_POSTS]:
elif new_data.url not in bot.data[botPy.RE_DATA_POSTS]:
bot.data[botPy.RE_DATA_POSTS][new_data.url] = new_data.to_json()
if bot.args["dev"]: py_print(f"Added post \"{new_data.url}\"")
return True
@@ -159,6 +159,9 @@ def add_post_to_data(bot: botPy.Bot, new_data: PostData, bypass_conditions: bool
def set_approve_post(bot: botPy.Bot, approved: bool, url: str) -> bool:
if url not in bot.data[botPy.RE_DATA_POSTS]:
return False
if not bot.data[botPy.RE_DATA_POSTS][url]["removed"]["removed"]:
bot.data[botPy.RE_DATA_POSTS][url]["approved"]["by_human"] = approved
return True
@@ -205,6 +208,9 @@ def set_vote_post(
) -> bool:
if url not in bot.data[botPy.RE_DATA_POSTS]:
return False
if bot.data[botPy.RE_DATA_POSTS][url]["removed"]["removed"]:
return False
votes = bot.data[botPy.RE_DATA_POSTS][url]["votes"]
re_voters: set[str] = set(votes["voters_re"])