diff --git a/Cargo.toml b/Cargo.toml index cd577ac..3b92daa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ flate2 = "1.1.2" formatx = "0.2.3" futures = "0.3.31" poise = "0.6.1" -pyo3 = "0.23.4" +pyo3 = "0.28.2" rand = "0.9.0" regex = "1.11.1" serde = "1.0.217" diff --git a/data/defaults/cfg_default.toml b/data/defaults/cfg_default.toml index a0bcc72..84d68be 100644 --- a/data/defaults/cfg_default.toml +++ b/data/defaults/cfg_default.toml @@ -6,6 +6,13 @@ lang = "en" # The discord bots status text status = "🎲 https://bytedice.net" +# Adds "(Commit #123)" at the end of the status +statusCommitNumber = true + +# Changes "(Commit #123)" into "(Experimental #123)" +# Requires statusCommitNumber to be true +statusExperimentalCommit = false + [reddit] # Which subreddits the bot will scan when executing "re"-category commands. # Is automatically disabled when `disabled_categories` includes "re". @@ -31,6 +38,7 @@ disabled_categories = [ # "fun", # "help" # "re" + # "debug" ] # The chance (between 0..1) for the `/8_ball` command to output a "quirky" answer. diff --git a/src/cmds/ping.rs b/src/cmds/ping.rs deleted file mode 100644 index d62b114..0000000 --- a/src/cmds/ping.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::{messages::send_msg, Context, Error}; - - -#[poise::command( - slash_command, - prefix_command, - rename = "ping", - category = "fun", - required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" -)] -/// Check if you have connection to the bot. -pub async fn cmd( - ctx: Context<'_>, - #[description = "The text to echo back."] text: Option, -) -> Result<(), Error> -{ - send_msg(ctx, text.unwrap_or_else(|| "Pong".to_string()), true, true).await; - - return Ok(()); -} \ No newline at end of file diff --git a/src/debug_cmds/main_cmd.rs b/src/debug_cmds/main_cmd.rs new file mode 100644 index 0000000..da53755 --- /dev/null +++ b/src/debug_cmds/main_cmd.rs @@ -0,0 +1,39 @@ +use crate::{Context, Error, debug_cmds::{ping, reload_cfg, stop, whoami}}; + + +#[derive(poise::ChoiceParameter, PartialEq)] +pub enum Subcommands { + GuildInvite, + LeaveGuild, + Ping, + ReloadCfg, + Stop, + ViewGuilds, + WhoAmI +} + + +#[poise::command( + slash_command, + prefix_command, + category = "owner", + rename = "debug", + required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" +)] +/// Various debug utilities +pub async fn cmd( + ctx: Context<'_>, + #[description = "Subcommand"] subcommand: Subcommands, + string_arg: Option +) -> Result<(), Error> +{ + match subcommand { + Subcommands::Ping => ping::cmd(ctx).await?, + Subcommands::ReloadCfg => reload_cfg::cmd(ctx).await?, + Subcommands::Stop => stop::cmd(ctx, string_arg).await?, + Subcommands::WhoAmI => whoami::cmd(ctx).await?, + _ => return Ok(()) + } + + return Ok(()); +} \ No newline at end of file diff --git a/src/debug_cmds/ping.rs b/src/debug_cmds/ping.rs new file mode 100644 index 0000000..570c281 --- /dev/null +++ b/src/debug_cmds/ping.rs @@ -0,0 +1,8 @@ +use crate::{messages::send_msg, Context, Error}; + + +pub async fn cmd(ctx: Context<'_>,) -> Result<(), Error> { + send_msg(ctx, "Pong".to_string(), true, true).await; + + return Ok(()); +} \ No newline at end of file diff --git a/src/cmds/reload_cfg.rs b/src/debug_cmds/reload_cfg.rs similarity index 72% rename from src/cmds/reload_cfg.rs rename to src/debug_cmds/reload_cfg.rs index 4326022..dbb8a26 100644 --- a/src/cmds/reload_cfg.rs +++ b/src/debug_cmds/reload_cfg.rs @@ -1,19 +1,7 @@ use crate::{data::{self, get_toml_mutex, read_cfg_data}, lang, messages::send_msg, Context, Error}; -#[poise::command( - slash_command, - prefix_command, - rename = "reload_cfg", - category = "owner", - owners_only, - required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" -)] -/// Reloads the entire config file. -pub async fn cmd( - ctx: Context<'_> -) -> Result<(), Error> -{ +pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> { let r = read_cfg_data(ctx.data(), false).await; let d = get_toml_mutex(&ctx.data().cfg).await.unwrap(); diff --git a/src/cmds/stop.rs b/src/debug_cmds/stop.rs similarity index 69% rename from src/cmds/stop.rs rename to src/debug_cmds/stop.rs index e81d983..df683eb 100644 --- a/src/cmds/stop.rs +++ b/src/debug_cmds/stop.rs @@ -4,21 +4,7 @@ use poise::serenity_prelude::OnlineStatus; use crate::{data, lang, messages::{edit_reply, send_msg}, websocket::send_cmd_json, Context, Error}; - -#[poise::command( - slash_command, - prefix_command, - rename = "stop", - category = "owner", - owners_only, - required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" -)] -/// I have security measures, even in developer mode. You wont access this without being a bot "owner". -pub async fn cmd( - ctx: Context<'_>, - #[description = "Type \"i want to stop the bot now\" to confirm."] confirmation: Option, -) -> Result<(), Error> -{ +pub async fn cmd(ctx: Context<'_>, confirmation: Option) -> Result<(), Error>{ let stop_confirm = "i want to stop the bot now".replace(" ", ""); let confirm_formatted = confirmation.unwrap_or_default().to_lowercase().replace(" ", ""); let should_stop = ctx.data().args.dev || confirm_formatted == stop_confirm; diff --git a/src/cmds/whoami.rs b/src/debug_cmds/whoami.rs similarity index 70% rename from src/cmds/whoami.rs rename to src/debug_cmds/whoami.rs index 0823104..b85c3b4 100644 --- a/src/cmds/whoami.rs +++ b/src/debug_cmds/whoami.rs @@ -1,12 +1,5 @@ use crate::{lang, messages::send_msg, Context, Error}; -#[poise::command( - slash_command, - prefix_command, - rename = "whoami", - category = "help", - required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" -)] pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> { let data = ctx.data(); let uid: u64 = ctx.author().id.into(); diff --git a/src/gen.rs b/src/gen.rs index eb3e2c7..d616c7f 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::{self, get_toml_mutex}, events, re_cmds, rs_println, Args, Cmd, Data}; +use crate::{Args, Cmd, Data, cmds, data::{self, get_toml_mutex}, debug_cmds, events, re_cmds, rs_println}; pub async fn gen_data(args: Args, owners: Vec) -> Data { @@ -79,8 +79,6 @@ async fn make_cmd_vec(data: &Data) -> Vec { let mut cmds = vec![ // GENERIC cmds::help::cmd(), - cmds::whoami::cmd(), - cmds::ping::cmd(), cmds::eight_ball::cmd(), // REDDIT re_cmds::add::cmd(), @@ -94,11 +92,11 @@ async fn make_cmd_vec(data: &Data) -> Vec { // [ADMIN / OWNER] cmds::embed::cmd(), cmds::send::cmd(), - cmds::stop::cmd(), cmds::add_server::cmd(), - cmds::reload_cfg::cmd(), // REDDIT [ADMIN / OWNER] - re_cmds::admin_bind::cmd() + re_cmds::admin_bind::cmd(), + // DEBUG + debug_cmds::main_cmd::cmd() ]; let cfg = get_toml_mutex(&data.cfg).await.unwrap(); diff --git a/src/main.rs b/src/main.rs index 7d62d56..08d55f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,13 @@ #![warn(unused_extern_crates)] #![allow(clippy::needless_return)] +#![allow(static_mut_refs)] mod cmds { pub mod add_server; pub mod eight_ball; pub mod embed; pub mod help; - pub mod ping; - pub mod reload_cfg; pub mod send; - pub mod stop; - pub mod whoami; } mod re_cmds { pub mod add; @@ -24,6 +21,13 @@ mod re_cmds { pub mod update; pub mod vote; } +mod debug_cmds { + pub mod main_cmd; + pub mod stop; + pub mod ping; + pub mod reload_cfg; + pub mod whoami; +} mod events; mod messages; mod python; diff --git a/src/python.rs b/src/python.rs index d382dcd..6e87f77 100644 --- a/src/python.rs +++ b/src/python.rs @@ -36,10 +36,8 @@ pub async fn start(args: Args) -> PyResult<()> { let mut traceback: String = String::new(); let mut is_error = false; - pyo3::prepare_freethreaded_python(); - - let _ = Python::with_gil(|py| -> Result<(), PyErr> { - let syspath = py.import("sys")?.getattr("path")?.downcast_into::()?; + let _ = Python::attach(|py| -> Result<(), PyErr> { + let syspath = py.import("sys")?.getattr("path")?.cast_into::()?; syspath.insert(0, path)?; let empty = CString::new("").unwrap();