From 98c35d937b4b0061fde41c35d2c73800180a0b02 Mon Sep 17 00:00:00 2001 From: ByteDice Date: Sat, 28 Feb 2026 14:03:35 +0100 Subject: [PATCH] added /debug Save for quickly saving any data --- TODO.md | 10 +++++++--- data/lang/en.json | 3 ++- src/debug_cmds/main_cmd.rs | 6 ++++-- src/debug_cmds/save.rs | 12 ++++++++++++ src/debug_cmds/stop.rs | 10 ++++++++-- src/main.rs | 3 ++- 6 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/debug_cmds/save.rs diff --git a/TODO.md b/TODO.md index b20de1d..2949cca 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,19 @@ ### High priority: +- Update LANG system to be more organized +- Add a lot more logging + + ### Medium priority: -- [ ] Postfix calculator -- [ ] Postfix generator - [ ] Random tip (from ByteDice.net/data/loadingScreenTips.json) -- [ ] A command that just sends my socials ### Low priority: + diff --git a/data/lang/en.json b/data/lang/en.json index 27955ff..7f15a58 100644 --- a/data/lang/en.json +++ b/data/lang/en.json @@ -21,8 +21,9 @@ "dc_msg_mandatory_response": "Mandatory response message, please ignore.", "dc_msg_no_perms": "Missing permission in that server: {0}", "dc_msg_not_in_guild": "I am not a part of that guild.", - "dc_msg_owner_data_save_complete": "Saving data... Done!\nShutting down...", + "dc_msg_owner_data_save_complete": "Saving data... Done!", "dc_msg_owner_data_save": "Saving data...", + "dc_msg_owner_shutdown": "Shutting down...", "dc_msg_owner_shutdown_failed_confirmation": "Failed to shut down: Invalid confirmation.", "dc_msg_re_already_voted": "Couldn't cast a vote: You have already voted on this post!", "dc_msg_re_also_approved": "Also approved it!", diff --git a/src/debug_cmds/main_cmd.rs b/src/debug_cmds/main_cmd.rs index 77a5084..a029125 100644 --- a/src/debug_cmds/main_cmd.rs +++ b/src/debug_cmds/main_cmd.rs @@ -1,4 +1,4 @@ -use crate::{Context, Error, debug_cmds::{guild_invite, leave_guild, ping, stop, view_guilds, whoami}}; +use crate::{Context, Error, debug_cmds::{guild_invite, leave_guild, ping, save, stop, view_guilds, whoami}}; #[derive(poise::ChoiceParameter, PartialEq)] @@ -7,6 +7,7 @@ pub enum Subcommands { LeaveGuild, Ping, //ReloadCfg, + Save, Stop, ViewGuilds, WhoAmI @@ -35,7 +36,8 @@ pub async fn cmd( Subcommands::GuildInvite => guild_invite::cmd(ctx, u64_arg_u).await?, Subcommands::LeaveGuild => leave_guild::cmd(ctx, u64_arg_u).await?, Subcommands::Ping => ping::cmd(ctx).await?, - //Subcommands::ReloadCfg => reload_cfg::cmd(ctx).await?, + //Subcommands::ReloadCfg => reload_cfg::cmd(ctx).await?, + Subcommands::Save => save::cmd(ctx).await?, Subcommands::Stop => stop::cmd(ctx, string_arg).await?, Subcommands::ViewGuilds => view_guilds::cmd(ctx).await?, Subcommands::WhoAmI => whoami::cmd(ctx).await?, diff --git a/src/debug_cmds/save.rs b/src/debug_cmds/save.rs new file mode 100644 index 0000000..ccb626e --- /dev/null +++ b/src/debug_cmds/save.rs @@ -0,0 +1,12 @@ +use crate::{Context, Error, data, lang, messages::{edit_reply, send_msg}}; + +pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> { + let msg = send_msg(ctx, lang!("dc_msg_owner_data_save"), true, true).await.unwrap(); + + data::write_dc_data(ctx.data()).await; + data::write_re_data().await; + + edit_reply(ctx, msg, lang!("dc_msg_owner_data_save_complete")).await; + + return Ok(()); +} \ No newline at end of file diff --git a/src/debug_cmds/stop.rs b/src/debug_cmds/stop.rs index df683eb..2a1a4c6 100644 --- a/src/debug_cmds/stop.rs +++ b/src/debug_cmds/stop.rs @@ -4,7 +4,7 @@ use poise::serenity_prelude::OnlineStatus; use crate::{data, lang, messages::{edit_reply, send_msg}, websocket::send_cmd_json, Context, Error}; -pub async fn cmd(ctx: Context<'_>, 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; @@ -15,7 +15,13 @@ pub async fn cmd(ctx: Context<'_>, confirmation: Option) -> Result<(), E data::write_re_data().await; send_cmd_json("stop_praw", None, true).await; - edit_reply(ctx, msg, lang!("dc_msg_owner_data_save_complete")).await; + let complete = format!( + "{}\n{}", + lang!("dc_msg_owner_data_save_complete"), + lang!("dc_msg_owner_shutdown") + ); + + edit_reply(ctx, msg, complete).await; ctx.serenity_context().set_presence(None, OnlineStatus::Invisible); ctx.framework().shard_manager.shutdown_all().await; diff --git a/src/main.rs b/src/main.rs index 5512535..cf0643b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,10 @@ mod debug_cmds { pub mod guild_invite; pub mod leave_guild; pub mod main_cmd; - pub mod stop; pub mod ping; pub mod reload_cfg; + pub mod save; + pub mod stop; pub mod view_guilds; pub mod whoami; }