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