added new config option, refactored other code
This commit is contained in:
@@ -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.
|
You can install Python modules by running `$ pip install {module}` or `$ python -m pip install {module}` in a terminal.
|
||||||
|
|
||||||
### 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)!) |
|
||||||
| `ASSISTANT_R_TOKEN` | The token for the Reddit bot/account. |
|
| `ASSISTANT_R_TOKEN` | The token for the Reddit bot/account. |
|
||||||
| `ASSISTANT_R_NAME` | The username of 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_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_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_BK_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for people who are allowed to use the `/re_*` commands. |
|
||||||
|
|
||||||
### Required permissions:
|
### 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`)
|
**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`.
|
* 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).
|
||||||
|
|||||||
@@ -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) -->
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"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
@@ -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
@@ -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()
|
||||||
})
|
})
|
||||||
@@ -93,4 +72,44 @@ pub async fn gen_bot(data: Data, args: Args) -> Client {
|
|||||||
.framework(framework)
|
.framework(framework)
|
||||||
.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
|
||||||
}
|
}
|
||||||
+4
-1
@@ -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;
|
||||||
@@ -74,8 +76,9 @@ 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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user