fix horrible oversight in IDisposable code
This commit is contained in:
parent
af80136e57
commit
b39def528d
7 changed files with 57 additions and 81 deletions
|
@ -21,10 +21,7 @@ namespace Maki
|
||||||
=> Dispose(false);
|
=> Dispose(false);
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
=> Dispose(true);
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Dispose(bool disposing)
|
protected void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +31,9 @@ namespace Maki
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
Collection.ToList().ForEach(x => Remove(x));
|
Collection.ToList().ForEach(x => Remove(x));
|
||||||
Collection.Clear();
|
Collection.Clear();
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Add(T item)
|
public virtual void Add(T item)
|
||||||
|
|
|
@ -896,7 +896,7 @@ namespace Maki
|
||||||
UserManager.Dispose();
|
UserManager.Dispose();
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
GC.SuppressFinalize(true);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Discord()
|
~Discord()
|
||||||
|
|
|
@ -6,171 +6,151 @@ namespace Maki
|
||||||
/// Discord Permission Flags
|
/// Discord Permission Flags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum DiscordPermission
|
public enum DiscordPermission : long
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows creation of instant invites
|
/// Allows creation of instant invites
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CreateInstantInvite = 1,
|
CreateInstantInvite = 0x1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows kicking members
|
/// Allows kicking members
|
||||||
/// </summary>
|
/// </summary>
|
||||||
KickMembers = 1 << 1,
|
KickMembers = 0x2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows banning members
|
/// Allows banning members
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BanMembers = 1 << 2,
|
BanMembers = 0x4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows all permissions and bypasses channel permission overwrites
|
/// Allows all permissions and bypasses channel permission overwrites
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Administrator = 1 << 3,
|
Administrator = 0x8,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows management and editing of channels
|
/// Allows management and editing of channels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageChannels = 1 << 4,
|
ManageChannels = 0x10,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows management and editing of the guild
|
/// Allows management and editing of the guild
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageGuild = 1 << 5,
|
ManageGuild = 0x20,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for the addition of reactions to messages
|
/// Allows for the addition of reactions to messages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
AddReactions = 1 << 6,
|
AddReactions = 0x40,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows viewing the audit log
|
/// Allows viewing the audit log
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ViewAuditLog = 1 << 7,
|
ViewAuditLog = 0x80,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows reading messages in a channel. The channel will not appear for users without this permission
|
/// Allows reading messages in a channel. The channel will not appear for users without this permission
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ReadMessages = 1 << 10,
|
ReadMessages = 0x400,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for sending messages in a channel.
|
/// Allows for sending messages in a channel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SendMessages = 1 << 11,
|
SendMessages = 0x800,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for sending of /tts messages
|
/// Allows for sending of /tts messages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SendTTSMessages = 1 << 12,
|
SendTTSMessages = 0x1000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for deletion of other users messages
|
/// Allows for deletion of other users messages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageMessages = 1 << 13,
|
ManageMessages = 0x2000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Links sent by this user will be auto-embedded
|
/// Links sent by this user will be auto-embedded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EmbedLinks = 1 << 14,
|
EmbedLinks = 0x4000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for uploading images and files
|
/// Allows for uploading images and files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
AttachFiles = 1 << 15,
|
AttachFiles = 0x8000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for reading of message history
|
/// Allows for reading of message history
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ReadMessageHistory = 1 << 16,
|
ReadMessageHistory = 0x10000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel
|
/// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
MentionEveryone = 1 << 17,
|
MentionEveryone = 0x20000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the usage of custom emojis from other servers
|
/// Allows the usage of custom emojis from other servers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ExternalEmojis = 1 << 18,
|
ExternalEmojis = 0x40000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for joining of a voice channel
|
/// Allows for joining of a voice channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceConnect = 1 << 20,
|
VoiceConnect = 0x100000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for speaking in a voice channel
|
/// Allows for speaking in a voice channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceSpeak = 1 << 21,
|
VoiceSpeak = 0x200000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for muting members in a voice channel
|
/// Allows for muting members in a voice channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceMuteMembers = 1 << 22,
|
VoiceMuteMembers = 0x400000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for deafening of members in a voice channel
|
/// Allows for deafening of members in a voice channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceDeafenMembers = 1 << 23,
|
VoiceDeafenMembers = 0x800000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for moving of members between voice channels
|
/// Allows for moving of members between voice channels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceMoveMembers = 1 << 24,
|
VoiceMoveMembers = 0x1000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for using voice-activity-detection in a voice channel
|
/// Allows for using voice-activity-detection in a voice channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
VoiceUseVAD = 1 << 25,
|
VoiceUseVAD = 0x2000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for modification of own nickname
|
/// Allows for modification of own nickname
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ChangeNickname = 1 << 26,
|
ChangeNickname = 0x4000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for modification of other users nicknames
|
/// Allows for modification of other users nicknames
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageNicknames = 1 << 27,
|
ManageNicknames = 0x8000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows management and editing of roles
|
/// Allows management and editing of roles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageRoles = 1 << 28,
|
ManageRoles = 0x10000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows management and editing of webhooks
|
/// Allows management and editing of webhooks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageWebhooks = 1 << 29,
|
ManageWebhooks = 0x20000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows management and editing of emojis
|
/// Allows management and editing of emojis
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ManageEmojis = 1 << 30,
|
ManageEmojis = 0x40000000,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Blank permissions
|
/// Blank permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// All Guild related permissions
|
|
||||||
/// </summary>
|
|
||||||
AllGuild = CreateInstantInvite | KickMembers | BanMembers | Administrator | ManageChannels | ManageGuild | AddReactions | ViewAuditLog | ChangeNickname | ManageNicknames | ManageRoles | ManageWebhooks | ManageEmojis,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// All text channel permissions
|
|
||||||
/// </summary>
|
|
||||||
AllText = CreateInstantInvite | ManageChannels | ViewAuditLog | ReadMessages | SendMessages | SendTTSMessages | ManageMessages | EmbedLinks | AttachFiles | ReadMessageHistory | MentionEveryone | ExternalEmojis | ManageRoles | ManageWebhooks | ManageEmojis,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// All voice channel permissions
|
|
||||||
/// </summary>
|
|
||||||
AllVoice = CreateInstantInvite | ManageChannels | ViewAuditLog | VoiceConnect | VoiceSpeak | VoiceMuteMembers | VoiceDeafenMembers | VoiceMoveMembers | VoiceUseVAD | ManageRoles,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// All permissions
|
|
||||||
/// </summary>
|
|
||||||
All = CreateInstantInvite | KickMembers | BanMembers | Administrator | ManageChannels | ManageGuild | AddReactions | ViewAuditLog | ReadMessages | SendMessages | SendTTSMessages | ManageMessages | EmbedLinks | AttachFiles | ReadMessageHistory | MentionEveryone | ExternalEmojis | VoiceConnect | VoiceSpeak | VoiceMuteMembers | VoiceDeafenMembers | VoiceMoveMembers | VoiceUseVAD | ChangeNickname | ManageNicknames | ManageRoles | ManageWebhooks | ManageEmojis,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,20 +11,20 @@ namespace Maki.Gateway
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subject shard
|
/// Subject shard
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly GatewayShard shard;
|
private readonly GatewayShard Shard;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interval timer for repeating the request
|
/// Interval timer for repeating the request
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Timer timer = null;
|
private Timer Timer = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="s">Parent GatewayShard instance</param>
|
/// <param name="shard">Parent GatewayShard instance</param>
|
||||||
public GatewayHeartbeatManager(GatewayShard s)
|
public GatewayHeartbeatManager(GatewayShard shard)
|
||||||
{
|
{
|
||||||
shard = s;
|
Shard = shard;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -32,10 +32,10 @@ namespace Maki.Gateway
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
if (timer != null)
|
if (Timer != null)
|
||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
timer = new Timer(Handler, null, TimeSpan.Zero, shard.HeartbeatInterval);
|
Timer = new Timer(Handler, null, TimeSpan.Zero, Shard.HeartbeatInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -44,7 +44,7 @@ namespace Maki.Gateway
|
||||||
/// <param name="state"></param>
|
/// <param name="state"></param>
|
||||||
private void Handler(object state)
|
private void Handler(object state)
|
||||||
{
|
{
|
||||||
shard.Send(GatewayOPCode.Heartbeat, shard.LastSequence);
|
Shard.Send(GatewayOPCode.Heartbeat, Shard.LastSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -52,11 +52,11 @@ namespace Maki.Gateway
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
if (timer == null)
|
if (Timer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
timer.Dispose();
|
Timer.Dispose();
|
||||||
timer = null;
|
Timer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,23 +418,21 @@ namespace Maki.Gateway
|
||||||
|
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!IsDisposed)
|
if (IsDisposed)
|
||||||
{
|
return;
|
||||||
IsDisposed = true;
|
|
||||||
Disconnect();
|
IsDisposed = true;
|
||||||
}
|
Disconnect();
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~GatewayShard()
|
~GatewayShard()
|
||||||
{
|
=> Dispose(false);
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
=> Dispose(true);
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ namespace Maki.Gateway
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
GC.SuppressFinalize(true);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~GatewayShardClient()
|
~GatewayShardClient()
|
||||||
|
|
|
@ -53,7 +53,6 @@ namespace Maki.Rest
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (RawResponseValue == null)
|
if (RawResponseValue == null)
|
||||||
{
|
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
byte[] bytes = new byte[4096];
|
byte[] bytes = new byte[4096];
|
||||||
|
@ -66,7 +65,6 @@ namespace Maki.Rest
|
||||||
RawResponseValue = new byte[ms.Length];
|
RawResponseValue = new byte[ms.Length];
|
||||||
ms.Read(RawResponseValue, 0, RawResponseValue.Length);
|
ms.Read(RawResponseValue, 0, RawResponseValue.Length);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return RawResponseValue;
|
return RawResponseValue;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +259,7 @@ namespace Maki.Rest
|
||||||
HttpWebResponse?.Close();
|
HttpWebResponse?.Close();
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
GC.SuppressFinalize(true);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~WebRequest()
|
~WebRequest()
|
||||||
|
|
Reference in a new issue