Browse Source

Removed Server.Invites, added DiscordClient.GetInvites(server)

tags/docs-0.9
RogueException 9 years ago
parent
commit
bf5d9ec527
5 changed files with 33 additions and 23 deletions
  1. +8
    -7
      src/Discord.Net/API/Endpoints.cs
  2. +2
    -0
      src/Discord.Net/API/Invites.cs
  3. +6
    -0
      src/Discord.Net/DiscordAPIClient.cs
  4. +17
    -2
      src/Discord.Net/DiscordClient.Invites.cs
  5. +0
    -14
      src/Discord.Net/Models/Server.cs

+ 8
- 7
src/Discord.Net/API/Endpoints.cs View File

@@ -13,33 +13,34 @@
public const string Channels = "channels"; public const string Channels = "channels";
public static string Channel(string channelId) => $"channels/{channelId}"; public static string Channel(string channelId) => $"channels/{channelId}";
public static string ChannelTyping(string channelId) => $"channels/{channelId}/typing";
public static string ChannelInvites(string channelId) => $"channels/{channelId}/invites";
public static string ChannelMessages(string channelId) => $"channels/{channelId}/messages"; public static string ChannelMessages(string channelId) => $"channels/{channelId}/messages";
public static string ChannelMessages(string channelId, int limit) => $"channels/{channelId}/messages?limit={limit}"; public static string ChannelMessages(string channelId, int limit) => $"channels/{channelId}/messages?limit={limit}";
public static string ChannelMessages(string channelId, int limit, string beforeId) => $"channels/{channelId}/messages?limit={limit}&before={beforeId}"; public static string ChannelMessages(string channelId, int limit, string beforeId) => $"channels/{channelId}/messages?limit={limit}&before={beforeId}";
public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}"; public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessageAck(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}/ack"; public static string ChannelMessageAck(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}/ack";
public static string ChannelInvites(string channelId) => $"channels/{channelId}/invites";
public static string ChannelPermission(string channelId, string userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}"; public static string ChannelPermission(string channelId, string userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}";
public static string ChannelTyping(string channelId) => $"channels/{channelId}/typing";


public const string Servers = "guilds"; public const string Servers = "guilds";
public static string Server(string serverId) => $"guilds/{serverId}"; public static string Server(string serverId) => $"guilds/{serverId}";
public static string ServerBan(string serverId, string userId) => $"guilds/{serverId}/bans/{userId}";
public static string ServerChannels(string serverId) => $"guilds/{serverId}/channels"; public static string ServerChannels(string serverId) => $"guilds/{serverId}/channels";
public static string ServerInvites(string serverId) => $"guilds/{serverId}/invites";
public static string ServerMember(string serverId, string userId) => $"guilds/{serverId}/members/{userId}"; public static string ServerMember(string serverId, string userId) => $"guilds/{serverId}/members/{userId}";
public static string ServerBan(string serverId, string userId) => $"guilds/{serverId}/bans/{userId}";
public static string ServerPrune(string serverId, int days) => $"guilds/{serverId}/prune?days={days}";
public static string ServerRoles(string serverId) => $"guilds/{serverId}/roles"; public static string ServerRoles(string serverId) => $"guilds/{serverId}/roles";
public static string ServerRole(string serverId, string roleId) => $"guilds/{serverId}/roles/{roleId}"; public static string ServerRole(string serverId, string roleId) => $"guilds/{serverId}/roles/{roleId}";
public static string ServerPrune(string serverId, int days) => $"guilds/{serverId}/prune?days={days}";


public const string Invites = "invite"; public const string Invites = "invite";
public static string Invite(string inviteId) => $"invite/{inviteId}"; public static string Invite(string inviteId) => $"invite/{inviteId}";
public static string InviteUrl(string inviteId) => $"https://discord.gg/{inviteId}"; public static string InviteUrl(string inviteId) => $"https://discord.gg/{inviteId}";


public const string Users = "users"; public const string Users = "users";
public static string UserMe => $"users/@me";
public static string UserChannels(string userId) => $"users/{userId}/channels";
public static string UserAvatar(string userId, string avatarId) => $"users/{userId}/avatars/{avatarId}.jpg"; public static string UserAvatar(string userId, string avatarId) => $"users/{userId}/avatars/{avatarId}.jpg";
public static string UserChannels(string userId) => $"users/{userId}/channels";
public static string UserMe => $"users/@me";

public const string Voice = "voice"; public const string Voice = "voice";
public const string VoiceRegions = "voice/regions"; public const string VoiceRegions = "voice/regions";
//public const string VoiceIce = "voice/ice"; //public const string VoiceIce = "voice/ice";


+ 2
- 0
src/Discord.Net/API/Invites.cs View File

@@ -4,6 +4,7 @@


using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic;


