added full language support for python & fixed reddut "add_post" cmd.
This commit is contained in:
+6
-1
@@ -56,5 +56,10 @@
|
||||
"dc_msg_update_removing_old": "{0}Removing old posts (threshold: {1}d)...",
|
||||
"dc_msg_update_removing": "{0}Removing removed posts...",
|
||||
"log_lang_load_success": "Successfully loaded the english language file!",
|
||||
"none": "None"
|
||||
"none": "None",
|
||||
"py_re_response_suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)",
|
||||
"py_re_response_weekly_add": "Successfully added your post to the weekly art submissions! Thank you for participating!",
|
||||
"py_re_response_weekly_exists": "Couldn't add this post to the submissions! Luckily, it's already there! Thank you for participating!",
|
||||
"py_re_response_weekly_mod_add": "[MOD ACTION] Successfully added this post to the weekly art submissions!",
|
||||
"py_re_response_weekly_mod_unremove": "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!"
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ pub async fn start(args: Args) -> PyResult<()> {
|
||||
|
||||
unsafe {
|
||||
app_path = CString::new(
|
||||
format!("args = {}\nlang_name = {}\n{}",
|
||||
format!("args = {}\nlang_name = \"{}\"\n{}",
|
||||
py_args,
|
||||
LANG_NAME.clone().unwrap(),
|
||||
code
|
||||
|
||||
+1
-1
@@ -66,5 +66,5 @@ class Bot:
|
||||
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"]
|
||||
self.flairs = new_cfg[CFG_DATA_RE]["search_flair"]
|
||||
self.flairs = new_cfg[CFG_DATA_RE]["search_flairs"]
|
||||
return True
|
||||
+14
-12
@@ -2,13 +2,9 @@ import asyncpraw.models as models
|
||||
|
||||
from macros import *
|
||||
import bot as botPy
|
||||
import data
|
||||
import posts
|
||||
|
||||
|
||||
BOT_ACTION_POSTFIX = "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)"
|
||||
|
||||
|
||||
async def make_cmd(cmd: str, bot: botPy.Bot) -> str:
|
||||
return f"u/{await bot.r.user.me()} {cmd}"
|
||||
|
||||
@@ -33,7 +29,7 @@ async def respond_to_mention(bot: botPy.Bot) -> bool:
|
||||
await bk_week_add(mention, bot)
|
||||
|
||||
else:
|
||||
py_print("Mention was not a command.")
|
||||
if bot.args["dev"]: py_print("Mention was not a command.")
|
||||
await mention.mark_read()
|
||||
|
||||
return True
|
||||
@@ -41,8 +37,11 @@ async def respond_to_mention(bot: botPy.Bot) -> bool:
|
||||
|
||||
async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
|
||||
if bot.args["dev"]: py_print("Mention was a command: add_post")
|
||||
if not mention.subreddit.display_name not in bot.sr_list:
|
||||
|
||||
subreddit = mention.subreddit.display_name
|
||||
if subreddit not in bot.sr_list:
|
||||
await mention.mark_read()
|
||||
if bot.args["dev"]: py_print(f"Mention wasn't in a selected subreddit. Subreddit: {subreddit}")
|
||||
return
|
||||
|
||||
await mention.submission.load()
|
||||
@@ -52,8 +51,9 @@ async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
|
||||
is_op = author == mention.submission.author
|
||||
is_mod = author in await mention.subreddit.moderator()
|
||||
|
||||
if not is_op and not is_mod:
|
||||
if (not is_op) and (not is_mod):
|
||||
await mention.mark_read()
|
||||
if bot.args["dev"]: py_print("Mention wasn't by the OP or a moderator.")
|
||||
return
|
||||
|
||||
short_url = mention.submission.shortlink
|
||||
@@ -62,16 +62,18 @@ async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
|
||||
bd = bot.data[botPy.RE_DATA_POSTS]
|
||||
|
||||
if short_url not in bd:
|
||||
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!"
|
||||
if not is_mod: r = lang("py_re_response_weekly_add")
|
||||
if is_mod: r = lang("py_re_response_weekly_mod_add")
|
||||
else:
|
||||
if bd[short_url]["removed"]["removed"] and is_mod:
|
||||
r = "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!"
|
||||
r = lang("py_re_response_weekly_mod_unremove")
|
||||
elif not bd[short_url]["removed"]["removed"]:
|
||||
r = "Couldn't add this post to the submissions! Luckily, it's already there!"
|
||||
r = lang("py_re_response_weekly_exists")
|
||||
|
||||
await posts.add_post_url(bot, short_url)
|
||||
|
||||
if r != "":
|
||||
await mention.reply(r + " Thank you for participating!" + "\n\n" + BOT_ACTION_POSTFIX)
|
||||
await mention.reply(r + "\n\n" + lang("py_re_response_suffix"))
|
||||
if bot.args["dev"]: py_print("Responded to mention.")
|
||||
elif bot.args["dev"]: py_print("Response is empty.")
|
||||
await mention.mark_read()
|
||||
@@ -144,6 +144,8 @@ def add_post_to_data(bot: botPy.Bot, new_data: PostData, bypass_conditions: bool
|
||||
new_data.removed = False
|
||||
new_data.removed_by = None
|
||||
new_data.removed_reason = None
|
||||
if bot.args["dev"]: py_print(f"Un-removed post \"{new_data.url}\"")
|
||||
return True
|
||||
|
||||
if bypass_conditions:
|
||||
bot.data[botPy.RE_DATA_POSTS][new_data.url] = new_data.to_json()
|
||||
|
||||
@@ -26,6 +26,8 @@ def py_error(*args):
|
||||
|
||||
|
||||
def lang(k: str) -> str:
|
||||
if G_LANG == {}:
|
||||
py_error("Language must be initialized before use!")
|
||||
t = G_LANG.get(k)
|
||||
if k is None: py_error(f"Key not found in language \"{G_LANG_NAME}\": {k}")
|
||||
return str(t)
|
||||
|
||||
Reference in New Issue
Block a user