[Feature] Initial user apps support (#2883)

* omg it kinda works somehow

* more things added

* a bit of xmldocs

* added interaction framework support

* working? IF

* more builder stuff

* space

* rename attribute to prevent conflict with `ContextType` enum

* context type

* moar features

* remove integration types

* trigger workflow

* modelzzzz

* `InteractionContextType`

* allow setting custom status with `SetGameAsync`

* bugzzz

* app permissions

* message interaction context

* hm

* push for cd

* structs lets goooo

* whoops forgot to change types

* whoops x2

* tweak some things

* xmldocs + missing prop + fix enabled in dm

* moar validations

* deprecate a bunch of stuffz

* disable moar obsolete warnings

* add IF sample

* Apply suggestions from code review

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>

* Update src/Discord.Net.Rest/Entities/RestApplication.cs

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>

---------

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
This commit is contained in:
Mihail Gribkov
2024-03-19 00:24:05 +03:00
committed by GitHub
parent bfc8dc229e
commit 24a69785fe
63 changed files with 1257 additions and 300 deletions

View File

@@ -164,6 +164,8 @@ Interaction service complex parameter constructors are prioritized in the follow
3. Type's only public constuctor.
#### DM Permissions
> [!WARNING]
> [EnabledInDmAttribute] is being deprecated in favor of [CommandContextTypes] attribute.
You can use the [EnabledInDmAttribute] to configure whether a globally-scoped top level command should be enabled in Dms or not. Only works on top level commands.
@@ -419,6 +421,12 @@ Discord Slash Commands support name/description localization. Localization is av
}
```
## User Apps
User apps are the kind of Discord applications that are installed onto a user instead of a guild, thus making commands usable anywhere on Discord. Note that only users who have installed the application will see the commands. This sample shows you how to create a simple user install command.
[!code-csharp[Registering Commands Example](samples/intro/userapps.cs)]
[AutocompleteHandlers]: xref:Guides.IntFw.AutoCompletion
[DependencyInjection]: xref:Guides.DI.Intro
@@ -447,6 +455,8 @@ Discord Slash Commands support name/description localization. Localization is av
[ChannelTypesAttribute]: xref:Discord.Interactions.ChannelTypesAttribute
[MaxValueAttribute]: xref:Discord.Interactions.MaxValueAttribute
[MinValueAttribute]: xref:Discord.Interactions.MinValueAttribute
[EnabledInDmAttribute]: xref:Discord.Interactions.EnabledInDmAttribute
[CommandContextTypes]: xref:Discord.Interactions.CommandContextTypesAttribute
[IChannel]: xref:Discord.IChannel
[IRole]: xref:Discord.IRole

View File

@@ -0,0 +1,19 @@
// This parameteres can be configured on the module level
// Set supported command context types to Bot DMs and Private Channels (regular DM & GDM)
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
// Set supported integration installation type to User Install
[IntegrationType(ApplicationIntegrationType.UserInstall)]
public class CommandModule() : InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("test", "Just a test command")]
public async Task TestCommand()
=> await RespondAsync("Hello There");
// But can also be overridden on the command level
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel, InteractionContextType.Guild)]
[IntegrationType(ApplicationIntegrationType.GuildInstall)]
[SlashCommand("echo", "Echo the input")]
public async Task EchoCommand(string input)
=> await RespondAsync($"You said: {input}");
}

View File

@@ -1,11 +1,11 @@
- name: Home
href: index.md
- name: Documentation
href: api/
topicUid: API.Docs
- name: Guides
href: guides/
topicUid: Guides.Introduction
- name: API Reference
href: api/
topicUid: API.Docs
- name: FAQ
href: faq/
topicUid: FAQ.Basics.GetStarted