poise icon indicating copy to clipboard operation
poise copied to clipboard

feature request: converters with poise context

Open sadorowo opened this issue 1 year ago • 3 comments

Currently, we can only use serenity::Context in ArgumentConvert, PopArgument and SlashArgument, because all these traits are imported from serenity. But what if we want to make a string-to-command converter? We are unable to use the ctx.framework() method in any way to get the command. The only solution would be to export the commands variable from other file, which is not a good solution.

Now the trait looks like this:

#[async_trait]
pub trait ArgumentConvert: Sized {
    type Err;

    async fn convert(
        ctx: &Context /* <- serenity::client::context::Context, NOT poise::Context<'_, Data, Error> */,
        guild_id: Option<GuildId>,
        channel_id: Option<ChannelId>,
        s: &str,
    ) -> Result<Self, Self::Err>;
}

How about creating a custom implementation, with Poise context support? It would be very helpful.

sadorowo avatar May 05 '23 17:05 sadorowo

I attempted something similar before, I think it could be made to work.

For motivation purposes and curiosity - what would you need a string-to-command converter for?

kangalio avatar May 05 '23 18:05 kangalio

I attempted something similar before, I think it could be made to work.

For motivation purposes and curiosity - what would you need a string-to-command converter for?

for e.g. custom help command, you can simply pass Command as a parameter. I know you can pass String and then get command by its name/aliases/etc. but this would be simpler.

sadorowo avatar May 06 '23 06:05 sadorowo

Yeah, that's the only use I can think of either.

You can see my attempt from two years ago here in this todo card and this commit

kangalio avatar May 06 '23 20:05 kangalio