From 4b9962dd66282654dd6703f32e669aee8b2c7a12 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Fri, 15 Nov 2024 15:11:38 +0100 Subject: [PATCH] context menu command test --- src/commands/accountv2.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/commands/accountv2.rs b/src/commands/accountv2.rs index 7ec3f25..43199eb 100644 --- a/src/commands/accountv2.rs +++ b/src/commands/accountv2.rs @@ -5,7 +5,7 @@ use serenity::{ all::{ChannelId, CreateActionRow, CreateAllowedMentions, CreateButton, CreateMessage, ReactionType, User}, json::JsonError, }; -use serenity::all::ButtonStyle; +use serenity::all::{ButtonStyle, Message}; use sqlx::{Pool, query_as, Sqlite}; use crate::commands::command_helper::cooldown; @@ -252,6 +252,21 @@ pub(crate) async fn list(ctx: Context<'_>, user: Option) -> Result<(), Err Ok(()) } +#[poise::command(context_menu_command="list accounts")] +pub(crate) async fn context_list(ctx: Context<'_>, m: Message) -> Result<(), Error> { + ctx.defer_ephemeral().await?; + cooldown(&ctx, 600, 300)?; + let pool: &Pool = &ctx.data().sqlite_pool; + let s: String = list_string(pool, &m.author).await?; + let r: CreateReply = CreateReply::default().ephemeral(true); + ctx.send( + r.content(s) + .allowed_mentions(CreateAllowedMentions::new().empty_roles().empty_users()), + ) + .await?; + Ok(()) +} + pub(crate) async fn list_string(pool: &Pool, user: &User) -> Result { let link_id: u16 = link_id_from_discord(pool, user.id.get()) .await @@ -295,7 +310,7 @@ async fn link_id_from_discord(pool: &Pool, snowflake: u64) -> Option