From babda495addcc772611a845c524c167e147cdcfd Mon Sep 17 00:00:00 2001 From: quin lynch Date: Thu, 1 Jul 2021 07:18:09 -0300 Subject: [PATCH] Complete merge of upstream/dev --- .../Discord.Net.WebSocket.csproj | 5 +- .../Entities/Invites/ISocketInvite.cs | 42 ------- .../Entities/Invites/InviteCache.cs | 47 -------- .../Entities/Invites/SocketGuildInvite.cs | 112 ------------------ .../Entities/Invites/SocketInviteHelper.cs | 17 --- 5 files changed, 4 insertions(+), 219 deletions(-) delete mode 100644 src/Discord.Net.WebSocket/Entities/Invites/ISocketInvite.cs delete mode 100644 src/Discord.Net.WebSocket/Entities/Invites/InviteCache.cs delete mode 100644 src/Discord.Net.WebSocket/Entities/Invites/SocketGuildInvite.cs delete mode 100644 src/Discord.Net.WebSocket/Entities/Invites/SocketInviteHelper.cs diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index 01aece130..80279ed59 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -1,6 +1,6 @@ - + Discord.Net.WebSocket Discord.WebSocket @@ -13,4 +13,7 @@ + + + diff --git a/src/Discord.Net.WebSocket/Entities/Invites/ISocketInvite.cs b/src/Discord.Net.WebSocket/Entities/Invites/ISocketInvite.cs deleted file mode 100644 index 8fe82b089..000000000 --- a/src/Discord.Net.WebSocket/Entities/Invites/ISocketInvite.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Discord.WebSocket -{ - public interface ISocketInvite - { - /// - /// Gets the unique identifier for this invite. - /// - /// - /// A string containing the invite code (e.g. FTqNnyS). - /// - string Code { get; } - /// - /// Gets the URL used to accept this invite - /// - /// - /// A string containing the full invite URL (e.g. https://discord.gg/FTqNnyS). - /// - string Url { get; } - - /// - /// Gets the channel this invite is linked to. - /// - /// - /// A generic channel that the invite points to. - /// - SocketGuildChannel Channel { get; } - - /// - /// Gets the guild this invite is linked to. - /// - /// - /// A guild object representing the guild that the invite points to. - /// - SocketGuild Guild { get; } - } -} diff --git a/src/Discord.Net.WebSocket/Entities/Invites/InviteCache.cs b/src/Discord.Net.WebSocket/Entities/Invites/InviteCache.cs deleted file mode 100644 index a203b780f..000000000 --- a/src/Discord.Net.WebSocket/Entities/Invites/InviteCache.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Discord.WebSocket -{ - internal class InviteCache - { - private readonly ConcurrentDictionary _invites; - private readonly ConcurrentQueue _queue; - private static int _size; - - public InviteCache(DiscordSocketClient client) - { - //NOTE: - //This should be an option in the client config. default for now is 20 invites per guild - _size = client.Guilds.Count * 20; - - _invites = new ConcurrentDictionary(); - _queue = new ConcurrentQueue(); - } - public void Add(SocketGuildInvite invite) - { - if(_invites.TryAdd(invite.Code, invite)) - { - _queue.Enqueue(invite.Code); - - while (_queue.Count > _size && _queue.TryDequeue(out string invCode)) - _invites.TryRemove(invCode, out _); - } - } - public SocketGuildInvite Remove(string inviteCode) - { - _invites.TryRemove(inviteCode, out SocketGuildInvite inv); - return inv; - } - public SocketGuildInvite Get(string inviteCode) - { - if(_invites.TryGetValue(inviteCode, out SocketGuildInvite inv)) - return inv; - return null; - } - } -} diff --git a/src/Discord.Net.WebSocket/Entities/Invites/SocketGuildInvite.cs b/src/Discord.Net.WebSocket/Entities/Invites/SocketGuildInvite.cs deleted file mode 100644 index 35fdf237c..000000000 --- a/src/Discord.Net.WebSocket/Entities/Invites/SocketGuildInvite.cs +++ /dev/null @@ -1,112 +0,0 @@ -using Discord.Rest; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization.Formatters; -using System.Text; -using System.Threading.Tasks; -using InviteUpdate = Discord.API.Gateway.InviteCreatedEvent; - -namespace Discord.WebSocket -{ - /// - /// Represents a guild invite - /// - public class SocketGuildInvite : SocketEntity, ISocketInvite - { - public string Code { get; private set; } - public string Url => $"{DiscordConfig.InviteUrl}{Code}"; - public SocketGuildChannel Channel { get; private set; } - public SocketGuild Guild { get; private set; } - /// - /// Gets the unique invite code - /// - /// Returns the unique invite code - /// - /// - public string Id => Code; - /// - /// Gets the user who created the invite - /// - /// Returns the user who created the invite - /// - /// - public SocketGuildUser Inviter { get; private set; } - /// - /// Gets the maximum number of times the invite can be used, if there is no limit then the value will be 0 - /// - /// Returns the maximum number of times the invite can be used, if there is no limit then the value will be 0 - /// - /// - public int? MaxUses { get; private set; } - /// - /// Gets whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) - /// - /// Returns whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) - /// - /// - public bool Temporary { get; private set; } - /// - /// Gets the time at which the invite was created - /// - /// Returns the time at which the invite was created - /// - /// - public DateTimeOffset? CreatedAt { get; private set; } - /// - /// Gets how long the invite is valid for - /// - /// Returns how long the invite is valid for (in seconds) - /// - /// - public TimeSpan? MaxAge { get; private set; } - - internal SocketGuildInvite(DiscordSocketClient _client, SocketGuild guild, SocketGuildChannel channel, string inviteCode, RestInviteMetadata rest) : base(_client, inviteCode) - { - Code = inviteCode; - Guild = guild; - Channel = channel; - CreatedAt = rest.CreatedAt; - Temporary = rest.IsTemporary; - MaxUses = rest.MaxUses; - Inviter = guild.GetUser(rest.Inviter.Id); - if (rest.MaxAge.HasValue) - MaxAge = TimeSpan.FromSeconds(rest.MaxAge.Value); - } - internal SocketGuildInvite(DiscordSocketClient _client, SocketGuild guild, SocketGuildChannel channel, string inviteCode, InviteUpdate Update) : base(_client, inviteCode) - { - Code = inviteCode; - Guild = guild; - Channel = channel; - - if (Update.RawTimestamp.IsSpecified) - CreatedAt = Update.RawTimestamp.Value; - else - CreatedAt = DateTimeOffset.Now; - - if (Update.inviter.IsSpecified) - Inviter = guild.GetUser(Update.inviter.Value.Id); - - Temporary = Update.TempInvite; - MaxUses = Update.MaxUsers; - MaxAge = TimeSpan.FromSeconds(Update.RawAge); - } - internal static SocketGuildInvite Create(DiscordSocketClient _client, SocketGuild guild, SocketGuildChannel channel, string inviteCode, InviteUpdate Update) - { - var invite = new SocketGuildInvite(_client, guild, channel, inviteCode, Update); - return invite; - } - internal static SocketGuildInvite CreateFromRest(DiscordSocketClient _client, SocketGuild guild, SocketGuildChannel channel, string inviteCode, RestInviteMetadata rest) - { - var invite = new SocketGuildInvite(_client, guild, channel, inviteCode, rest); - return invite; - } - /// - /// Deletes the invite - /// - /// - /// - public Task DeleteAsync(RequestOptions options = null) - => SocketInviteHelper.DeleteAsync(this, Discord, options); - } -} diff --git a/src/Discord.Net.WebSocket/Entities/Invites/SocketInviteHelper.cs b/src/Discord.Net.WebSocket/Entities/Invites/SocketInviteHelper.cs deleted file mode 100644 index 3781739a9..000000000 --- a/src/Discord.Net.WebSocket/Entities/Invites/SocketInviteHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Discord.WebSocket -{ - internal class SocketInviteHelper - { - public static async Task DeleteAsync(ISocketInvite invite, BaseSocketClient client, - RequestOptions options) - { - await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false); - } - } -}