hotfixes & QOL
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
### High priority:
|
### High priority:
|
||||||
- [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server
|
- [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server
|
||||||
- [ ] handle dm_on_error cfg
|
- [ ] handle dm_on_error cfg
|
||||||
- [ ] Add button event listeners
|
|
||||||
- [ ] Allow updating the data autonomously and via manual commands.
|
- [ ] Allow updating the data autonomously and via manual commands.
|
||||||
- [ ] Automatically approve posts that don't get caught by reverse image search (ris)
|
- [ ] Automatically approve posts that don't get caught by reverse image search (ris)
|
||||||
- [ ] Make buttons do stuff
|
- [ ] Make buttons do stuff
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
🎲 https://bytedice.net
|
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
[general]
|
||||||
|
# The discord bots status text
|
||||||
|
status = "🎲 https://bytedice.net"
|
||||||
|
|
||||||
[reddit]
|
[reddit]
|
||||||
# Which subreddits the bot will scan when executing "re"-category commands.
|
# Which subreddits the bot will scan when executing "re"-category commands.
|
||||||
# Is automatically disabled when `disabled_categories` includes "re".
|
# Is automatically disabled when `disabled_categories` includes "re".
|
||||||
|
|||||||
+3
-1
@@ -12,7 +12,7 @@
|
|||||||
"dc_msg_corrupted_data": "Oopsies `(。>\\\\<)`. It looks like my data i-is \\**sob*\\*... c-corrupted!\n[From Byte Dice]: I have no idea what I was thinking while writing this at 2am. I'm not removing it.",
|
"dc_msg_corrupted_data": "Oopsies `(。>\\\\<)`. It looks like my data i-is \\**sob*\\*... c-corrupted!\n[From Byte Dice]: I have no idea what I was thinking while writing this at 2am. I'm not removing it.",
|
||||||
"dc_msg_data_server_404": "This server is not in the data!\n Hint: Run the command `/add_server` inside of a Discord server (requires administrator permission).",
|
"dc_msg_data_server_404": "This server is not in the data!\n Hint: Run the command `/add_server` inside of a Discord server (requires administrator permission).",
|
||||||
"dc_msg_dm_python_err_socket": "Unknown internal Python error occurred: Websocket response error",
|
"dc_msg_dm_python_err_socket": "Unknown internal Python error occurred: Websocket response error",
|
||||||
"dc_msg_dm_python_err": "Unknown internal Python Error: `{0}`",
|
"dc_msg_dm_python_err": "Unknown internal Python Error:\n```\n{0}\n```",
|
||||||
"dc_msg_embed_default_embed_desc": "Default english embed description.",
|
"dc_msg_embed_default_embed_desc": "Default english embed description.",
|
||||||
"dc_msg_embed_re_post": "Spoilers and vote length anonymizer for fair review!\n## Post Data:\n**Post upvotes:** ||`{0:>6}`||\n**Moderator votes:** ||`{1:>6}`||\n**Media type:** `{2}`\n**URL:** ||<{3}>||\n\n## Listing Data:\n**Added by:** `{{ human: {4}, bot: {5} }}`\n**Approved by:** `{{ human: {6}, bot: [not implemented] }}`",
|
"dc_msg_embed_re_post": "Spoilers and vote length anonymizer for fair review!\n## Post Data:\n**Post upvotes:** ||`{0:>6}`||\n**Moderator votes:** ||`{1:>6}`||\n**Media type:** `{2}`\n**URL:** ||<{3}>||\n\n## Listing Data:\n**Added by:** `{{ human: {4}, bot: {5} }}`\n**Approved by:** `{{ human: {6}, bot: [not implemented] }}`",
|
||||||
"dc_msg_embed_re_removed": "## Removed by `{0}`\n**Reason:** {1}\n**URL**: ||<{2}>||",
|
"dc_msg_embed_re_removed": "## Removed by `{0}`\n**Reason:** {1}\n**URL**: ||<{2}>||",
|
||||||
@@ -29,11 +29,13 @@
|
|||||||
"dc_msg_re_permdeny_not_re_mod": "Permission denied: You are not a moderator of the subreddit(s) {0}",
|
"dc_msg_re_permdeny_not_re_mod": "Permission denied: You are not a moderator of the subreddit(s) {0}",
|
||||||
"dc_msg_re_post_404": "Post URL \"<{0}>\" not found: Post doesn't exist in the data!\n Hint: Run the command `/re_addpost [URL]` in a Discord channel or `u/ByteDiceAssistant add_post` in a Reddit post.",
|
"dc_msg_re_post_404": "Post URL \"<{0}>\" not found: Post doesn't exist in the data!\n Hint: Run the command `/re_addpost [URL]` in a Discord channel or `u/ByteDiceAssistant add_post` in a Reddit post.",
|
||||||
"dc_msg_re_post_add_success": "Added post with URL \"<{0}>\"!",
|
"dc_msg_re_post_add_success": "Added post with URL \"<{0}>\"!",
|
||||||
|
"dc_msg_re_post_approve_remove": "Couldn't approve the post because it has been removed!",
|
||||||
"dc_msg_re_post_approve_success": "Successfully approved the post!",
|
"dc_msg_re_post_approve_success": "Successfully approved the post!",
|
||||||
"dc_msg_re_post_disapprove_success": "Successfully disapproved the post!",
|
"dc_msg_re_post_disapprove_success": "Successfully disapproved the post!",
|
||||||
"dc_msg_re_post_remove_success": "Successfully removed post with URL \"<{0}>\"!",
|
"dc_msg_re_post_remove_success": "Successfully removed post with URL \"<{0}>\"!",
|
||||||
"dc_msg_re_post_unremove_success": "Successfully restored post with URL \"<{0}>\"!",
|
"dc_msg_re_post_unremove_success": "Successfully restored post with URL \"<{0}>\"!",
|
||||||
"dc_msg_re_post_update_success": "Updated post with URL \"<{0}>\"!",
|
"dc_msg_re_post_update_success": "Updated post with URL \"<{0}>\"!",
|
||||||
|
"dc_msg_re_post_vote_removed_post": "Couldn't [vote / un-vote] the post because it has been removed!",
|
||||||
"dc_msg_re_posts_channel_404": "Could not find `re_posts_channel` in data!\nHint: Run `/admin_re_bindchannel` in a (preferably read-only) channel (requires administrator permission).",
|
"dc_msg_re_posts_channel_404": "Could not find `re_posts_channel` in data!\nHint: Run `/admin_re_bindchannel` in a (preferably read-only) channel (requires administrator permission).",
|
||||||
"dc_msg_re_vote_err": "Failed to [vote / un-vote]: Unknown internal error.",
|
"dc_msg_re_vote_err": "Failed to [vote / un-vote]: Unknown internal error.",
|
||||||
"dc_msg_re_vote_mod_success": "Successfully voted (as moderator vote)!",
|
"dc_msg_re_vote_mod_success": "Successfully voted (as moderator vote)!",
|
||||||
|
|||||||
+29
-21
@@ -1,10 +1,10 @@
|
|||||||
use crate::data::{get_mutex_data, update_re_data};
|
use crate::data::{get_mutex_data, get_toml_mutex, update_re_data};
|
||||||
use crate::messages::{make_post_embed, make_removed_embed, EmbedOptions};
|
use crate::messages::{make_post_embed, make_removed_embed, EmbedOptions};
|
||||||
use crate::re_cmds::generic_fns::{is_bk_mod, is_bk_mod_serenity, serenity_edit_msg_embed, serenity_send_msg};
|
use crate::re_cmds::generic_fns::{is_bk_mod, is_bk_mod_serenity, serenity_edit_msg_embed, serenity_send_msg};
|
||||||
use crate::websocket::send_cmd_json;
|
use crate::websocket::send_cmd_json;
|
||||||
use crate::{lang, rs_println, Data, Error, CFG_DATA_RE};
|
use crate::{lang, rs_println, Data, Error, CFG_DATA_RE};
|
||||||
|
|
||||||
use poise::serenity_prelude::{self as serenity, ActivityData, ComponentInteraction, Interaction, Member, Ready};
|
use poise::serenity_prelude::{self as serenity, ActivityData, ChannelId, ComponentInteraction, Interaction, Member, MessageId, Ready};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@@ -18,7 +18,7 @@ pub fn event_handler<'a>(
|
|||||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
|
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
match event {
|
match event {
|
||||||
serenity::FullEvent::Ready { data_about_bot } => on_ready(ctx, data_about_bot),
|
serenity::FullEvent::Ready { data_about_bot } => on_ready(ctx, data_about_bot, data).await,
|
||||||
serenity::FullEvent::InteractionCreate { interaction } => { let _ = handle_buttons(ctx, data, interaction).await; },
|
serenity::FullEvent::InteractionCreate { interaction } => { let _ = handle_buttons(ctx, data, interaction).await; },
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -27,15 +27,15 @@ pub fn event_handler<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_ready(ctx: &serenity::Context, data_about_bot: &Ready) {
|
async fn on_ready(ctx: &serenity::Context, data_about_bot: &Ready, data: &Data) {
|
||||||
rs_println!(
|
rs_println!(
|
||||||
"Bot started as user \"{}\" with id {}",
|
"Bot started as user \"{}\" with id {}",
|
||||||
data_about_bot.user.name,
|
data_about_bot.user.name,
|
||||||
data_about_bot.user.id
|
data_about_bot.user.id
|
||||||
);
|
);
|
||||||
|
|
||||||
let file_text = std::fs::read_to_string("./cfg/status.txt").unwrap();
|
let m_data = get_toml_mutex(&data.cfg).await.unwrap();
|
||||||
let custom_activity = ActivityData::custom(file_text);
|
let custom_activity = ActivityData::custom(m_data["general"]["status"].as_str().unwrap());
|
||||||
|
|
||||||
ctx.online();
|
ctx.online();
|
||||||
ctx.set_activity(Some(custom_activity));
|
ctx.set_activity(Some(custom_activity));
|
||||||
@@ -65,6 +65,16 @@ async fn handle_buttons(ctx: &serenity::Context, data: &Data, interaction: &Inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn update_embed(ctx: &serenity::Context, url: &str, new_data: &Value, c_id: &ChannelId, m_id: &MessageId) {
|
||||||
|
let e: EmbedOptions;
|
||||||
|
let remove = new_data["removed"]["removed"].as_bool().unwrap();
|
||||||
|
if remove { e = make_removed_embed(new_data, url, true); }
|
||||||
|
else { e = make_post_embed (new_data, url, true); }
|
||||||
|
|
||||||
|
serenity_edit_msg_embed(ctx, &c_id, &m_id, e).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn approve_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, component: &ComponentInteraction, url: String, approve: bool) -> Result<(), Error> {
|
async fn approve_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, component: &ComponentInteraction, url: String, approve: bool) -> Result<(), Error> {
|
||||||
if !is_bk_mod_serenity(ctx, data, c_member, component).await { return Ok(()); }
|
if !is_bk_mod_serenity(ctx, data, c_member, component).await { return Ok(()); }
|
||||||
|
|
||||||
@@ -73,13 +83,11 @@ async fn approve_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, co
|
|||||||
let c_id = component.channel_id;
|
let c_id = component.channel_id;
|
||||||
let m_id = component.message.id;
|
let m_id = component.message.id;
|
||||||
|
|
||||||
if r["value"].as_bool().unwrap() {
|
|
||||||
update_re_data(data).await;
|
update_re_data(data).await;
|
||||||
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
||||||
let e = make_post_embed(new_data, &url, true);
|
update_embed(ctx, &url, new_data, &c_id, &m_id).await;
|
||||||
|
|
||||||
serenity_edit_msg_embed(ctx, &c_id, &m_id, e).await;
|
|
||||||
|
|
||||||
|
if r["value"].as_bool().unwrap() {
|
||||||
if approve {
|
if approve {
|
||||||
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_approve_success"), true).await;
|
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_approve_success"), true).await;
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,9 @@ async fn approve_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, co
|
|||||||
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_disapprove_success"), true).await;
|
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_disapprove_success"), true).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_approve_remove"), true).await;
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -107,15 +118,11 @@ async fn remove_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, com
|
|||||||
let c_id = component.channel_id;
|
let c_id = component.channel_id;
|
||||||
let m_id = component.message.id;
|
let m_id = component.message.id;
|
||||||
|
|
||||||
if r["value"].as_bool().unwrap() {
|
|
||||||
update_re_data(data).await;
|
update_re_data(data).await;
|
||||||
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
||||||
let e: EmbedOptions;
|
update_embed(ctx, &url, new_data, &c_id, &m_id).await;
|
||||||
if remove { e = make_removed_embed(new_data, &url, true); }
|
|
||||||
else { e = make_post_embed (new_data, &url, true); }
|
|
||||||
|
|
||||||
serenity_edit_msg_embed(ctx, &c_id, &m_id, e).await;
|
|
||||||
|
|
||||||
|
if r["value"].as_bool().unwrap() {
|
||||||
if remove {
|
if remove {
|
||||||
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_remove_success", &url), true).await;
|
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_remove_success", &url), true).await;
|
||||||
}
|
}
|
||||||
@@ -137,13 +144,11 @@ async fn vote_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, compo
|
|||||||
let c_id = component.channel_id;
|
let c_id = component.channel_id;
|
||||||
let m_id = component.message.id;
|
let m_id = component.message.id;
|
||||||
|
|
||||||
if r["value"].as_bool().unwrap() {
|
|
||||||
update_re_data(data).await;
|
update_re_data(data).await;
|
||||||
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
let new_data = &get_mutex_data(&data.reddit_data).await.unwrap()[CFG_DATA_RE][&url];
|
||||||
let e = make_post_embed(new_data, &url, true);
|
update_embed(ctx, &url, new_data, &c_id, &m_id).await;
|
||||||
|
|
||||||
serenity_edit_msg_embed(ctx, &c_id, &m_id, e).await;
|
|
||||||
|
|
||||||
|
if r["value"].as_bool().unwrap() {
|
||||||
if vote {
|
if vote {
|
||||||
if is_mod { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_mod_success"), true).await; }
|
if is_mod { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_mod_success"), true).await; }
|
||||||
else { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_success"), true).await; }
|
else { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_success"), true).await; }
|
||||||
@@ -153,7 +158,10 @@ async fn vote_btn(ctx: &serenity::Context, data: &Data, c_member: &Member, compo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if !vote { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_remove_havent"), true).await; }
|
if new_data["removed"]["removed"].as_bool().unwrap() {
|
||||||
|
serenity_send_msg(ctx, component, lang!("dc_msg_re_post_vote_removed_post"), true).await;
|
||||||
|
}
|
||||||
|
else if !vote { serenity_send_msg(ctx, component, lang!("dc_msg_re_vote_remove_havent"), true).await; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
+3
-1
@@ -164,8 +164,10 @@ async fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if !args.nosched {
|
if !args.nosched {
|
||||||
|
let dur = if args.test { Duration::from_secs(60) } else { Duration::from_secs(60 * 10) };
|
||||||
|
|
||||||
let schedules: Vec<Schedule> = vec![
|
let schedules: Vec<Schedule> = vec![
|
||||||
(Duration::from_secs(2 * 60), || Box::pin(read_reddit_inbox()))
|
(dur, || Box::pin(read_reddit_inbox()))
|
||||||
];
|
];
|
||||||
|
|
||||||
run_schedules(schedules).await;
|
run_schedules(schedules).await;
|
||||||
|
|||||||
+23
-6
@@ -23,19 +23,30 @@ pub async fn start(args: Args) -> PyResult<()> {
|
|||||||
let py_args = args_str.replace(":true", ":True").replace(":false", ":False");
|
let py_args = args_str.replace(":true", ":True").replace(":false", ":False");
|
||||||
let app_path = CString::new(format!("args = {}\n{}", py_args, code)).unwrap();
|
let app_path = CString::new(format!("args = {}\n{}", py_args, code)).unwrap();
|
||||||
|
|
||||||
|
let mut traceback: String = String::new();
|
||||||
|
let mut is_error = false;
|
||||||
|
|
||||||
pyo3::prepare_freethreaded_python();
|
pyo3::prepare_freethreaded_python();
|
||||||
|
|
||||||
let from_python = Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
let _ = Python::with_gil(|py| -> Result<(), PyErr> {
|
||||||
let syspath = py.import("sys")?.getattr("path")?.downcast_into::<PyList>()?;
|
let syspath = py.import("sys")?.getattr("path")?.downcast_into::<PyList>()?;
|
||||||
syspath.insert(0, path)?;
|
syspath.insert(0, path)?;
|
||||||
let empty = CString::new("").unwrap();
|
let empty = CString::new("").unwrap();
|
||||||
|
|
||||||
let app: Py<PyAny> = PyModule::from_code(py, &app_path, &empty, &empty)?.into();
|
let py_result = PyModule::from_code(py, &app_path, &empty, &empty);
|
||||||
|
|
||||||
return Ok(app);
|
if let Err(ref e) = py_result {
|
||||||
|
traceback = py.import("traceback")?
|
||||||
|
.call_method1("format_exception", (e.get_type(py), e.value(py), e.traceback(py)))?
|
||||||
|
.extract::<Vec<String>>()?
|
||||||
|
.join("");
|
||||||
|
is_error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
});
|
});
|
||||||
|
|
||||||
if from_python.is_err() {
|
if is_error {
|
||||||
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
|
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
|
||||||
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
|
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
|
||||||
let own_vec_u64: Vec<u64> = own_vec_str
|
let own_vec_u64: Vec<u64> = own_vec_str
|
||||||
@@ -43,9 +54,15 @@ pub async fn start(args: Args) -> PyResult<()> {
|
|||||||
.map(|s| s.parse::<u64>().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax."))
|
.map(|s| s.parse::<u64>().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax."))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
send_dm(lang!("dc_msg_dm_python_err", format!("{:?}", from_python)), args, own_vec_u64).await;
|
send_dm(
|
||||||
errln!("pyO3: {:?}", from_python);
|
lang!("dc_msg_dm_python_err", format!("{}", traceback)),
|
||||||
|
args,
|
||||||
|
own_vec_u64
|
||||||
|
).await;
|
||||||
|
|
||||||
|
errln!("pyO3: {}", traceback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -37,12 +37,13 @@ class Bot:
|
|||||||
password = self.password,
|
password = self.password,
|
||||||
user_agent = self.useragent
|
user_agent = self.useragent
|
||||||
)
|
)
|
||||||
|
self.sr_list: list[str] = ["bytedicetesting"]
|
||||||
self.sr = None
|
self.sr = None
|
||||||
self.data_f: TextIOWrapper = None
|
self.data_f: TextIOWrapper = None
|
||||||
self.data: dict = {}
|
self.data: dict = {}
|
||||||
|
|
||||||
async def initialize(self):
|
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):
|
async def set_args(self, args: dict):
|
||||||
self.args = args
|
self.args = args
|
||||||
@@ -57,11 +58,13 @@ class Bot:
|
|||||||
|
|
||||||
async def update_cfg_str(self, new_cfg: str) -> bool:
|
async def update_cfg_str(self, new_cfg: str) -> bool:
|
||||||
json_cfg = toml.loads(new_cfg)
|
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"]
|
self.fetch_limit = json_cfg[CFG_DATA_RE]["fetch_limit"]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def update_cfg(self, new_cfg: dict) -> bool:
|
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"]
|
self.fetch_limit = new_cfg[CFG_DATA_RE]["fetch_limit"]
|
||||||
return True
|
return True
|
||||||
+13
-16
@@ -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 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:
|
if not mention.new:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -33,13 +33,15 @@ async def respond_to_mention(bot: botPy.Bot) -> bool:
|
|||||||
await bk_week_add(mention, bot)
|
await bk_week_add(mention, bot)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
py_print("Mention was not a command.")
|
||||||
await mention.mark_read()
|
await mention.mark_read()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
|
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()
|
await mention.mark_read()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -58,23 +60,18 @@ async def bk_week_add(mention: models.Comment, bot: botPy.Bot):
|
|||||||
|
|
||||||
r = ""
|
r = ""
|
||||||
bd = bot.data[botPy.RE_DATA_POSTS]
|
bd = bot.data[botPy.RE_DATA_POSTS]
|
||||||
|
|
||||||
if short_url not in bd:
|
if short_url not in bd:
|
||||||
posts.add_post_url(bot, short_url)
|
if not is_mod: r = "Successfully added your post to the weekly art submissions!"
|
||||||
r = "Successfully added this post to the data!"
|
if is_mod: r = "[MOD ACTION] Successfully added this post to the weekly art submissions!"
|
||||||
|
|
||||||
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:
|
else:
|
||||||
r = "[MOD ACTION] Successfully added this post to the data!"
|
if bd[short_url]["removed"]["removed"] and is_mod:
|
||||||
|
r = "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!"
|
||||||
post = await posts.from_url(bot, short_url)
|
elif not bd[short_url]["removed"]["removed"]:
|
||||||
post_data = posts.get_post_details(post[1])
|
r = "Couldn't add this post to the submissions! Luckily, it's already there!"
|
||||||
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 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 + " Thank you for participating!" + "\n\n" + BOT_ACTION_POSTFIX)
|
||||||
await mention.mark_read()
|
await mention.mark_read()
|
||||||
+9
-3
@@ -9,7 +9,7 @@ from macros import *
|
|||||||
|
|
||||||
DATA_PATH = os.path.join(os.path.join(os.getcwd(), "data"))
|
DATA_PATH = os.path.join(os.path.join(os.getcwd(), "data"))
|
||||||
DB_PATH = os.path.join(DATA_PATH, "db")
|
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"))
|
CFG_PATH = os.path.join(os.path.join(os.getcwd(), "cfg"))
|
||||||
|
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ def read_data(bot: botPy.Bot) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
py_print("re_data.json not found, creating new from preset...")
|
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 = json.load(f)
|
||||||
|
|
||||||
data_preset_json[botPy.RE_DATA_POSTS].pop("EXAMPLE VALUE", None)
|
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)")
|
if bot.args["dev"]: py_print(f"Added post \"{new_data.url}\" (Conditions bypassed)")
|
||||||
return True
|
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()
|
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}\"")
|
if bot.args["dev"]: py_print(f"Added post \"{new_data.url}\"")
|
||||||
return True
|
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:
|
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"]:
|
if not bot.data[botPy.RE_DATA_POSTS][url]["removed"]["removed"]:
|
||||||
bot.data[botPy.RE_DATA_POSTS][url]["approved"]["by_human"] = approved
|
bot.data[botPy.RE_DATA_POSTS][url]["approved"]["by_human"] = approved
|
||||||
return True
|
return True
|
||||||
@@ -206,6 +209,9 @@ def set_vote_post(
|
|||||||
if url not in bot.data[botPy.RE_DATA_POSTS]:
|
if url not in bot.data[botPy.RE_DATA_POSTS]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if bot.data[botPy.RE_DATA_POSTS][url]["removed"]["removed"]:
|
||||||
|
return False
|
||||||
|
|
||||||
votes = bot.data[botPy.RE_DATA_POSTS][url]["votes"]
|
votes = bot.data[botPy.RE_DATA_POSTS][url]["votes"]
|
||||||
re_voters: set[str] = set(votes["voters_re"])
|
re_voters: set[str] = set(votes["voters_re"])
|
||||||
dc_voters: set[int] = set(votes["voters_dc"])
|
dc_voters: set[int] = set(votes["voters_dc"])
|
||||||
|
|||||||
Reference in New Issue
Block a user