Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3: API design review #1340

Draft
wants to merge 10 commits into
base: blank
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,6 @@ docs/api/\.manifest
\.idea/

# Codealike UID
codealike.json
codealike.json

*.ignore
73 changes: 73 additions & 0 deletions Discord.Net.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5DAC796B-0B77-4F84-B790-83DB78C6DFFE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net", "src\Discord.Net\Discord.Net.csproj", "{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{4795640A-030C-4A9A-A9B0-20C56AF4DA3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "idn", "sample\idn\idn.csproj", "{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{68EE1EAC-F487-4BAC-917B-233370B3AEA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Tests.Unit", "test\Discord.Tests.Unit\Discord.Tests.Unit.csproj", "{6AD4FF67-D45E-4E7E-8853-990390D35C9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|x64.ActiveCfg = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|x64.Build.0 = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|x86.ActiveCfg = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Debug|x86.Build.0 = Debug|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|Any CPU.Build.0 = Release|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|x64.ActiveCfg = Release|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|x64.Build.0 = Release|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|x86.ActiveCfg = Release|Any CPU
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370}.Release|x86.Build.0 = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|x64.ActiveCfg = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|x64.Build.0 = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|x86.ActiveCfg = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Debug|x86.Build.0 = Debug|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|Any CPU.Build.0 = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|x64.ActiveCfg = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|x64.Build.0 = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|x86.ActiveCfg = Release|Any CPU
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A}.Release|x86.Build.0 = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|x64.ActiveCfg = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|x64.Build.0 = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Debug|x86.Build.0 = Debug|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|Any CPU.Build.0 = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|x64.ActiveCfg = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|x64.Build.0 = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|x86.ActiveCfg = Release|Any CPU
{6AD4FF67-D45E-4E7E-8853-990390D35C9F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3194F5DC-C0AF-4459-AAA3-91CB8FB8C370} = {5DAC796B-0B77-4F84-B790-83DB78C6DFFE}
{5BE5DE89-53B7-4243-AEA8-FD8A6420908A} = {4795640A-030C-4A9A-A9B0-20C56AF4DA3F}
{6AD4FF67-D45E-4E7E-8853-990390D35C9F} = {68EE1EAC-F487-4BAC-917B-233370B3AEA1}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Discord.Net Contributors
Copyright (c) 2015-2020 Discord.Net Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
41 changes: 2 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
# Discord.Net
[![NuGet](https://img.shields.io/nuget/vpre/Discord.Net.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net)
[![MyGet](https://img.shields.io/myget/discord-net/vpre/Discord.Net.svg)](https://www.myget.org/feed/Packages/discord-net)
[![Build status](https://ci.appveyor.com/api/projects/status/5sb7n8a09w9clute/branch/dev?svg=true)](https://ci.appveyor.com/project/RogueException/discord-net/branch/dev)
[![Discord](https://discordapp.com/api/guilds/81384788765712384/widget.png)](https://discord.gg/jkrBmQR)
# Discord.Net 2020

An unofficial .NET API Wrapper for the Discord client (http://discordapp.com).

Check out the [documentation](https://discord.foxbot.me/docs/) or join the [Discord API Chat](https://discord.gg/jkrBmQR).

## Installation
### Stable (NuGet)
Our stable builds available from NuGet through the Discord.Net metapackage:
- [Discord.Net](https://www.nuget.org/packages/Discord.Net/)

The individual components may also be installed from NuGet:
- [Discord.Net.Commands](https://www.nuget.org/packages/Discord.Net.Commands/)
- [Discord.Net.Rest](https://www.nuget.org/packages/Discord.Net.Rest/)
- [Discord.Net.WebSocket](https://www.nuget.org/packages/Discord.Net.WebSocket/)
- [Discord.Net.Webhook](https://www.nuget.org/packages/Discord.Net.Webhook/)

### Unstable (MyGet)
Nightly builds are available through our MyGet feed (`https://www.myget.org/F/discord-net/api/v3/index.json`).

## Compiling
In order to compile Discord.Net, you require the following:

### Using Visual Studio
- [Visual Studio 2017](https://www.microsoft.com/net/core#windowsvs2017)
- [.NET Core SDK](https://www.microsoft.com/net/download/core)

The .NET Core workload must be selected during Visual Studio installation.

### Using Command Line
- [.NET Core SDK](https://www.microsoft.com/net/download/core)

## Known Issues

### WebSockets (Win7 and earlier)
.NET Core 1.1 does not support WebSockets on Win7 and earlier. This issue has been fixed since the release of .NET Core 2.1. It is recommended to target .NET Core 2.1 or above for your project if you wish to run your bot on legacy platforms; alternatively, you may choose to install the [Discord.Net.Providers.WS4Net](https://www.nuget.org/packages/Discord.Net.Providers.WS4Net/) package.
Rewrite branch, work in progress.
37 changes: 37 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- REST
- Models
- Preconditions
- Endpoints
- Channel
- Emoji
- Guild
- Invite
- User
- Voice
- Webhook
- Ratelimiter with refit
- Gateway
- Models
- Client
- Socket
- use token
* Receive
* Compression
- Voice (long)
- Core
- CDN
- Datastore
- Entities
- Channel
- Emoji
- Guild
- User
- Utilities
- Token Validation (port from @ChrisJ)
- Tests
- Unit test Gateway stability / deadlockability?
- Port ChrisJ's token validator tests
- Extensions
- Commands
? design - use finite's or quahu's
- Interactivity
Empty file added doc/.gitkeep
Empty file.
106 changes: 106 additions & 0 deletions ep.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
https://gist.github.com/SinisterRectus/9518f3e7d0d1ccb4335b2a0d389c30b0

Sorted By Route
--------------------------------------------------------------------------------------------------------------------
Get Entitlements GET /applications/{application.id}/entitlements
Get Entitlement GET /applications/{application.id}/entitlements/{entitlement.id}
Delete Test Entitlement DELETE /applications/{application.id}/entitlements/{entitlement.id}/
Consume SKU POST /applications/{application.id}/entitlements/{entitlement.id}/consume
Get SKUs GET /applications/{application.id}/skus
Delete/Close Channel DELETE /channels/{channel.id}
Get Channel GET /channels/{channel.id}
Modify Channel PUT/PATCH /channels/{channel.id}
Get Channel Invites GET /channels/{channel.id}/invites
Create Channel Invite POST /channels/{channel.id}/invites
Get Channel Messages GET /channels/{channel.id}/messages
Create Message POST /channels/{channel.id}/messages
Bulk Delete Messages POST /channels/{channel.id}/messages/bulk-delete
Bulk Delete Messages (deprecated) POST /channels/{channel.id}/messages/bulk_delete
Delete Message DELETE /channels/{channel.id}/messages/{message.id}
Get Channel Message GET /channels/{channel.id}/messages/{message.id}
Edit Message PATCH /channels/{channel.id}/messages/{message.id}
Delete All Reactions DELETE /channels/{channel.id}/messages/{message.id}/reactions
Get Reactions GET /channels/{channel.id}/messages/{message.id}/reactions/{emoji}
Delete Own Reaction DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me
Create Reaction PUT /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me
Delete User Reaction DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/{user.id}
Delete Channel Permission DELETE /channels/{channel.id}/permissions/{overwrite.id}
Edit Channel Permissions PUT /channels/{channel.id}/permissions/{overwrite.id}
Get Pinned Messages GET /channels/{channel.id}/pins
Delete Pinned Channel Message DELETE /channels/{channel.id}/pins/{message.id}
Add Pinned Channel Message PUT /channels/{channel.id}/pins/{message.id}
Group DM Remove Recipient DELETE /channels/{channel.id}/recipients/{user.id}
Group DM Add Recipient PUT /channels/{channel.id}/recipients/{user.id}
Trigger Typing Indicator POST /channels/{channel.id}/typing
Get Channel Webhooks GET /channels/{channel.id}/webhooks
Create Webhook POST /channels/{channel.id}/webhooks
Get Gateway GET /gateway
Get Gateway Bot GET /gateway/bot
Create Guild POST /guilds
Delete Guild DELETE /guilds/{guild.id}
Get Guild GET /guilds/{guild.id}
Modify Guild PATCH /guilds/{guild.id}
Get Guild Audit Log GET /guilds/{guild.id}/audit-logs
Get Guild Bans GET /guilds/{guild.id}/bans
Remove Guild Ban DELETE /guilds/{guild.id}/bans/{user.id}
Get Guild Ban GET /guilds/{guild.id}/bans/{user.id}
Create Guild Ban PUT /guilds/{guild.id}/bans/{user.id}
Get Guild Channels GET /guilds/{guild.id}/channels
Modify Guild Channel Positions PATCH /guilds/{guild.id}/channels
Create Guild Channel POST /guilds/{guild.id}/channels
Get Guild Embed GET /guilds/{guild.id}/embed
Modify Guild Embed PATCH /guilds/{guild.id}/embed
List Guild Emojis GET /guilds/{guild.id}/emojis
Create Guild Emoji POST /guilds/{guild.id}/emojis
Delete Guild Emoji DELETE /guilds/{guild.id}/emojis/{emoji.id}
Get Guild Emoji GET /guilds/{guild.id}/emojis/{emoji.id}
Modify Guild Emoji PATCH /guilds/{guild.id}/emojis/{emoji.id}
Get Guild Integrations GET /guilds/{guild.id}/integrations
Create Guild Integration POST /guilds/{guild.id}/integrations
Delete Guild Integration DELETE /guilds/{guild.id}/integrations/{integration.id}
Modify Guild Integration PATCH /guilds/{guild.id}/integrations/{integration.id}
Sync Guild Integration POST /guilds/{guild.id}/integrations/{integration.id}/sync
Get Guild Invites GET /guilds/{guild.id}/invites
List Guild Members GET /guilds/{guild.id}/members
Modify Current User Nick PATCH /guilds/{guild.id}/members/@me/nick
Remove Guild Member DELETE /guilds/{guild.id}/members/{user.id}
Get Guild Member GET /guilds/{guild.id}/members/{user.id}
Modify Guild Member PATCH /guilds/{guild.id}/members/{user.id}
Add Guild Member PUT /guilds/{guild.id}/members/{user.id}
Remove Guild Member Role DELETE /guilds/{guild.id}/members/{user.id}/roles/{role.id}
Add Guild Member Role PUT /guilds/{guild.id}/members/{user.id}/roles/{role.id}
Get Guild Prune Count GET /guilds/{guild.id}/prune
Begin Guild Prune POST /guilds/{guild.id}/prune
Get Guild Voice Regions GET /guilds/{guild.id}/regions
Get Guild Roles GET /guilds/{guild.id}/roles
Modify Guild Role Positions PATCH /guilds/{guild.id}/roles
Create Guild Role POST /guilds/{guild.id}/roles
Delete Guild Role DELETE /guilds/{guild.id}/roles/{role.id}
Modify Guild Role PATCH /guilds/{guild.id}/roles/{role.id}
Get Guild Vanity URL GET /guilds/{guild.id}/vanity-url
Get Guild Webhooks GET /guilds/{guild.id}/webhooks
Get Guild Widget Image GET /guilds/{guild.id}/widget.png
Delete Invite DELETE /invites/{invite.code}
Get Invite GET /invites/{invite.code}
Get Current Application Information GET /oauth2/applications/@me
Delete Purchase Discount DELETE /store/skus/{sku.id}/discounts/{user.id}/
Create Purchase Discount PUT /store/skus/{sku.id}/discounts/{user.id}/
Get Current User GET /users/@me
Modify Current User PATCH /users/@me
Get User DMs GET /users/@me/channels
Create DM POST /users/@me/channels
Create Group DM POST /users/@me/channels
Get User Connections GET /users/@me/connections
Get Current User Guilds GET /users/@me/guilds
Leave Guild DELETE /users/@me/guilds/{guild.id}
Get User GET /users/{user.id}
List Voice Regions GET /voice/regions
Delete Webhook DELETE /webhooks/{webhook.id}
Get Webhook GET /webhooks/{webhook.id}
Modify Webhook PATCH /webhooks/{webhook.id}
Delete Webhook with Token DELETE /webhooks/{webhook.id}/{webhook.token}
Get Webhook with Token GET /webhooks/{webhook.id}/{webhook.token}
Modify Webhook with Token PATCH /webhooks/{webhook.id}/{webhook.token}
Execute Webhook POST /webhooks/{webhook.id}/{webhook.token}
Execute GitHub-Compatible Webhook POST /webhooks/{webhook.id}/{webhook.token}/github
Execute Slack-Compatible Webhook POST /webhooks/{webhook.id}/{webhook.token}/slack
Empty file added sample/.gitkeep
Empty file.
74 changes: 74 additions & 0 deletions sample/idn/Inspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections;
using System.Linq;
using System.Reflection;
using System.Text;

namespace idn
{
public static class Inspector
{
public static string Inspect(object value)
{
var builder = new StringBuilder();
if (value != null)
{
var type = value.GetType().GetTypeInfo();
builder.AppendLine($"[{type.Namespace}.{type.Name}]");
builder.AppendLine($"{InspectProperty(value)}");

if (value is IEnumerable)
{
var items = (value as IEnumerable).Cast<object>().ToArray();
if (items.Length > 0)
{
builder.AppendLine();
foreach (var item in items)
builder.AppendLine($"- {InspectProperty(item)}");
}
}
else
{
var groups = type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(x => x.GetIndexParameters().Length == 0)
.GroupBy(x => x.Name)
.OrderBy(x => x.Key)
.ToArray();
if (groups.Length > 0)
{
builder.AppendLine();
int pad = groups.Max(x => x.Key.Length) + 1;
foreach (var group in groups)
builder.AppendLine($"{group.Key.PadRight(pad, ' ')}{InspectProperty(group.First().GetValue(value))}");
}
}
}
else
builder.AppendLine("null");
return builder.ToString();
}

private static string InspectProperty(object obj)
{
if (obj == null)
return "null";

var type = obj.GetType();

var debuggerDisplay = type.GetProperty("DebuggerDisplay", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (debuggerDisplay != null)
return debuggerDisplay.GetValue(obj).ToString();

var toString = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.Where(x => x.Name == "ToString" && x.DeclaringType != typeof(object))
.FirstOrDefault();
if (toString != null)
return obj.ToString();

var count = type.GetProperty("Count", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (count != null)
return $"[{count.GetValue(obj)} Items]";

return obj.ToString();
}
}
}
Loading