Skip to content

Commit b14af1c

Browse files
authored
Adding Entity guides, flowcharts, better sample system. (#2054)
* initial * Interaction glossary entry * Sharded Interaction sample * Renames into solution * Debugging samples * Modify target location for webhookclient * Finalizing docs work, resolving docfx errors. * Adding threaduser to user chart * Add branch info to readme. * Edits to user chart * Resolve format for glossary entries * Patch sln target * Issue with file naming fixed * Patch 1/x for builds * Appending suggestions
1 parent b0f59e3 commit b14af1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1056
-341
lines changed

Discord.Net.sln

Lines changed: 121 additions & 106 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,22 @@ Due to the nature of the Discord API, we will oftentimes need to add a property
8181
Furthermore, while we will never break the API (outside of interface changes) on minor builds, we will occasionally need to break the ABI, by introducing parameters to a method to match changes upstream with Discord. As such, a minor version increment may require you to recompile your code, and dependencies, such as addons, may also need to be recompiled and republished on the newer version. When a binary breaking change is made, the change will be noted in the release notes.
8282

8383
An increment of the MAJOR component indicates that breaking changes have been made to the library; consumers should check the release notes to determine what changes need to be made.
84+
85+
## Branches
86+
87+
### Release/X.X
88+
89+
Release branch following Major.Minor. Upon release, patches will be pushed to these branches.
90+
New NuGet releases will be tagged on these branches.
91+
92+
### Dev
93+
94+
Development branch, available on MyGet. This branch is what pull requests are targetted to.
95+
96+
### Feature/X
97+
98+
Branches that target Dev, adding new features. Feel free to explore these branches and give feedback where necessary.
99+
100+
### Docs/X
101+
102+
Usually targets Dev. These branches are used to update documentation with either new features or existing feature rework.

docs/faq/basics/basic-operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ able to message.
5353
You may check the message channel type. Visit [Glossary] to see the
5454
various types of channels.
5555

56-
[glossary]: xref:FAQ.Glossary#message-channels
56+
[Glossary]: xref:Guides.Entities.Glossary#channels
5757

5858
## How can I get the guild from a message?
5959

docs/faq/misc/legacy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Visit the repo's [release tag] to see the latest public pre-release.
2424

2525
The `DependencyMap` has been replaced with Microsoft's
2626
[DependencyInjection] Abstractions. An example usage can be seen
27-
[here](https://github.com/foxbot/DiscordBotBase/blob/csharp/src/DiscordBot/Program.cs#L36).
27+
[here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/release/3.x/samples/InteractionFramework/Program.cs#L66).
2828

2929
[DependencyInjection]: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection

docs/faq/toc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@
1616
topicUid: FAQ.Commands.Interactions
1717
- name: Dependency Injection
1818
topicUid: FAQ.Commands.DI
19-
- name: Glossary
20-
topicUid: FAQ.Glossary
2119
- name: Legacy or Upgrade
2220
topicUid: FAQ.Legacy

docs/guides/entities/casting.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
uid: Guides.Entities.Casting
3+
title: Casting & Unboxing
4+
---
5+
6+
# Casting
7+
8+
Casting can be done in many ways, and is the only method to box and unbox types to/from their base definition.
9+
Casting only works for types that inherit the base type that you want to unbox from.
10+
`IUser` cannot be cast to `IMessage`.
11+
12+
> [!NOTE]
13+
> Interfaces **can** be cast to other interfaces, as long as they inherit each other.
14+
> The same goes for reverse casting. As long as some entity can be simplified into what it inherits, your cast will pass.
15+
16+
## Boxing
17+
18+
A boxed object is the definition of an object that was simplified (or trimmed) by incoming traffic,
19+
but still owns the data of the originally constructed type. Boxing is an implicit operation.
20+
21+
Through casting, we can **unbox** this type, and access the properties that were unaccessible before.
22+
23+
## Unboxing
24+
25+
Unboxing is the most direct way to access the real definition of an object.
26+
If we want to return a type from its interface, we can unbox it directly.
27+
28+
[!code-csharp[Unboxing](samples/unboxing.cs)]
29+
30+
## Regular casting
31+
32+
In 'regular' casting, we use the `as` keyword to assign the given type to the object.
33+
If the boxed type can indeed be cast into given type,
34+
it will become said type, and its properties can be accessed.
35+
[!code-csharp[Casting](samples/casting.cs)]
36+
37+
> [!WARNING]
38+
> If the type you're casting to is null, a `NullReferenceException` will be thrown when it's called.
39+
> This makes safety casting much more interesting to use, as it prevents this exception from being thrown.
40+
41+
## Safety casting
42+
43+
Safety casting makes sure that the type you're trying to cast to can never be null, as it passes checks upon calling them.
44+
45+
There are 3 different ways to safety cast an object:
46+
47+
### Basic safety casting:
48+
49+
To safety cast an object, all we need to do is check if it is of the member type in a statement.
50+
If this check fails, it will continue below, making sure we don't try to access null.
51+
[!code-csharp[Base](samples/safety-cast.cs)]
52+
53+
### Object declaration:
54+
55+
Here we declare the object we are casting to,
56+
making it so that you can immediately work with its properties without reassigning through regular casting.
57+
[!code-csharp[Declare](samples/safety-cast-var.cs)]
58+
59+
### Reverse passage:
60+
61+
In previous examples, we want to let code continue running after the check, or if the check fails.
62+
In this example, the cast will return the entire method (ignoring the latter) upon failure,
63+
and declare the variable for further use into the method:
64+
[!code-csharp[Pass](samples/safety-cast-pass.cs)]
65+
66+
> [!NOTE]
67+
> Usage of `is`, `not` and `as` is required in cast assignment and/or type checks. `==`, `!=` and `=` are invalid assignment,
68+
> as these operators only apply to initialized objects and not their types.

docs/faq/misc/glossary.md renamed to docs/guides/entities/glossary.md

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
---
2-
uid: FAQ.Glossary
3-
title: Common Terminologies / Glossary
2+
uid: Guides.Entities.Glossary
3+
title: Glossary & Flowcharts
44
---
55

6-
# Glossary
6+
# Entity Types
77

8-
This is an additional chapter for quick references to various common
9-
types that you may see within Discord.Net. To see more information
10-
regarding each type of object, click on the object to navigate
11-
to our API documentation page where you might find more explanation
12-
about it.
8+
A list of all Discord.Net entities, what they can be cast to and what their properties are.
139

14-
## Common Types
15-
16-
* A **Guild** ([IGuild]) is an isolated collection of users and
17-
channels, and are often referred to as "servers".
18-
- Example: [Discord API](https://discord.gg/jkrBmQR)
19-
* A **Channel** ([IChannel]) represents a generic channel.
20-
- Example: #dotnet_discord-net
21-
- See [Channel Types](#channel-types)
10+
> [!NOTE]
11+
> All interfaces have the same inheritance tree for both `Socket` and `Rest` entities.
12+
> Entities with that have been marked red are exclusive to the project they source from.
2213
23-
[IGuild]: xref:Discord.IGuild
24-
[IChannel]: xref:Discord.IChannel
14+
## Channels
2515

26-
## Channel Types
16+
![IChannelChart](images/IChannel.png)
2717

2818
### Message Channels
2919
* A **Text Channel** ([ITextChannel]) is a message channel from a Guild.
@@ -40,14 +30,11 @@ channels, and are often referred to as "servers".
4030
- This can be any channels that may exist in a guild.
4131
* A **Voice Channel** ([IVoiceChannel]) is a voice channel in a guild.
4232
* A **Stage Channel** ([IStageChannel]) is a stage channel in a guild.
43-
* A **Category Channel** ([ICategoryChannel]) (2.0+) is a category that
33+
* A **Category Channel** ([ICategoryChannel]) is a category that
4434
holds one or more sub-channels.
45-
* A **Nested Channel** ([INestedChannel]) (2.0+) is a channel that can
35+
* A **Nested Channel** ([INestedChannel]) is a channel that can
4636
exist under a category.
4737

48-
> [!NOTE]
49-
> A Channel ([IChannel]) can be all types of channels.
50-
5138
[INestedChannel]: xref:Discord.INestedChannel
5239
[IGuildChannel]: xref:Discord.IGuildChannel
5340
[IMessageChannel]: xref:Discord.IMessageChannel
@@ -62,17 +49,27 @@ exist under a category.
6249
[IStageChannel]: xref:Discord.IStageChannel
6350
[INewsChannel]: xref:Discord.INewsChannel
6451

65-
## Message Types
52+
## Messages
53+
54+
![IMessageChart](images/IMessage.png)
6655

56+
* A **Rest Followup Message** ([RestFollowupMessage]) is a message returned by followup on on an interaction.
57+
* A **Rest Interaction Message** ([RestInteractionMessage]) is a message returned by the interaction's original response.
58+
* A **Rest User Message** ([RestUserMessage]) is a message sent over rest; it can be any of the above.
6759
* An **User Message** ([IUserMessage]) is a message sent by a user.
6860
* A **System Message** ([ISystemMessage]) is a message sent by Discord itself.
6961
* A **Message** ([IMessage]) can be any of the above.
7062

63+
[RestFollowupMessage]: xref:Discord.Rest.RestFollowupMessage
64+
[RestInteractionMessage]: xref:Discord.Rest.RestInteractionMessage
65+
[RestUserMEssage]: xref:Discord.Rest.RestUserMessage
7166
[IUserMessage]: xref:Discord.IUserMessage
7267
[ISystemMessage]: xref:Discord.ISystemMessage
7368
[IMessage]: xref:Discord.IMessage
7469

75-
## User Types
70+
## Users
71+
72+
![IUserChart](images/IUser.png)
7673

7774
* A **Guild User** ([IGuildUser]) is a user available inside a guild.
7875
* A **Group User** ([IGroupUser]) is a user available inside a group.
@@ -85,7 +82,29 @@ exist under a category.
8582
[ISelfUser]: xref:Discord.ISelfUser
8683
[IUser]: xref:Discord.IUser
8784

88-
## Emoji Types
85+
## Interactions
86+
87+
![IInteractionChart](images/IInteraction.png)
88+
89+
* A **Slash command** ([ISlashCommandInteraction]) is an application command executed in the text box, with provided parameters.
90+
* A **Message Command** ([IMessageCommandInteraction]) is an application command targetting a message.
91+
* An **User Command** ([IUserCommandInteraction]) is an application command targetting a user.
92+
* An **Application Command** ([IApplicationCommandInteraction]) is any of the above.
93+
* A **Message component** ([IMessageComponent]) is the interaction of a button being clicked/dropdown option(s) entered.
94+
* An **Autocomplete Interaction** ([IAutocompleteinteraction]) is an interaction that has been automatically completed.
95+
* An **Interaction** ([IDiscordInteraction]) is any of the above.
96+
97+
[ISlashCommandInteraction]: xref:Discord.ISlashCommandInteraction
98+
[IMessageCommandInteraction]: xref:Discord.IMessageCommandInteraction
99+
[IUserCommandInteraction]: xref:Discord.IUserCommandInteraction
100+
[IApplicationCommandInteraction]: xref:Discord.IApplicationCommandInteraction
101+
[IMessageComponent]: xref:Discord.IMessageComponent
102+
[IAutocompleteinteraction]: xref:Discord.IAutocompleteInteraction
103+
[IDiscordInteraction]: xref:Discord.IDiscordInteraction
104+
105+
## Other types:
106+
107+
### Emoji
89108

90109
* An **Emote** ([Emote]) is a custom emote from a guild.
91110
- Example: `<:dotnet:232902710280716288>`
@@ -95,16 +114,15 @@ exist under a category.
95114
[Emote]: xref:Discord.Emote
96115
[Emoji]: xref:Discord.Emoji
97116

98-
99-
## Sticker Types
117+
### Stickers
100118

101119
* A **Sticker** ([ISticker]) is a standard Discord sticker.
102120
* A **Custom Sticker ([ICustomSticker]) is a Guild-unique sticker.
103121

104122
[ISticker]: xref:Discord.ISticker
105123
[ICustomSticker]: xref:Discord.ICustomSticker
106124

107-
## Activity Types
125+
### Activity
108126

109127
* A **Game** ([Game]) refers to a user's game activity.
110128
* A **Rich Presence** ([RichGame]) refers to a user's detailed
58.2 KB
Loading
36.9 KB
Loading
36.1 KB
Loading

0 commit comments

Comments
 (0)