From 8939334f84498e9e8e7ccdaffa3d2c96f0dacf39 Mon Sep 17 00:00:00 2001 From: Byte Dice Date: Mon, 24 Feb 2025 19:38:42 +0100 Subject: [PATCH] update README, security, and user friendliness --- README.md | 11 +++++++++++ src/messages.rs | 6 ++++-- src/python/bot.py | 21 ++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 64f5173..9867670 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,17 @@ An automation tool for Byte Dice. It's both a Discord and Reddit bot in one prog * typing * websockets +**Environment variables:** +| **Name** | **Description** | +| --- | --- | +| `ASSISTANT_TOKEN` | The Discord bot token. | +| `ASSISTANT_TOKEN_TEST` | (Optional) A testing Discord bot token. This is only needed when the program is ran 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. | +| `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. | + You can install Python modules by running `$ pip install {module}` or `$ python -m pip install {module}` in a terminal. **How to run:** diff --git a/src/messages.rs b/src/messages.rs index d079421..4737432 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -177,8 +177,10 @@ pub async fn http_edit_msg( pub async fn send_dm(msg: String, args: Args) { - let uid = env::var("ASSISTANT_DM_USER").expect("Missing ASSISTANT_DM_USER env var!").parse::().unwrap(); - let user = UserId::new(uid); + let uid = env::var("ASSISTANT_DM_USER"); + if uid.is_err() { return; } + + let user = UserId::new(uid.unwrap().parse::().unwrap()); let token: String; if !args.test { diff --git a/src/python/bot.py b/src/python/bot.py index bfdb639..5656036 100644 --- a/src/python/bot.py +++ b/src/python/bot.py @@ -6,9 +6,16 @@ from macros import * class Bot: - args: dict = {"NO_RUST": True, "dev": True, "py": True, "port": 2920} + args: dict = {"NO_RUST": True, "dev": True, "py": True, "port": 2920} + r_id: str = os.environ.get("ASSISTANT_R_ID") + secret: str = os.environ.get("ASSISTANT_R_TOKEN") + username: str = os.environ.get("ASSISTANT_R_NAME") password: str = os.environ.get("ASSISTANT_R_PASS") - secret: str = os.environ.get("ASSISTANT_R_TOKEN") + + useragent: str =\ + f"{username} by u/RandomPersonDotExe aka u/Byte_Dice"\ + if r_id == "YmZjr4zLr2qtHdpQXtj0sBOOdJzrXQ"\ + else f"{username} (original program by u/RandomPersonDotExe aka u/Byte_Dice)" if password is None: py_error("Environment variable \"ASSISTANT_R_PASS\" is null!") @@ -17,11 +24,11 @@ class Bot: def __init__(self): self.r: praw.Reddit = praw.Reddit( - client_id="iCSRWS6PMlTLwmylCJRYmA", - client_secret=self.secret, - username="ByteDiceAssistant", - password=self.password, - user_agent="Byte Dice Assistant by u/RandomPersonDotExe aka u/Byte_Dice" + client_id = self.r_id, + client_secret = self.secret, + username = self.username, + password = self.password, + user_agent = self.useragent ) self.sr = None self.data_f: TextIOWrapper = None