enhanced the bk mod IDs security by using env instead of a file
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
An automation tool for Byte Dice. It's both a Discord and Reddit bot in one program.
|
||||
|
||||
> [!CAUTION]
|
||||
> This tool is not intended for public use outside of the official *Byte Dice Assistant* bots. Expect issues if you host this yourself.
|
||||
> This tool is not intended for public use outside of the official *Byte Dice Assistant* bots. Expect issues if you host this yourself.\
|
||||
> This tool is only designed to run on Windows (10 and 11) and XUbuntu and may not work on any other OS.
|
||||
|
||||
# Open-source - Copyright
|
||||
|
||||
@@ -38,7 +39,7 @@ You can install Python modules by running `$ pip install {module}` or `$ python
|
||||
| `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_WEEK_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for people who are allowed to use the `/bk_week` commands. |
|
||||
| `ASSISTANT_BK_MODS` | (OPTIONAL) Same format as `ASSISTANT_OWNERS` but for people who are allowed to use the `/bk_week` 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`.**
|
||||
@@ -56,7 +57,7 @@ You can install Python modules by running `$ pip install {module}` or `$ python
|
||||
* Run `$ setx VARIABLE_NAME "value"` in a terminal.
|
||||
|
||||
* On Unix (Linux / Mac):
|
||||
* Run `$ sudo nano /etc/environment` or `$ sudo vim /etc/environment` in the terminal.
|
||||
* Run `$ sudo nano /etc/environment` or `$ sudo vim /etc/environment` in the terminal (and enter your password if prompted to).
|
||||
* press `i` (only if you used VIM).
|
||||
* write `VARIABLE_NAME="value"` + a new line for every variable.
|
||||
* if nano: `ctrl + O` (and press enter) then `ctrl + X`.
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"bk1": {
|
||||
"discord": [
|
||||
697149665166229614,
|
||||
526842473062989864,
|
||||
1171015493537247273,
|
||||
1156779840956010496,
|
||||
1021944396473716847,
|
||||
1085622021024653362,
|
||||
1223480842525872148,
|
||||
1155349278655520858
|
||||
],
|
||||
"reddit": [
|
||||
|
||||
]
|
||||
},
|
||||
"bk2": {
|
||||
"discord": [
|
||||
1004132854227292272,
|
||||
1031352334745354282,
|
||||
1173039143245332520,
|
||||
1281040971710201857,
|
||||
772049174672703528
|
||||
],
|
||||
"reddit": [
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
+6
-10
@@ -26,12 +26,8 @@ enum TopCategory {
|
||||
}
|
||||
|
||||
|
||||
fn is_bk_mod(mod_list: Value, uid: u64) -> bool {
|
||||
let obj = mod_list.as_object().unwrap();
|
||||
let bk1_arr = obj["bk1"]["discord"].as_array().unwrap();
|
||||
let bk2_arr = obj["bk2"]["discord"].as_array().unwrap();
|
||||
|
||||
return bk1_arr.contains(&json!(uid)) || bk2_arr.contains(&json!(uid));
|
||||
fn is_bk_mod(mod_list: Vec<u64>, uid: u64) -> bool {
|
||||
return mod_list.contains(&uid);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +177,7 @@ pub async fn bk_week_add(
|
||||
#[description = "Wether to approve it after adding it"] approve: Option<bool>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods_json.clone(), ctx.author().id.get()) {
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
not_bk_mod_msg(ctx).await;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -253,7 +249,7 @@ pub async fn bk_week_remove(
|
||||
#[description = "The reason of the removal."] reason: Option<String>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods_json.clone(), ctx.author().id.get()) {
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
not_bk_mod_msg(ctx).await;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -291,7 +287,7 @@ pub async fn bk_week_approve(
|
||||
#[description = "Wether to approve or disapprove the post"] disapprove: Option<bool>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods_json.clone(), ctx.author().id.get()) {
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
not_bk_mod_msg(ctx).await;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -694,7 +690,7 @@ pub async fn bk_week_vote(
|
||||
|
||||
let url_data = &post_data[&url];
|
||||
|
||||
let is_mod = is_bk_mod(ctx.data().bk_mods_json.clone(), ctx.author().id.get());
|
||||
let is_mod = is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get());
|
||||
let voters_dc = url_data["votes"]["voters_dc"].as_array().unwrap();
|
||||
let mod_voters = url_data["votes"]["mod_voters"].as_array().unwrap();
|
||||
let voters = if is_mod { mod_voters } else { voters_dc };
|
||||
|
||||
+9
-4
@@ -62,7 +62,7 @@ struct Data {
|
||||
ball_prompts: [Vec<String>; 2],
|
||||
reddit_data: Mutex<Option<Value>>,
|
||||
discord_data: Mutex<Option<Value>>,
|
||||
bk_mods_json: Value,
|
||||
bk_mods: Vec<u64>,
|
||||
args: Args
|
||||
}
|
||||
|
||||
@@ -145,16 +145,21 @@ async fn start(args: Args, owners: Vec<u64>) {
|
||||
async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
||||
let ball_classic_str = std::fs::read_to_string("./data/8-ball_classic.txt").unwrap();
|
||||
let ball_quirk_str = std::fs::read_to_string("./data/8-ball_quirky.txt").unwrap();
|
||||
let bk_mods_str = std::fs::read_to_string("./data/bk_mods.json").unwrap();
|
||||
|
||||
let ball_classic: Vec<String> = ball_classic_str.lines().map(String::from).collect();
|
||||
let ball_quirk: Vec<String> = ball_quirk_str .lines().map(String::from).collect();
|
||||
let bk_mods: Value = serde_json::from_str(&bk_mods_str).unwrap();
|
||||
|
||||
let mods_env = std::env::var("ASSISTANT_BK_MODS").expect("Missing ASSISTANT_BK_MODS env var!");
|
||||
let mods_vec_str: Vec<String> = mods_env.split(",").map(String::from).collect();
|
||||
let mods_vec_u64: Vec<u64> = mods_vec_str
|
||||
.iter()
|
||||
.filter_map(|s| Some(s.parse::<u64>().expect("Failed to parse ASSISTANT_BK_MODS. Invalid syntax.")))
|
||||
.collect();
|
||||
|
||||
let data = Data {
|
||||
owners,
|
||||
ball_prompts: [ball_classic, ball_quirk],
|
||||
bk_mods_json: bk_mods,
|
||||
bk_mods: mods_vec_u64,
|
||||
reddit_data: None.into(),
|
||||
discord_data: None.into(),
|
||||
args: args.clone()
|
||||
|
||||
Reference in New Issue
Block a user