feat: add checkdb command
This commit is contained in:
parent
b2e6bb1dfa
commit
57500c5dd7
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "SELECT * FROM custom_commands;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "command",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
|
"name": "response",
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": []
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "663e948628219d6294d25f57cd0d94b55ff2d4d9bc5c5a5dc25397741ad845f6"
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "UPDATE custom_commands SET response = $2 WHERE id = $1;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int4",
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "dabc1a5ecdfb9d99d66d62e8b855737c0360df5a30fc02832a74d781ae698fee"
|
||||||
|
}
|
|
@ -138,3 +138,50 @@ pub async fn edit(
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[poise::command(slash_command)]
|
||||||
|
pub async fn checkdb(ctx: Context<'_>) -> eyre::Result<()> {
|
||||||
|
let query = sqlx::query!("SELECT * FROM custom_commands;");
|
||||||
|
let data = query
|
||||||
|
.fetch_all(&ctx.data().db)
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.map(|r| (r.id, r.command.clone(), r.response.clone()))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // we only care how many digits are needed.
|
||||||
|
let max_id_length =
|
||||||
|
f64::from(data.clone().iter().map(|r| r.0).max().unwrap_or(0)).log10() as usize;
|
||||||
|
let max_name_length = data
|
||||||
|
.clone()
|
||||||
|
.iter()
|
||||||
|
.map(|(_, command, _)| command)
|
||||||
|
.map(String::len)
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0)
|
||||||
|
+ 1;
|
||||||
|
|
||||||
|
let rows = data.iter().map(|(id, command, response)| {
|
||||||
|
format!(
|
||||||
|
"{id:>max_id_length$}|{}{command:<max_name_length$}|{response}",
|
||||||
|
ctx.data().settings.prefix,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
if data.is_empty() {
|
||||||
|
ctx.reply("Es liegen keine customcommands vor.").await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let mut msg = String::from("```fix\n");
|
||||||
|
for row in rows {
|
||||||
|
if msg.clone().len() + row.len() > 1990 {
|
||||||
|
msg += "```";
|
||||||
|
ctx.reply(msg).await?;
|
||||||
|
msg = String::from("```fix\n");
|
||||||
|
}
|
||||||
|
msg += &(row + "\n");
|
||||||
|
}
|
||||||
|
msg += "```";
|
||||||
|
ctx.reply(msg).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ fn build_framework(settings: Settings, db: PgPool) -> poise::Framework<Data, eyr
|
||||||
commands::custom_commands::add(),
|
commands::custom_commands::add(),
|
||||||
commands::custom_commands::del(),
|
commands::custom_commands::del(),
|
||||||
commands::custom_commands::edit(),
|
commands::custom_commands::edit(),
|
||||||
|
commands::custom_commands::checkdb(),
|
||||||
commands::admin::new_modpack(),
|
commands::admin::new_modpack(),
|
||||||
],
|
],
|
||||||
prefix_options: poise::PrefixFrameworkOptions {
|
prefix_options: poise::PrefixFrameworkOptions {
|
||||||
|
|
Loading…
Reference in a new issue