namespace Discord.API namespace Discord.API
{ {
@@ -53,6 +54,7 @@ namespace Discord.API


//Get //Get
public class GetInviteResponse : InviteReference { } public class GetInviteResponse : InviteReference { }
public class GetInvitesResponse : List<InviteReference> { }


//Accept //Accept
public class AcceptInviteResponse : InviteReference { } public class AcceptInviteResponse : InviteReference { }


+ 6
- 0
src/Discord.Net/DiscordAPIClient.cs View File

@@ -126,6 +126,12 @@ namespace Discord


return _rest.Get<GetInviteResponse>(Endpoints.Invite(inviteIdOrXkcd)); return _rest.Get<GetInviteResponse>(Endpoints.Invite(inviteIdOrXkcd));
} }
public Task<GetInvitesResponse> GetInvites(string serverId)
{
if (serverId == null) throw new ArgumentNullException(nameof(serverId));

return _rest.Get<GetInvitesResponse>(Endpoints.ServerInvites(serverId));
}
public Task<AcceptInviteResponse> AcceptInvite(string inviteId) public Task<AcceptInviteResponse> AcceptInvite(string inviteId)
{ {
if (inviteId == null) throw new ArgumentNullException(nameof(inviteId)); if (inviteId == null) throw new ArgumentNullException(nameof(inviteId));


+ 17
- 2
src/Discord.Net/DiscordClient.Invites.cs View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;


@@ -10,8 +11,6 @@ namespace Discord
/// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks>
public async Task<Invite> GetInvite(string inviteIdOrXkcd) public async Task<Invite> GetInvite(string inviteIdOrXkcd)
{ {
//This doesn't work well if it's an invite to a different server!

if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd));
CheckReady(); CheckReady();


@@ -30,6 +29,22 @@ namespace Discord
return invite; return invite;
} }


/// <summary> Gets all active (non-expired) invites to a provided server. </summary>
public async Task<Invite[]> GetInvites(Server server)
{
if (server == null) throw new ArgumentNullException(nameof(server));
CheckReady();

var response = await _api.GetInvites(server.Id).ConfigureAwait(false);
return response.Select(x =>
{
var invite = new Invite(this, x.Code, x.XkcdPass, x.Guild.Id, x.Inviter?.Id, x.Channel?.Id);
invite.Cache(); //Builds references
invite.Update(x);
return invite;
}).ToArray();
}

/// <summary> Creates a new invite to the default channel of the provided server. </summary> /// <summary> Creates a new invite to the default channel of the provided server. </summary>
/// <param name="maxAge"> Time (in seconds) until the invite expires. Set to 0 to never expire. </param> /// <param name="maxAge"> Time (in seconds) until the invite expires. Set to 0 to never expire. </param>
/// <param name="tempMembership"> If true, a user accepting this invite will be kicked from the server after closing their client. </param> /// <param name="tempMembership"> If true, a user accepting this invite will be kicked from the server after closing their client. </param>


+ 0
- 14
src/Discord.Net/Models/Server.cs View File

@@ -55,11 +55,6 @@ namespace Discord
public IEnumerable<Channel> VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice); public IEnumerable<Channel> VoiceChannels => _channels.Select(x => x.Value).Where(x => x.Type == ChannelType.Voice);
private ConcurrentDictionary<string, Channel> _channels; private ConcurrentDictionary<string, Channel> _channels;


/// <summary> Returns a collection of all invites to this server. </summary>
[JsonIgnore]
public IEnumerable<Invite> Invites => _invites.Values;
private ConcurrentDictionary<string, Invite> _invites;

/// <summary> Returns a collection of all users within this server with their server-specific data. </summary> /// <summary> Returns a collection of all users within this server with their server-specific data. </summary>
[JsonIgnore] [JsonIgnore]
public IEnumerable<User> Members => _members.Select(x => x.Value); public IEnumerable<User> Members => _members.Select(x => x.Value);
@@ -85,7 +80,6 @@ namespace Discord


//Local Cache //Local Cache
_bans = new ConcurrentDictionary<string, bool>(); _bans = new ConcurrentDictionary<string, bool>();
_invites = new ConcurrentDictionary<string, Invite>();
} }
internal override void LoadReferences() internal override void LoadReferences()
{ {
@@ -113,11 +107,6 @@ namespace Discord
roles.Clear(); roles.Clear();


//Local Cache //Local Cache
var invites = _invites;
foreach (var invite in invites)
invite.Value.Uncache();
invites.Clear();

_bans.Clear(); _bans.Clear();


_afkChannel.Unload(); _afkChannel.Unload();
@@ -218,9 +207,6 @@ namespace Discord
_channels.TryRemove(channel.Id, out channel); _channels.TryRemove(channel.Id, out channel);
} }


internal void AddInvite(Invite invite) => _invites.TryAdd(invite.Id, invite);
internal void RemoveInvite(Invite invite) => _invites.TryRemove(invite.Id, out invite);

internal void AddMember(User user) internal void AddMember(User user)
{ {
if (_members.TryAdd(user.Id, user)) if (_members.TryAdd(user.Id, user))


Loading…
Cancel
Save