diff --git a/bk_week_help_dc.md b/bk_week_help_dc.md index fe246b5..d258f78 100644 --- a/bk_week_help_dc.md +++ b/bk_week_help_dc.md @@ -2,19 +2,16 @@ ## `/bk_week_add [url] [approve]` Adds a URL to the list of posts. This is done automatically by the bot for certain posts. - **`[approve]`**: `true` or `false`, determines whether to pre-approve the post. - ## `/bk_week_remove [url]` Removes an existing URL from the list of posts. - ## `/bk_week_approve [url]` Flags the post as **human_approved**, confirming that the artwork is original. - ## `/bk_week_disapprove [url]` Reverses the effect of `/bk_week_approve`. - +## `/bk_week_update` +Updates all data in the binded Discord channel. It's reccommended to run this rarely. ## `/bk_week_bind` Binds the current channel as the channel where the bk_week data is sent and updated in. No binding means the only way to view the data is using `/bk_week_get`. - ### **Examples** ``` /bk_week_add https://reddit.com/post_url false diff --git a/bk_week_help_re.md b/bk_week_help_re.md index 0b36b92..04f0ae8 100644 --- a/bk_week_help_re.md +++ b/bk_week_help_re.md @@ -1,11 +1,9 @@ # Reddit Commands -To execute a command on the Reddit bot, include `u/ByteDiceAssistant [args]` in a comment. +To execute a command on the Reddit bot, include `u/ByteDiceAssistant [args]` in a comment. - **`[args]`**: The command you want to run and its arguments. - ## `bk_week_add` -Adds the post to the list of posts. -- **Only moderators of a subreddit or the OP (Original Poster) can use this command.** - +Adds the post to the list of posts. +- **Only moderators of a subreddit or the OP (Original Poster) can use this command.** ### **Examples** ``` "u/ByteDiceAssistant bk_week_add" diff --git a/src/bk_week_cmds.rs b/src/bk_week_cmds.rs index d2beb71..e66a99c 100644 --- a/src/bk_week_cmds.rs +++ b/src/bk_week_cmds.rs @@ -162,7 +162,14 @@ pub async fn bk_week_add( let r = websocket::send_cmd_json("add_post_url", json!([&url, a])).await.unwrap(); if !r["value"].as_bool().unwrap() { - send_msg(ctx, "Unknown error!\nError trace: `bk_week_cmds.rs -> bk_week_add() -> Unknown error`.".to_string(), true, true).await; + send_msg( + ctx, + r#"Unknown error! + Error trace: `bk_week_cmds.rs -> bk_week_add() -> Unknown error`. + Common reason: The URL provided was likely invalid."#.to_string(), + true, + true + ).await; return Ok(()); } diff --git a/src/main.rs b/src/main.rs index 601ee4c..51adb76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,9 @@ struct Args { #[arg(short = 'w', long, help = "Wipes all data before running the program.")] wipe: bool, #[arg(short = 't', long, help = "Makes the program use the ASSISTANT_TOKEN_TEST env var instead of ASSISTANT_TOKEN. This env var should hold the token of a non-production bot.")] - test: bool + test: bool, + #[arg(long, help = "Removes the annoying ping prints.")] + noping: bool } struct Data { diff --git a/src/messages.rs b/src/messages.rs index 6b1d321..d82bac3 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -136,6 +136,7 @@ pub async fn edit_msg( pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions { + let media_type = &post_data["post_data"]["media_type"]; let desc_str = format!( r#"Sorted by what I think will be most important Spoilers and vote length anonymizer for fair review! @@ -148,7 +149,7 @@ pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions ## Listing Data: **Added by:** `{{ human: {}, bot: {} }}` **Approved by:** `{{ human: {}, bot: [not implemented] }}`"#, - post_data["post_data"]["media_type"].as_str().unwrap(), + if !media_type.is_null() { media_type.as_str().unwrap() } else { "None" }, post_data["post_data"]["upvotes"].as_i64().unwrap(), url, post_data["post_data"]["media_urls"].as_array().unwrap().iter().map(|s| format!("* ||<{}>||", s.as_str().unwrap())).collect::>().join("\n"), diff --git a/src/python/posts.py b/src/python/posts.py index 578f59e..e104417 100644 --- a/src/python/posts.py +++ b/src/python/posts.py @@ -1,5 +1,7 @@ import emoji from asyncpraw import models +import asyncprawcore as prawcore +import asyncpraw.exceptions as exc import data import bot as botPy @@ -93,11 +95,13 @@ def has_media(post: models.Submission) -> tuple[bool, str, int, list[str]]: async def from_url(bot: botPy.Bot, url: str) -> tuple[bool, models.Submission]: - post: models.Submission = await bot.r.submission(url=url) - - if hasattr(post, "id"): + try: + post: models.Submission = await bot.r.submission(url=url) return True, post - else: + except (prawcore.NotFound, prawcore.BadRequest, exc.InvalidURL): + return False, None + except Exception as e: + py_error(f"Unexpected error at posts.py -> from_url():\n{e}") return False, None @@ -119,7 +123,7 @@ async def add_post_url(bot, url: str, approve: bool) -> bool: result, post = await from_url(bot, url) if not result: - return result + return False post_data = get_post_details(post) post_data.approved_by_human = approve diff --git a/src/websocket.rs b/src/websocket.rs index 7e2808f..5a9b5a1 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -133,12 +133,12 @@ async fn handle_message(msg: tungstenite::protocol::Message, args: Args) { } } tungstenite::Message::Binary(bytes) => { - if args.dev { + if args.dev && !args.noping { rs_println!("[Binary] from Python: {:?}", bytes); } } _ => { - if args.dev { + if args.dev && !args.noping { rs_println!("Received from Python: [UNKNOWN / OTHER]"); } }