serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
597 stars 106 forks source link

Add User Apps #266

Open fgardt opened 2 months ago

fgardt commented 2 months ago

this is the implementation for user apps that I've been using like this since 3 days after user apps got announced / released to beta.

I like the flexibility that having install_context and interaction_context being separate properties brings but there were concerns regarding usability / it being too complex.

example:

#[poise::command(
    slash_command,
    install_context = "Guild|User",
    interaction_context = "Guild|BotDm|PrivateChannel"
)]
pub async fn info(ctx: Ctx<'_>) -> Result<(), CommandError> {
  // ...command impl...
}

_note: this added the unstable_discord_api feature to the serenity dependency, that should probably be removed again(?) I have not found a nice way to feature guard this without having to chain the feature flag in everywhere and some other issues._

GnomedDev commented 2 months ago

I would recommend adding an unstable feature flag to poise, which enables the unstable_discord_api flag in serenity.

C0D3-M4513R commented 2 months ago

Also probably the docs should be updated with the new install_context and interaction_context options, if the unstable feature is enabled?

I can also confirm, that this pr works as expected, when using the current branch of serenity (as is expected).

GnomedDev commented 1 month ago

Hey, @fgardt do you plan on fixing the CI failures?

fgardt commented 1 month ago

I'll look into it yeah

techs-sus commented 1 month ago

hello, i've been testing this pr more in depth and subcommands work weirdly:

lets say you have a parent command: /bot and you want to make a "reload" command for the bot owner which reloads the bot

#[poise::command(
    slash_command,
    subcommands("reload"),
    install_context = "Guild|User",
    // hmm... only 1 command needs to be different; so lets do a non-restrictive selection
    interaction_context = "Guild|BotDm|PrivateChannel"
)]
pub async fn bot(_: Ctx<'_>) -> Result<(), CommandError> {}

#[poise::command(
    slash_command,
    owners_only,
    // great! now we can make this a botdm command to prevent confusion?
    install_context = "User",
    interaction_context = "BotDm"
)]
pub async fn reload(ctx: Ctx<'_>) -> Result<(), CommandError> {
  // ... reload logic
}

sadly, the subcommand has no control over its interaction_context or its install_context, which means the command will show up in guilds and in group dms, which is not the intended behavior

jamesbt365 commented 1 month ago

Subcommands inherit context and permissions from the parent, this is a limitation of discord itself. At most extra documentation (if there isn't any of inheriting context) can be added, but its already mentioned for permissions in our docs.

SpeckledFleebeedoo commented 2 weeks ago

Any idea when this will be merged/released? I'd like to see this functionality become available.

jamesbt365 commented 2 weeks ago

Any idea when this will be merged/released? I'd like to see this functionality become available.

You are welcome to use this as your base for the mean time but it would be nice to see the API in serenity be updated first before this rolls out. It'll happen when it does and there is no ETA for this feature.

sawa-ko commented 1 week ago

Any update on this?

jamesbt365 commented 1 week ago

Considering this isn't merged or hasn't had a single commit since your question answers itself, no, there is no update on this.