moved "debug" commands to a single command to reduce clutter
This commit is contained in:
@@ -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<String>
|
||||
) -> 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(());
|
||||
}
|
||||
@@ -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(());
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
use crate::{data::{self, get_toml_mutex, read_cfg_data}, lang, messages::send_msg, Context, 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();
|
||||
|
||||
if r.is_none() { return Ok(()); }
|
||||
|
||||
let data_binding = get_toml_mutex(&ctx.data().cfg).await.unwrap();
|
||||
let lang_cfg = data_binding["general"]["lang"].as_str().unwrap();
|
||||
data::load_lang_data(lang_cfg.to_string());
|
||||
|
||||
if r.unwrap()["value"].as_bool().unwrap() {
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("dc_msg_reload_cfg_success", toml::to_string_pretty(&d).unwrap()),
|
||||
true,
|
||||
true
|
||||
).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
send_msg(ctx, lang!("dc_msg_reload_cfg_python_fail"), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
use std::process;
|
||||
|
||||
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<String>) -> 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;
|
||||
|
||||
if should_stop {
|
||||
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;
|
||||
send_cmd_json("stop_praw", None, true).await;
|
||||
|
||||
edit_reply(ctx, msg, lang!("dc_msg_owner_data_save_complete")).await;
|
||||
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
||||
ctx.framework().shard_manager.shutdown_all().await;
|
||||
|
||||
process::exit(0);
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("dc_msg_owner_shutdown_failed_confirmation"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
use crate::{lang, messages::send_msg, Context, Error};
|
||||
|
||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let data = ctx.data();
|
||||
let uid: u64 = ctx.author().id.into();
|
||||
|
||||
let is_owner = data.owners .contains(&uid);
|
||||
let is_bk_mod = data.bk_mods.contains(&uid);
|
||||
|
||||
send_msg(ctx, lang!("dc_msg_whoami", is_owner, is_bk_mod), true, true).await;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
Reference in New Issue
Block a user