bug fixing
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<!-- - [x] ~~Multithread so it can run both Discord and Reddit bot!!!~~ -->¨
|
||||
<!-- - [x] Security that only allows bk mods to run these commands. -->
|
||||
<!-- - [x] Some kind of voting system. -->
|
||||
- [ ] `/bk_week_top [category] [amount]` to get the top N posts in a category (e.g upvotes)
|
||||
- [ ] Allow updating the data autonomously and via manual commands.
|
||||
- [ ] 30-minute schedule when bot adds posts
|
||||
- [ ] Manually add posts
|
||||
|
||||
+9
-8
@@ -472,8 +472,6 @@ async fn read_msgs(ctx: Context<'_>, c_id: u64) -> Vec<Message> {
|
||||
}
|
||||
|
||||
|
||||
// TODO: all posts get updated for some reason (i think, debug print pls)
|
||||
// TODO: also doesn't edit messages if they got removed
|
||||
async fn msgs_to_json<'a>(msgs: Vec<Message>, reddit_data: &'a Value) -> Value {
|
||||
let mut msgs_json: Value = json!({"no_change": {}, "updated": {}, "removed": {}, "duplicates": {}});
|
||||
|
||||
@@ -488,8 +486,9 @@ async fn msgs_to_json<'a>(msgs: Vec<Message>, reddit_data: &'a Value) -> Value {
|
||||
.any(|key| msgs_json[key].as_object().unwrap().contains_key(&url))
|
||||
{
|
||||
let dupes_mut = msgs_json["duplicates"].as_object_mut().unwrap();
|
||||
if !dupes_mut.contains_key(&url) { dupes_mut.insert(url.clone(), json!([])); }
|
||||
dupes_mut[&url].as_array_mut().unwrap().push(json!(msg.id.get()));
|
||||
if !dupes_mut.contains_key(&url) {
|
||||
dupes_mut.insert(url.clone(), json!(msg.id.get()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -508,10 +507,9 @@ async fn msgs_to_json<'a>(msgs: Vec<Message>, reddit_data: &'a Value) -> Value {
|
||||
let re_url = &reddit_data["bk_weekly_art_posts"][&url];
|
||||
|
||||
if re_url.get("removed").is_some() {
|
||||
if msgs_json.get("removed").is_some() {
|
||||
if u_json.get("removed").is_some() {
|
||||
if let Some(obj) = msgs_json["no_change"].as_object_mut() {
|
||||
obj.insert(url.clone(), json!(msg.id.get()));
|
||||
obj.insert(url.clone(), u_json.clone());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -525,7 +523,7 @@ async fn msgs_to_json<'a>(msgs: Vec<Message>, reddit_data: &'a Value) -> Value {
|
||||
if u_json["added"] != re_url["added"]
|
||||
|| u_json["approved"] != re_url["approved"]
|
||||
|| u_json["post_data"]["upvotes"] != re_url["post_data"]["upvotes"]
|
||||
|| u_json["votes"] != re_url["votes"]
|
||||
|| u_json["votes"]["mod_voters"] != re_url["votes"]["mod_voters"]
|
||||
{
|
||||
u_json.as_object_mut().unwrap().insert("msg_id".to_string(), Value::String(msg.id.clone().to_string()));
|
||||
|
||||
@@ -537,7 +535,6 @@ async fn msgs_to_json<'a>(msgs: Vec<Message>, reddit_data: &'a Value) -> Value {
|
||||
|
||||
if let Some(obj) = msgs_json["no_change"].as_object_mut() {
|
||||
obj.insert(url.clone(), json!(msg.id.get()));
|
||||
obj.insert(url, u_json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,6 +561,10 @@ pub async fn bk_week_vote(
|
||||
send_post_not_found_message(ctx, &url).await;
|
||||
return Ok(());
|
||||
}
|
||||
if post_data[&url].get("removed").is_some() {
|
||||
send_post_removed_message(ctx, &url, post_data[&url]["removed_by"].as_str().unwrap()).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let url_data = &post_data[&url];
|
||||
|
||||
|
||||
+12
-19
@@ -159,8 +159,6 @@ pub async fn send_dm(msg: String, args: Args) {
|
||||
|
||||
pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions {
|
||||
let media_type = &post_data["post_data"]["media_type"];
|
||||
let re_votes = &post_data["votes"]["voters_re"].as_array().unwrap().len();
|
||||
let dc_votes = &post_data["votes"]["voters_dc"].as_array().unwrap().len();
|
||||
|
||||
let desc_str = format!(
|
||||
r#"Sorted by what I think will be most important
|
||||
@@ -168,28 +166,16 @@ pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions
|
||||
## Post Data:
|
||||
**Media type:** `{}`
|
||||
**Post upvotes:** ||`{:>6}`||
|
||||
**URL:** ||<{}>||
|
||||
**Media URLS:**
|
||||
{}
|
||||
|
||||
## Voting data:
|
||||
**Moderator votes:** ||`{:>6}`||
|
||||
**Community votes:** ||`{:>6}`||
|
||||
* ||**From Reddit:** `{:>6}`||
|
||||
* ||**From Discord:** `{:>6}`||
|
||||
**URL:** ||<{}>||
|
||||
|
||||
## Listing Data:
|
||||
**Added by:** `{{ human: {}, bot: {} }}`
|
||||
**Approved by:** `{{ human: {}, bot: [not implemented] }}`"#,
|
||||
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::<Vec<_>>().join("\n"),
|
||||
|
||||
post_data["votes"]["mod_voters"].as_array().unwrap().len(),
|
||||
re_votes + dc_votes,
|
||||
re_votes,
|
||||
dc_votes,
|
||||
url,
|
||||
|
||||
if post_data["added"] ["by_human"].as_bool().unwrap() { "✅" } else { "❌" },
|
||||
if post_data["added"] ["by_bot"].as_bool().unwrap() { "✅" } else { "❌" },
|
||||
@@ -202,7 +188,12 @@ pub fn embed_post(post_data: &Value, url: &str, empheral: bool) -> EmbedOptions
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
let json_min = json!({"post_data": json!({ "upvotes": post_data["post_data"]["upvotes"] }), "added": post_data["added"], "approved": post_data["approved"]});
|
||||
let json_min = json!(
|
||||
{"post_data": json!({ "upvotes": post_data["post_data"]["upvotes"] }),
|
||||
"added": post_data["added"],
|
||||
"approved": post_data["approved"],
|
||||
"votes": json!({"mod_voters": post_data["votes"]["mod_voters"]})}
|
||||
);
|
||||
let media_urls = post_data["post_data"]["media_urls"].as_array().unwrap();
|
||||
|
||||
return EmbedOptions {
|
||||
@@ -224,9 +215,11 @@ pub fn embed_post_removed(post_data: &Value, url: &str, empheral: bool) -> Embed
|
||||
return EmbedOptions {
|
||||
title: Some("REMOVED!".to_string()),
|
||||
desc: format!(
|
||||
"## Removed by `{}`\n**Reason:** {}\n\nJSON: ||`{}`||",
|
||||
"## Removed by `{}`\n**Reason:** {}\nURL: ||<{}>||\n\nJSON: ||`{}`||",
|
||||
post_data["removed_by"].as_str().unwrap(),
|
||||
post_data["remove_reason"].as_str().unwrap(),
|
||||
if !post_data["remove_reason"].is_null() { post_data["remove_reason"].as_str().unwrap() }
|
||||
else { "None" },
|
||||
url,
|
||||
serde_json::to_string(&post_data).unwrap()
|
||||
),
|
||||
col: Some(REMOVED_DC_COL),
|
||||
|
||||
Reference in New Issue
Block a user