bug fixes & help update

This commit is contained in:
2025-02-17 02:42:46 +01:00
parent 70126a5fd3
commit 53d5de35df
7 changed files with 29 additions and 20 deletions
+2 -5
View File
@@ -2,19 +2,16 @@
## `/bk_week_add [url] [approve]` ## `/bk_week_add [url] [approve]`
Adds a URL to the list of posts. This is done automatically by the bot for certain posts. 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. - **`[approve]`**: `true` or `false`, determines whether to pre-approve the post.
## `/bk_week_remove [url]` ## `/bk_week_remove [url]`
Removes an existing URL from the list of posts. Removes an existing URL from the list of posts.
## `/bk_week_approve [url]` ## `/bk_week_approve [url]`
Flags the post as **human_approved**, confirming that the artwork is original. Flags the post as **human_approved**, confirming that the artwork is original.
## `/bk_week_disapprove [url]` ## `/bk_week_disapprove [url]`
Reverses the effect of `/bk_week_approve`. 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` ## `/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`. 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** ### **Examples**
``` ```
/bk_week_add https://reddit.com/post_url false /bk_week_add https://reddit.com/post_url false
-2
View File
@@ -1,11 +1,9 @@
# Reddit Commands # 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. - **`[args]`**: The command you want to run and its arguments.
## `bk_week_add` ## `bk_week_add`
Adds the post to the list of posts. Adds the post to the list of posts.
- **Only moderators of a subreddit or the OP (Original Poster) can use this command.** - **Only moderators of a subreddit or the OP (Original Poster) can use this command.**
### **Examples** ### **Examples**
``` ```
"u/ByteDiceAssistant bk_week_add" "u/ByteDiceAssistant bk_week_add"
+8 -1
View File
@@ -162,7 +162,14 @@ pub async fn bk_week_add(
let r = websocket::send_cmd_json("add_post_url", json!([&url, a])).await.unwrap(); let r = websocket::send_cmd_json("add_post_url", json!([&url, a])).await.unwrap();
if !r["value"].as_bool().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(()); return Ok(());
} }
+3 -1
View File
@@ -40,7 +40,9 @@ struct Args {
#[arg(short = 'w', long, help = "Wipes all data before running the program.")] #[arg(short = 'w', long, help = "Wipes all data before running the program.")]
wipe: bool, 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.")] #[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 { struct Data {
+2 -1
View File
@@ -136,6 +136,7 @@ pub async fn edit_msg(
pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions { 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!( let desc_str = format!(
r#"Sorted by what I think will be most important r#"Sorted by what I think will be most important
Spoilers and vote length anonymizer for fair review! 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: ## Listing Data:
**Added by:** `{{ human: {}, bot: {} }}` **Added by:** `{{ human: {}, bot: {} }}`
**Approved by:** `{{ human: {}, bot: [not implemented] }}`"#, **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(), post_data["post_data"]["upvotes"].as_i64().unwrap(),
url, url,
post_data["post_data"]["media_urls"].as_array().unwrap().iter().map(|s| format!("* ||<{}>||", s.as_str().unwrap())).collect::<Vec<_>>().join("\n"), post_data["post_data"]["media_urls"].as_array().unwrap().iter().map(|s| format!("* ||<{}>||", s.as_str().unwrap())).collect::<Vec<_>>().join("\n"),
+9 -5
View File
@@ -1,5 +1,7 @@
import emoji import emoji
from asyncpraw import models from asyncpraw import models
import asyncprawcore as prawcore
import asyncpraw.exceptions as exc
import data import data
import bot as botPy 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]: async def from_url(bot: botPy.Bot, url: str) -> tuple[bool, models.Submission]:
post: models.Submission = await bot.r.submission(url=url) try:
post: models.Submission = await bot.r.submission(url=url)
if hasattr(post, "id"):
return True, post 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 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) result, post = await from_url(bot, url)
if not result: if not result:
return result return False
post_data = get_post_details(post) post_data = get_post_details(post)
post_data.approved_by_human = approve post_data.approved_by_human = approve
+2 -2
View File
@@ -133,12 +133,12 @@ async fn handle_message(msg: tungstenite::protocol::Message, args: Args) {
} }
} }
tungstenite::Message::Binary(bytes) => { tungstenite::Message::Binary(bytes) => {
if args.dev { if args.dev && !args.noping {
rs_println!("[Binary] from Python: {:?}", bytes); rs_println!("[Binary] from Python: {:?}", bytes);
} }
} }
_ => { _ => {
if args.dev { if args.dev && !args.noping {
rs_println!("Received from Python: [UNKNOWN / OTHER]"); rs_println!("Received from Python: [UNKNOWN / OTHER]");
} }
} }