-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,356 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
# 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) | ||
|
||
An unofficial .NET API Wrapper for the Discord client (http://discordapp.com). | ||
An unofficial .NET API Wrapper for the Discord client (https://discordapp.com). | ||
|
||
Check out the [documentation](https://discord.foxbot.me/docs/) or join the [Discord API Chat](https://discord.gg/jkrBmQR). | ||
This branch is an unstable reference design of the next major release, Discord.Net v3. Currently, this branch | ||
does not offer any functionality, and is only being used for API design. | ||
|
||
## Installation | ||
### Stable (NuGet) | ||
Our stable builds available from NuGet through the Discord.Net metapackage: | ||
- [Discord.Net](https://www.nuget.org/packages/Discord.Net/) | ||
## Contributing | ||
|
||
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/) | ||
This branch is being developed on preview releases of .NET Core and Visual Studio; the following features | ||
are necessary to contribute: | ||
- C# 8 with Nullable Reference Types and IAsyncEnumerable | ||
- .NET Core 3 with ValueTask support | ||
|
||
### Unstable (MyGet) | ||
Nightly builds are available through our MyGet feed (`https://www.myget.org/F/discord-net/api/v3/index.json`). | ||
The following configurations are known to work: | ||
- Visual Studio 2019 16.2 Preview 3 | ||
- .NET Core SDK 3.0.100-preview6-012264 | ||
|
||
## Compiling | ||
In order to compile Discord.Net, you require the following: | ||
### Documentation | ||
|
||
### Using Visual Studio | ||
- [Visual Studio 2017](https://www.microsoft.com/net/core#windowsvs2017) | ||
- [.NET Core SDK](https://www.microsoft.com/net/download/core) | ||
Documentation Strings are currently being left out, primarily because I find them extremely distracting when | ||
trying to read over long interfaces, but also because this design will likely be iterated on before being finalized, | ||
and it would be annoying to have to move docstrings around. | ||
|
||
The .NET Core workload must be selected during Visual Studio installation. | ||
Please leave docstrings out of contributions until the implementation round is finished. | ||
|
||
### 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. | ||
Usability documentation is being provided in sample solutions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Discord; | ||
|
||
namespace Sample | ||
{ | ||
public class Program | ||
{ | ||
static void Main() | ||
=> new Program().MainAsync().GetAwaiter().GetResult(); | ||
public async Task MainAsync() | ||
{ | ||
string token = "abc"; | ||
var client = DiscordClientBuilder.FromConfig(new DiscordClientConfig | ||
{ | ||
Token = token, | ||
DefaultStateBehavior = StateBehavior.SyncOnly | ||
}); | ||
await client.StartAndWaitAsync(); | ||
|
||
client.MessageCreated += msg => Task.Run(() => OnMessageCreated(msg)).Observe(); | ||
|
||
await Task.Delay(-1); | ||
} | ||
public async Task OnMessageCreated(IMessage msg) | ||
{ | ||
if (!(msg is IUserMessage message)) | ||
return; | ||
var guild = await msg.GetGuildAsync(); | ||
if (guild == null) | ||
return; | ||
var owner = await guild.GetOwnerAsync(); | ||
var dm = await (await owner.GetUserAsync()).GetOrCreateDMChannelAsync(); | ||
await dm.SendMessageAsync($"{msg.Author} said: {msg.Content}"); | ||
} | ||
} | ||
|
||
public static class TaskExtensions | ||
{ | ||
public static void Observe(this Task task) | ||
{ | ||
task.ContinueWith(t => | ||
{ | ||
if (t.IsFaulted) | ||
{ | ||
var flattened = t.Exception.Flatten(); | ||
foreach (var ex in flattened.InnerExceptions) | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>7.3</LangVersion> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> <!-- TODO: netstandard3/.NET 5/whatever is mainstream when we release --> | ||
<LangVersion>8.0</LangVersion> | ||
<RootNamespace>Discord</RootNamespace> | ||
<Nullable>Enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" /> | ||
<PackageReference Include="Wumpus.Net.Gateway" Version="0.2.2-build-00031" /> | ||
<PackageReference Include="Wumpus.Net.Rest" Version="0.2.2-build-00031" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Models\Emotes\" /> | ||
<Folder Include="Models\Guilds\" /> | ||
<Folder Include="Models\Roles\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// todo: meth | ||
// todo: props | ||
// todo: docs | ||
namespace Discord | ||
{ | ||
public interface IActivity | ||
{ | ||
string Name { get; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Discord.Net/Entities/Channels/GuildChannelProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// todo: docs | ||
using Voltaic; | ||
using Wumpus; | ||
using Model = Wumpus.Requests.ModifyChannelParams; | ||
|
||
namespace Discord | ||
{ | ||
public class GuildChannelProperties | ||
{ | ||
public Optional<string> Name { get; set; } | ||
public Optional<int> Position { get; set; } | ||
public Optional<SnowflakeOrEntity<ICategoryChannel>?> Category { get; set; } | ||
|
||
internal virtual Model ToWumpus() | ||
{ | ||
var model = new Model(); | ||
if (Name.IsSpecified) | ||
model.Name = new Utf8String(Name.Value); | ||
model.Position = Position; | ||
if (Category.IsSpecified) | ||
{ | ||
model.ParentId = Category.Value.HasValue ? Category.Value.Value.Id : (Snowflake?)null; | ||
} | ||
|
||
return model; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// todo: docs | ||
namespace Discord | ||
{ | ||
// review: another marker interface 😕 | ||
public interface ICategoryChannel : IGuildChannel | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// TODO: docs | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IChannel : ISnowflakeEntity | ||
{ | ||
string Name { get; } | ||
|
||
ValueTask<IUser> GetUserAsync(ulong id, StateBehavior stateBehavior = default, RequestOptions? options = default); | ||
IAsyncEnumerable<IUser> GetUsersAsync(StateBehavior stateBehavior = default, RequestOptions? options = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// todo: docs | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IDMChannel : IMessageChannel | ||
{ | ||
ValueTask<IUser> GetRecipientAsync(StateBehavior stateBehavior, RequestOptions? options = default); | ||
ulong RecipientId { get; } | ||
|
||
// not applicable: CloseAsync | ||
} | ||
} |
Oops, something went wrong.