diff --git a/.sqlx/query-663e948628219d6294d25f57cd0d94b55ff2d4d9bc5c5a5dc25397741ad845f6.json b/.sqlx/query-663e948628219d6294d25f57cd0d94b55ff2d4d9bc5c5a5dc25397741ad845f6.json new file mode 100644 index 0000000..dd204d1 --- /dev/null +++ b/.sqlx/query-663e948628219d6294d25f57cd0d94b55ff2d4d9bc5c5a5dc25397741ad845f6.json @@ -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" +} diff --git a/.sqlx/query-dabc1a5ecdfb9d99d66d62e8b855737c0360df5a30fc02832a74d781ae698fee.json b/.sqlx/query-dabc1a5ecdfb9d99d66d62e8b855737c0360df5a30fc02832a74d781ae698fee.json new file mode 100644 index 0000000..c014d2d --- /dev/null +++ b/.sqlx/query-dabc1a5ecdfb9d99d66d62e8b855737c0360df5a30fc02832a74d781ae698fee.json @@ -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" +} diff --git a/src/commands/custom_commands.rs b/src/commands/custom_commands.rs index 18e2b7d..a2762b4 100644 --- a/src/commands/custom_commands.rs +++ b/src/commands/custom_commands.rs @@ -138,3 +138,50 @@ pub async fn edit( } 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::>(); + #[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: 1990 { + msg += "```"; + ctx.reply(msg).await?; + msg = String::from("```fix\n"); + } + msg += &(row + "\n"); + } + msg += "```"; + ctx.reply(msg).await?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index b85adf1..9d6f7e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ fn build_framework(settings: Settings, db: PgPool) -> poise::Framework