added new config option, refactored other code

This commit is contained in:
2025-06-05 23:32:33 +02:00
parent 7922bc50a9
commit 71da587242
6 changed files with 61 additions and 44 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ You can install Python modules by running `$ pip install {module}` or `$ python
### Environment variables: ### Environment variables:
| **Name** | **Description** | | **Name** | **Description** |
| --- | --- | | ---------------------- | --- |
| `ASSISTANT_TOKEN` | The Discord bot token. (Create a Discord bot [here](https://discord.com/developers/docs/intro)!) | | `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_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_ID` | The id for the Reddit bot/account. (Create a Reddit bot [here](https://www.reddit.com/prefs/apps)!) |
@@ -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`. * 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` * 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). * Download the code (and extract it if needed).
* Open a terminal. * Open a terminal.
* Set the environment variables (listed above). * Set the environment variables (listed above).
-2
View File
@@ -1,7 +1,5 @@
### High priority: ### High priority:
- [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server - [ ] 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. - [ ] Allow updating the data autonomously and via manual commands.
- [ ] Automatically approve posts that don't get caught by reverse image search (ris) - [ ] Automatically approve posts that don't get caught by reverse image search (ris)
<!-- - [ ] 10-minute schedule for updating Discord channel (IMPOSSIBLE / REALLY FUCKING HARD) --> <!-- - [ ] 10-minute schedule for updating Discord channel (IMPOSSIBLE / REALLY FUCKING HARD) -->
+2
View File
@@ -1,5 +1,7 @@
{ {
"comment": "IMPORTANT!!! Anything labeled with 'RESTART_{cfg-name-here}' requires a restart to apply",
"reddit": { "reddit": {
"RESTART_enabled": true,
"subreddits": "bytedicetesting", "subreddits": "bytedicetesting",
"fetch_limit": 100 "fetch_limit": 100
} }
+2 -7
View File
@@ -1,8 +1,7 @@
use poise::Command; use std::collections::HashMap;
use std::{collections::HashMap, error::Error as StdErr};
use tokio::fs; 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)] #[derive(poise::ChoiceParameter, PartialEq)]
@@ -15,10 +14,6 @@ enum HelpOptions {
} }
type Cmd = Command<Data, Box<dyn StdErr + Send + Sync>>;
#[poise::command( #[poise::command(
slash_command, slash_command,
prefix_command, prefix_command,
+42 -23
View File
@@ -4,7 +4,7 @@ use poise::serenity_prelude::UserId;
use poise::serenity_prelude as serenity; use poise::serenity_prelude as serenity;
use poise::serenity_prelude::Client; 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<u64>) -> Data { pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
@@ -56,28 +56,7 @@ pub async fn gen_bot(data: Data, args: Args) -> Client {
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
owners: own, owners: own,
commands: vec![ commands: make_cmd_vec(&data).await,
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()
],
event_handler: events::event_handler, event_handler: events::event_handler,
..Default::default() ..Default::default()
}) })
@@ -94,3 +73,43 @@ pub async fn gen_bot(data: Data, args: Args) -> Client {
.await .await
.unwrap(); .unwrap();
} }
async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
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
}
+3
View File
@@ -37,10 +37,12 @@ use std::process;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::vec; use std::vec;
use std::error::Error as StdErr;
use clap::Parser; use clap::Parser;
use r#gen::gen_bot; use r#gen::gen_bot;
use r#gen::gen_data; use r#gen::gen_data;
use poise::Command;
use schedule::run_schedules; use schedule::run_schedules;
use serde::Serialize; use serde::Serialize;
use serde_json::Value; use serde_json::Value;
@@ -76,6 +78,7 @@ struct Args {
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>; type Context<'a> = poise::Context<'a, Data, Error>;
type Cmd = Command<Data, Box<dyn StdErr + Send + Sync>>;
struct Data { struct Data {