things
This commit is contained in:
@@ -11,16 +11,17 @@ An automation tool for Byte Dice. It's both a Discord and Reddit bot in one prog
|
|||||||
|
|
||||||
## How to run
|
## How to run
|
||||||
**Dependecies:** This program uses Rust (v1.82.0) and Python (v3.11.4), you can likely use other versions if they are compatible. This program also uses these Python modules:
|
**Dependecies:** This program uses Rust (v1.82.0) and Python (v3.11.4), you can likely use other versions if they are compatible. This program also uses these Python modules:
|
||||||
<!-- TODO: update with all python modules (not just external) -->
|
|
||||||
* sys
|
|
||||||
* io
|
|
||||||
* asyncpraw
|
|
||||||
* json
|
|
||||||
* typing
|
|
||||||
* asyncio
|
* asyncio
|
||||||
|
* asyncpraw
|
||||||
|
* asyncprawcore
|
||||||
|
* emoji
|
||||||
|
* io
|
||||||
|
* json
|
||||||
|
* os
|
||||||
|
* sys
|
||||||
* threading
|
* threading
|
||||||
* time
|
* time
|
||||||
* emoji
|
* typing
|
||||||
* websockets
|
* websockets
|
||||||
|
|
||||||
You can install Python modules by running `$ pip install {module}` or `$ python -m pip install {module}` in a terminal.
|
You can install Python modules by running `$ pip install {module}` or `$ python -m pip install {module}` in a terminal.
|
||||||
|
|||||||
+11
-4
@@ -1,22 +1,29 @@
|
|||||||
# Discord Commands
|
# Discord Commands
|
||||||
|
## `/bk_week_get [url]`
|
||||||
|
Shows info about a single post.
|
||||||
## `/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>`**: (OPTIONAL) `true` or `false`, determines whether to pre-approve the post.
|
- **`<approve>`**: (OPTIONAL) `true` or `false`, determines whether to approve the post when added.
|
||||||
## `/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] <disapprove>`
|
## `/bk_week_approve [url] <disapprove>`
|
||||||
Flags the post as **human_approved**, confirming that the artwork is original.
|
Flags the post as **human_approved**, confirming that the artwork is original.
|
||||||
- **`<disapprove>`**: (OPTIONAL) `true` or `false`, set to `true` if you want to undo an approval.
|
- **`<disapprove>`**: (OPTIONAL) `true` or `false`, set to `true` if you want to undo an approval.
|
||||||
## `/bk_week_update`
|
|
||||||
Updates all data in the bound Discord channel. It's recommended to run this rarely.
|
|
||||||
## `/bk_week_vote [url] <remove_vote>`
|
## `/bk_week_vote [url] <remove_vote>`
|
||||||
Adds a vote to a post. The intended use for votes is for a "moderator picks" and a "community picks" section of the weekly art.
|
Adds a vote to a post. The intended use for votes is for a "moderator picks" and a "community picks" section of the weekly art.
|
||||||
You can vote on as many posts as you want, but only once per post.
|
You can vote on as many posts as you want, but only once per post.
|
||||||
|
## `/bk_week_update`
|
||||||
|
Updates all data in the bound Discord channel. It's recommended to only run this if absolutely needed to.
|
||||||
## `/bk_admin_bind`
|
## `/bk_admin_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`.
|
||||||
|
## `/bk_week_help [option]`
|
||||||
|
Shows a help text.
|
||||||
|
- **`[option]`**: `Discord` or `Reddit`, determines what help text to send.
|
||||||
### **Examples**
|
### **Examples**
|
||||||
```
|
```
|
||||||
/bk_week_add https://reddit.com/post_url false
|
/bk_week_add https://reddit.com/post_url false
|
||||||
/bk_week_add https://reddit.com/post_url
|
/bk_week_add https://reddit.com/post_url
|
||||||
/bk_week_approve https://reddit.com/post_url
|
/bk_week_approve https://reddit.com/post_url
|
||||||
```
|
```
|
||||||
|
# Things to note
|
||||||
|
* This bot uses shortURLs when storing posts. If you want to access posts, you should use their shortURL. You can get a Reddit shortURL by running `/re_shorturl [url]`.
|
||||||
+2
-5
@@ -1,12 +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 [cmd]` in a comment.
|
||||||
- **`[args]`**: The command you want to run and its arguments.
|
- **`[cmd]`**: 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.**
|
||||||
<!-- ## `bk_week_vote`
|
|
||||||
Adds a vote to the post. (see `/bk_week_vote` in the Discord help).
|
|
||||||
- **Anyone can use this command. If a moderator uses it the vote will be flagged as a moderator vote.** -->
|
|
||||||
### **Examples**
|
### **Examples**
|
||||||
```
|
```
|
||||||
"u/ByteDiceAssistant bk_week_add"
|
"u/ByteDiceAssistant bk_week_add"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
/bk_week_top - get the top posts in a category
|
||||||
+11
-7
@@ -1,5 +1,5 @@
|
|||||||
use crate::websocket::send_cmd_json;
|
use crate::websocket::send_cmd_json;
|
||||||
use crate::{rs_println, websocket, Context, Data, Error, BK_WEEK};
|
use crate::{cmds, rs_println, websocket, Context, Data, Error, BK_WEEK};
|
||||||
use crate::messages::*;
|
use crate::messages::*;
|
||||||
use crate::data::{self, dc_bind_bk};
|
use crate::data::{self, dc_bind_bk};
|
||||||
|
|
||||||
@@ -172,35 +172,38 @@ pub async fn bk_week_add(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let shorturl_u = cmds::to_shorturl(&url);
|
||||||
|
let shorturl = if shorturl_u.is_ok() { shorturl_u.unwrap() } else { url };
|
||||||
|
|
||||||
data::update_re_data(ctx.data()).await;
|
data::update_re_data(ctx.data()).await;
|
||||||
let reddit_data = get_reddit_data(ctx.data()).await.unwrap();
|
let reddit_data = get_reddit_data(ctx.data()).await.unwrap();
|
||||||
|
|
||||||
if let Some(bk_week) = reddit_data.get(BK_WEEK) {
|
if let Some(bk_week) = reddit_data.get(BK_WEEK) {
|
||||||
let a = approve.unwrap_or_else(|| false);
|
let a = approve.unwrap_or_else(|| false);
|
||||||
let r = websocket::send_cmd_json("add_post_url", Some(json!([&url, a, true]))).await.unwrap();
|
let r = websocket::send_cmd_json("add_post_url", Some(json!([&shorturl, a, true]))).await.unwrap();
|
||||||
|
|
||||||
if !r["value"].as_bool().unwrap() {
|
if !r["value"].as_bool().unwrap() {
|
||||||
send_msg(
|
send_msg(
|
||||||
ctx,
|
ctx,
|
||||||
r#"Unknown error!
|
r#"Unknown error!
|
||||||
Error trace: `bk_week_cmds.rs -> bk_week_add() -> Unknown error`.
|
Error trace: `bk_week_cmds.rs -> bk_week_add() -> Unknown error`.
|
||||||
Common reason: The URL provided was likely invalid."#.to_string(),
|
Common reasons: The URL provided was likely invalid or 403: forbidden (e.g a private subreddit)."#.to_string(),
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
).await;
|
).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(post) = bk_week.get(&url) {
|
if let Some(post) = bk_week.get(&shorturl) {
|
||||||
if post.get("removed").is_some() {
|
if post.get("removed").is_some() {
|
||||||
send_unremove_msg(ctx, &url).await;
|
send_unremove_msg(ctx, &shorturl).await;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send_updated_msg(ctx, &url).await;
|
send_updated_msg(ctx, &shorturl).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send_msg(ctx, format!("Added post with URL \"<{}>\"!", &url), true, true).await;
|
send_msg(ctx, format!("Added post with URL \"<{}>\"!", &shorturl), true, true).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
if a {
|
if a {
|
||||||
@@ -284,6 +287,7 @@ async fn approve_cmd(ctx: Context<'_>, url: &str, reddit_data: &Value, approve:
|
|||||||
if let Some(post) = reddit_data.get(BK_WEEK).unwrap().get(&url) {
|
if let Some(post) = reddit_data.get(BK_WEEK).unwrap().get(&url) {
|
||||||
if post.get("removed").is_some() {
|
if post.get("removed").is_some() {
|
||||||
send_post_removed_message(ctx, &url, post.get("removed_by").unwrap().as_str().unwrap()).await;
|
send_post_removed_message(ctx, &url, post.get("removed_by").unwrap().as_str().unwrap()).await;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let r = websocket::send_cmd_json("set_approve_post", Some(json!([approve, &url]))).await.unwrap();
|
let r = websocket::send_cmd_json("set_approve_post", Some(json!([approve, &url]))).await.unwrap();
|
||||||
|
|||||||
+1
-1
@@ -165,7 +165,7 @@ pub async fn re_shorturl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn to_shorturl(url: &str) -> Result<String, &str> {
|
pub fn to_shorturl(url: &str) -> Result<String, &str> {
|
||||||
let re = Regex::new(r"comments/([a-zA-Z0-9]+)").unwrap();
|
let re = Regex::new(r"comments/([a-zA-Z0-9]+)").unwrap();
|
||||||
|
|
||||||
if let Some(caps) = re.captures(url) {
|
if let Some(caps) = re.captures(url) {
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ pub async fn dc_add_server(data: &Data, server_id: u64) -> Result<(), ()> {
|
|||||||
if !servers.contains_key(&server_id.to_string()) {
|
if !servers.contains_key(&server_id.to_string()) {
|
||||||
servers.insert(server_id.to_string(), json!({ "bk_week_channel": 0, "bk_mod_role": "bk mod", "bk_mods": [] }));
|
servers.insert(server_id.to_string(), json!({ "bk_week_channel": 0, "bk_mod_role": "bk mod", "bk_mods": [] }));
|
||||||
}
|
}
|
||||||
println!("moo");
|
|
||||||
write_dc_data(data).await;
|
|
||||||
println!("muu");
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -141,7 +138,6 @@ pub async fn dc_bind_bk(data: &Data, server_id: u64, channel_id: u64) -> Result<
|
|||||||
let server = servers[&server_id.to_string()].as_object_mut().unwrap();
|
let server = servers[&server_id.to_string()].as_object_mut().unwrap();
|
||||||
|
|
||||||
server.insert("bk_week_channel".to_string(), channel_id.into());
|
server.insert("bk_week_channel".to_string(), channel_id.into());
|
||||||
write_dc_data(data).await;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ class Bot:
|
|||||||
self.data: dict = {}
|
self.data: dict = {}
|
||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
self.sr = await self.r.subreddit("bytedicetesting")#boykisser")
|
self.sr = await self.r.subreddit("bytedicetesting")
|
||||||
|
|
||||||
async def set_args(self, args: dict):
|
async def set_args(self, args: dict):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,3 @@
|
|||||||
import asyncpraw as praw
|
|
||||||
import asyncpraw.models as models
|
import asyncpraw.models as models
|
||||||
|
|
||||||
from macros import *
|
from macros import *
|
||||||
@@ -40,6 +39,10 @@ async def respond_to_mention(bot: botPy.Bot) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
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:
|
||||||
|
await mention.mark_read()
|
||||||
|
return
|
||||||
|
|
||||||
await mention.submission.load()
|
await mention.submission.load()
|
||||||
|
|
||||||
author = mention.author
|
author = mention.author
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ async def from_url(bot: botPy.Bot, url: str) -> tuple[bool, models.Submission]:
|
|||||||
try:
|
try:
|
||||||
post: models.Submission = await bot.r.submission(url=url)
|
post: models.Submission = await bot.r.submission(url=url)
|
||||||
return True, post
|
return True, post
|
||||||
except (prawcore.NotFound, prawcore.BadRequest, exc.InvalidURL):
|
except (prawcore.NotFound, prawcore.BadRequest, exc.InvalidURL, prawcore.Forbidden):
|
||||||
return False, None
|
return False, None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
py_error(f"Unexpected error at posts.py -> from_url():\n{e}")
|
py_error(f"Unexpected error at posts.py -> from_url():\n{e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user