From 2774b56e30c962113262e937666317045cd1e959 Mon Sep 17 00:00:00 2001 From: ByteDice Date: Sun, 2 Mar 2025 02:08:09 +0100 Subject: [PATCH] removed unnessesary env var (untested) --- README.md | 4 ++-- src/main.rs | 3 --- src/messages.rs | 26 ++++++++++++++------------ src/websocket.rs | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index af17665..08e4de0 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ You can install Python modules by running `$ pip install {module}` or `$ python | --- | --- | | `ASSISTANT_TOKEN` | The Discord bot token. (Create a Discord bot [here](https://discord.com/developers/docs/intro)!) | | `ASSISTANT_TOKEN_TEST` | (Optional) A testing Discord bot token. This is only needed when the program is run with `-t` or `--test`. | -| `ASSISTANT_DM_USER` | (Optional) Your Discord user ID. The assistant will DM this user when *certain* errors occur. | | `ASSISTANT_R_ID` | The id for the Reddit bot/account. (Create a Reddit bot [here](https://www.reddit.com/prefs/apps)!) | | `ASSISTANT_R_TOKEN` | The token for the Reddit bot/account. | | `ASSISTANT_R_NAME` | The username of the Reddit bot/account. | | `ASSISTANT_R_PASS` | The password for the Reddit bot/account. | -| `ASSISTANT_OWNERS` | (OPTIONAL) A list of Discord user IDs that "own" the bot. Separate each ID with a single comma and **no** spaces. | +| `ASSISTANT_OWNERS` | (OPTIONAL) A list of Discord user IDs that "own" the bot. Separate each ID with a single comma and **no** spaces. This will allow the specified user IDs to run root commands such as `/stop`, it will also DM these users when *certain* errors occur. | +| `ASSISTANT_BK_WEEK_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for | ### Required permissions: **These are automatically set if you use the [official invite link](https://discord.com/oauth2/authorize?client_id=1212127255795335208&permissions=84992&integration_type=0&scope=bot).** diff --git a/src/main.rs b/src/main.rs index 2bd5325..59ff336 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,9 +32,6 @@ use tokio::time; use websocket::send_cmd_json; -// TODO: bot command permissions - - #[derive(Parser, Serialize, Clone)] struct Args { #[arg(short = 'p', long, default_value = "2920", help = "Sets the port number, e.g 2200.")] diff --git a/src/messages.rs b/src/messages.rs index 130a88e..c45d5cd 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -179,24 +179,26 @@ pub async fn http_edit_msg( pub async fn send_dm(msg: String, args: Args) { - let uid = env::var("ASSISTANT_DM_USER"); - if uid.is_err() { return; } + let uids = env::var("ASSISTANT_OWNERS"); + if uids.is_err() { return; } + + let uids_split: Vec = uids.unwrap() + .split(',') + .map(|s| s.to_string()) + .collect(); - let user = UserId::new(uid.unwrap().parse::().unwrap()); - - let token: String; - if !args.test { - token = std::env::var("ASSISTANT_TOKEN").expect("Missing ASSISTANT_TOKEN env var!"); - } - else { - token = std::env::var("ASSISTANT_TOKEN_TEST").expect("Missing ASSISTANT_TOKEN_TEST env var!"); - }; + let token: String = + if !args.test { std::env::var("ASSISTANT_TOKEN") .expect("Missing ASSISTANT_TOKEN env var!") } + else { std::env::var("ASSISTANT_TOKEN_TEST").expect("Missing ASSISTANT_TOKEN_TEST env var!") }; let http = Http::new(&token); let c_msg = CreateMessage::new().content(msg); - let _ = user.dm(http, c_msg).await; + for uid in uids_split { + let user = UserId::new(uid.parse::().unwrap()); + let _ = user.dm(http.as_ref(), c_msg.clone()).await; + } } diff --git a/src/websocket.rs b/src/websocket.rs index 22c9744..8fe5775 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -134,7 +134,7 @@ async fn handle_message(msg: tungstenite::protocol::Message, args: Args) { if text.starts_with("json:") { let t_json: Value = serde_json::from_str(&text[5..]).unwrap(); if t_json.get("error").is_some() { - send_dm("Internal Python error!".to_string(), args).await; + send_dm("Unknown internal Python error occurred!".to_string(), args).await; } }