diff --git a/README.md b/README.md index acb926c..25decfc 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,16 @@ This program uses Rust (v1.82.0) and Python (v3.11.4), you can likely use other You can install Python modules by running `$ pip install {module}` or `$ python -m pip install {module}` in a terminal. ### Environment variables: -| **Name** | **Description** | -| --- | --- | -| `ASSISTANT_TOKEN` | The Discord bot token. (Create a Discord bot [here](https://discord.com/developers/docs/intro)!) | +| **Name** | **Description** | +| ---------------------- | --- | +| `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_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. 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_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for people who are allowed to use the `/re_*` commands. | +| `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. 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_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for people who are allowed to use the `/re_*` commands. | ### 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) or an invite link with the permissions integer set to `84992`.** (The permission integer is this part of the URL `&permissions=84992`) @@ -59,7 +59,7 @@ You can install Python modules by running `$ pip install {module}` or `$ python * For help, run `cargo run -- -h` or `cargo run -- --help`. * To only run the Python part, use `cargo run -- --py`, or for a better error output, `python ./src/python/main.py` -### Long answer for absolute beginners: +### Long answer for beginners: * Download the code (and extract it if needed). * Open a terminal. * Set the environment variables (listed above). diff --git a/TODO.md b/TODO.md index e242ade..03c100a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,5 @@ ### High priority: - [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server - - [ ] Rename commands from "bk_week_{name}" to "re_{name}" - - [ ] Allow disabling bk_week - [ ] Allow updating the data autonomously and via manual commands. - [ ] Automatically approve posts that don't get caught by reverse image search (ris) diff --git a/data/cfg_default.json b/data/cfg_default.json index 96f17ae..25ddd6e 100644 --- a/data/cfg_default.json +++ b/data/cfg_default.json @@ -1,6 +1,8 @@ { + "comment": "IMPORTANT!!! Anything labeled with 'RESTART_{cfg-name-here}' requires a restart to apply", "reddit": { + "RESTART_enabled": true, "subreddits": "bytedicetesting", - "fetch_limit": 100 + "fetch_limit": 100 } } \ No newline at end of file diff --git a/src/cmds/help.rs b/src/cmds/help.rs index d197600..2f93a57 100644 --- a/src/cmds/help.rs +++ b/src/cmds/help.rs @@ -1,8 +1,7 @@ -use poise::Command; -use std::{collections::HashMap, error::Error as StdErr}; +use std::collections::HashMap; use tokio::fs; -use crate::{lang, messages::send_msg, Context, Data, Error}; +use crate::{lang, messages::send_msg, Context, Cmd, Error}; #[derive(poise::ChoiceParameter, PartialEq)] @@ -15,10 +14,6 @@ enum HelpOptions { } -type Cmd = Command>; - - - #[poise::command( slash_command, prefix_command, diff --git a/src/gen.rs b/src/gen.rs index 01e32e4..9e59d83 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -4,7 +4,7 @@ use poise::serenity_prelude::UserId; use poise::serenity_prelude as serenity; use poise::serenity_prelude::Client; -use crate::{cmds, data, events, re_cmds, rs_println, Args, Data}; +use crate::{cmds, data::{self, get_mutex_data}, events, re_cmds, rs_println, Args, Cmd, Data}; pub async fn gen_data(args: Args, owners: Vec) -> Data { @@ -56,28 +56,7 @@ pub async fn gen_bot(data: Data, args: Args) -> Client { let framework = poise::Framework::builder() .options(poise::FrameworkOptions { owners: own, - commands: vec![ - cmds::help::cmd(), - cmds::ping::cmd(), - cmds::embed::cmd(), - cmds::send::cmd(), - cmds::stop::cmd(), - cmds::eight_ball::cmd(), - cmds::add_server::cmd(), - // reddit - re_cmds::add::cmd(), - re_cmds::approve::cmd(), - re_cmds::get::cmd(), - re_cmds::remove::cmd(), - re_cmds::top::cmd(), - re_cmds::update::cmd(), - re_cmds::vote::cmd(), - re_cmds::shorturl::cmd(), - // reddit admin - re_cmds::admin_bind::cmd(), - // cfg - cmds::reload_cfg::cmd() - ], + commands: make_cmd_vec(&data).await, event_handler: events::event_handler, ..Default::default() }) @@ -93,4 +72,44 @@ pub async fn gen_bot(data: Data, args: Args) -> Client { .framework(framework) .await .unwrap(); +} + + +async fn make_cmd_vec(data: &Data) -> Vec { + let mut cmds = vec![]; + let cfg = get_mutex_data(&data.cfg).await.unwrap(); + + // GENERIC + cmds.extend([ + cmds::help::cmd(), + cmds::ping::cmd(), + cmds::embed::cmd(), + cmds::send::cmd(), + cmds::stop::cmd(), + cmds::eight_ball::cmd(), + cmds::add_server::cmd() + ]); + + // REDDIT + if cfg["RESTART_enabled"].as_bool().unwrap() { + cmds.extend([ + re_cmds::add::cmd(), + re_cmds::approve::cmd(), + re_cmds::get::cmd(), + re_cmds::remove::cmd(), + re_cmds::top::cmd(), + re_cmds::update::cmd(), + re_cmds::vote::cmd(), + re_cmds::shorturl::cmd() + ]); + } + + cmds.extend([ + // reddit admin + re_cmds::admin_bind::cmd(), + // cfg + cmds::reload_cfg::cmd() + ]); + + return cmds } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1bf13b7..9f76be2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,10 +37,12 @@ use std::process; use std::thread; use std::time::Duration; use std::vec; +use std::error::Error as StdErr; use clap::Parser; use r#gen::gen_bot; use r#gen::gen_data; +use poise::Command; use schedule::run_schedules; use serde::Serialize; use serde_json::Value; @@ -74,8 +76,9 @@ struct Args { } -type Error = Box; +type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; +type Cmd = Command>; struct Data {