mirror of
https://github.com/supleed2/nanobot.git
synced 2024-11-09 20:25:48 +00:00
Add logging to commands
This commit is contained in:
parent
d501512ff2
commit
655b6447b0
36
src/cmds.rs
36
src/cmds.rs
|
@ -5,6 +5,7 @@ use poise::Modal;
|
|||
/// Buttons to (de-)register application commands globally or by guild
|
||||
#[poise::command(prefix_command, owners_only)]
|
||||
pub(crate) async fn cmds(ctx: poise::Context<'_, Data, Error>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) cmds", ctx.author());
|
||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -17,6 +18,7 @@ pub(crate) async fn setup(
|
|||
#[channel_types("Text", "News")]
|
||||
channel: serenity::GuildChannel,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) setup", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct Setup {
|
||||
#[name = "Contents of the verification intro message"]
|
||||
|
@ -72,6 +74,7 @@ pub(crate) async fn setup(
|
|||
/// Get the number of members in the members table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn count_members(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) count_members", ctx.author());
|
||||
let count = db::count_members(&ctx.data().db).await?;
|
||||
ctx.say(format!("There are {count} entries in the members table"))
|
||||
.await?;
|
||||
|
@ -85,6 +88,7 @@ pub(crate) async fn delete_member(
|
|||
id: serenity::Member,
|
||||
remove_roles: Option<bool>,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_member {id}", ctx.author());
|
||||
match db::delete_member_by_id(&ctx.data().db, id.user.id.0 as i64).await? {
|
||||
true => {
|
||||
if remove_roles.unwrap_or(true) {
|
||||
|
@ -108,6 +112,7 @@ pub(crate) async fn delete_member(
|
|||
/// Print all members in members table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_members", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct Confirm {
|
||||
#[name = "This will output the members db as text"]
|
||||
|
@ -148,6 +153,7 @@ pub(crate) async fn get_member(_ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Get member info by Discord ID
|
||||
#[poise::command(slash_command, rename = "id")]
|
||||
pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_member_by_id {id}", ctx.author());
|
||||
match db::get_member_by_id(&ctx.data().db, id.id.0 as i64).await? {
|
||||
Some(m) => {
|
||||
ctx.say(format!("Member info for {id}:\n```rust\n{m:#?}\n```"))
|
||||
|
@ -161,6 +167,10 @@ pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::User) -> Resul
|
|||
/// Get member info by Shortcode
|
||||
#[poise::command(slash_command, rename = "shortcode")]
|
||||
pub(crate) async fn get_member_by_shortcode(ctx: ACtx<'_>, shortcode: String) -> Result<(), Error> {
|
||||
println!(
|
||||
"Cmd: ({}) get_member_by_shortcode {shortcode}",
|
||||
ctx.author()
|
||||
);
|
||||
match db::get_member_by_shortcode(&ctx.data().db, &shortcode).await? {
|
||||
Some(m) => {
|
||||
ctx.say(format!(
|
||||
|
@ -179,6 +189,7 @@ pub(crate) async fn get_member_by_shortcode(ctx: ACtx<'_>, shortcode: String) ->
|
|||
/// Get member info by Nickname
|
||||
#[poise::command(slash_command, rename = "nick")]
|
||||
pub(crate) async fn get_member_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_member_by_nickname {nickname}", ctx.author());
|
||||
match db::get_member_by_nickname(&ctx.data().db, &nickname).await? {
|
||||
Some(m) => {
|
||||
ctx.say(format!(
|
||||
|
@ -197,6 +208,7 @@ pub(crate) async fn get_member_by_nickname(ctx: ACtx<'_>, nickname: String) -> R
|
|||
/// Get member info by Real Name
|
||||
#[poise::command(slash_command, rename = "name")]
|
||||
pub(crate) async fn get_member_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_member_by_realname {realname}", ctx.author());
|
||||
match db::get_member_by_realname(&ctx.data().db, &realname).await? {
|
||||
Some(m) => {
|
||||
ctx.say(format!(
|
||||
|
@ -222,6 +234,10 @@ pub(crate) async fn add_member(
|
|||
realname: String,
|
||||
fresher: bool,
|
||||
) -> Result<(), Error> {
|
||||
println!(
|
||||
"Cmd: ({}) add_member {id}, {shortcode}, {realname}, {nickname}",
|
||||
ctx.author(),
|
||||
);
|
||||
db::insert_member(
|
||||
&ctx.data().db,
|
||||
Member {
|
||||
|
@ -250,6 +266,7 @@ pub(crate) async fn insert_member_from_pending(
|
|||
nickname: String,
|
||||
fresher: bool,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) insert_member_from_pending {id}", ctx.author());
|
||||
match db::insert_member_from_pending(&ctx.data().db, id.id.0 as i64, &nickname, fresher).await {
|
||||
Ok(()) => {
|
||||
ctx.say(format!("Member moved from pending to members table: {id}"))
|
||||
|
@ -266,6 +283,7 @@ pub(crate) async fn insert_member_from_manual(
|
|||
ctx: ACtx<'_>,
|
||||
id: serenity::User,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) insert_member_from_manual {id}", ctx.author());
|
||||
match db::insert_member_from_manual(&ctx.data().db, id.id.0 as i64).await {
|
||||
Ok(()) => {
|
||||
ctx.say(format!("Member moved from manual to members table: {id}"))
|
||||
|
@ -279,6 +297,7 @@ pub(crate) async fn insert_member_from_manual(
|
|||
/// Get the number of pending members in the pending table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) count_pending", ctx.author());
|
||||
let count = db::count_pending(&ctx.data().db).await?;
|
||||
ctx.say(format!("There are {count} entries in the pending table"))
|
||||
.await?;
|
||||
|
@ -288,6 +307,7 @@ pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Delete pending member info by Discord ID
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_pending {id}", ctx.author());
|
||||
match db::delete_pending_by_id(&ctx.data().db, id.id.0 as i64).await? {
|
||||
true => {
|
||||
ctx.say(format!("Successfully deleted pending member info for {id}"))
|
||||
|
@ -304,6 +324,7 @@ pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<
|
|||
/// Print all pending members in pending table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_pending", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPending {
|
||||
#[name = "This will output the pending db as text"]
|
||||
|
@ -330,6 +351,7 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Get pending member info by Discord ID
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_pending {id}", ctx.author());
|
||||
match db::get_pending_by_id(&ctx.data().db, id.id.0 as i64).await? {
|
||||
Some(p) => {
|
||||
ctx.say(format!("Pending info for {id}:\n```rust\n{p:#?}\n```"))
|
||||
|
@ -348,6 +370,10 @@ pub(crate) async fn add_pending(
|
|||
shortcode: String,
|
||||
realname: String,
|
||||
) -> Result<(), Error> {
|
||||
println!(
|
||||
"Cmd: ({}) add_pending {id}, {shortcode}, {realname}",
|
||||
ctx.author()
|
||||
);
|
||||
db::insert_pending(
|
||||
&ctx.data().db,
|
||||
PendingMember {
|
||||
|
@ -364,6 +390,7 @@ pub(crate) async fn add_pending(
|
|||
/// Delete all pending members in pending table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_all_pending", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPurgePending {
|
||||
#[name = "This will wipe the pending db"]
|
||||
|
@ -390,6 +417,7 @@ pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Get the number of manual members in the manual table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) count_manual", ctx.author());
|
||||
let count = db::count_manual(&ctx.data().db).await?;
|
||||
ctx.say(format!("There are {count} entries in the manual table"))
|
||||
.await?;
|
||||
|
@ -399,6 +427,7 @@ pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Delete manual member info by Discord ID
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_manual {id}", ctx.author());
|
||||
match db::delete_manual_by_id(&ctx.data().db, id.id.0 as i64).await? {
|
||||
true => {
|
||||
ctx.say(format!("Successfully deleted manual member info for {id}"))
|
||||
|
@ -415,6 +444,7 @@ pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(
|
|||
/// Print all manual members in manual table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_manual", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct ConfirmManual {
|
||||
#[name = "This will output the manual db as text"]
|
||||
|
@ -441,6 +471,7 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
/// Get manual member info by Discord ID
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_manual {id}", ctx.author());
|
||||
match db::get_manual_by_id(&ctx.data().db, id.id.0 as i64).await? {
|
||||
Some(m) => {
|
||||
ctx.say(format!("Manual info for {id}:\n```rust\n{m:#?}\n```"))
|
||||
|
@ -461,6 +492,10 @@ pub(crate) async fn add_manual(
|
|||
realname: String,
|
||||
fresher: bool,
|
||||
) -> Result<(), Error> {
|
||||
println!(
|
||||
"Cmd: ({}) add_manual {id}, {shortcode}, {realname}, {nickname}",
|
||||
ctx.author()
|
||||
);
|
||||
db::insert_manual(
|
||||
&ctx.data().db,
|
||||
ManualMember {
|
||||
|
@ -479,6 +514,7 @@ pub(crate) async fn add_manual(
|
|||
/// Delete all manual members in manual table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_all_manual", ctx.author());
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPurgeManual {
|
||||
#[name = "This will wipe the manual db"]
|
||||
|
|
Loading…
Reference in a new issue