updates
This commit is contained in:
parent
c81ea9441c
commit
625ca8e30c
4 changed files with 18 additions and 32 deletions
|
@ -8,10 +8,8 @@ using Maki.Structures.Messages;
|
||||||
using Maki.Structures.Presences;
|
using Maki.Structures.Presences;
|
||||||
using Maki.Structures.Roles;
|
using Maki.Structures.Roles;
|
||||||
using Maki.Structures.Users;
|
using Maki.Structures.Users;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Maki
|
namespace Maki
|
||||||
|
@ -21,12 +19,6 @@ namespace Maki
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Discord : IDisposable
|
public class Discord : IDisposable
|
||||||
{
|
{
|
||||||
// temporary, whether gateway data should be written to a file
|
|
||||||
public bool LogGateway = false;
|
|
||||||
|
|
||||||
// temporary, whether rest data should be written to the console
|
|
||||||
public bool LogRest = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Discord Gateway/API version we're targeting
|
/// Discord Gateway/API version we're targeting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -209,14 +201,18 @@ namespace Maki
|
||||||
public DiscordServer[] Servers => servers.ToArray();
|
public DiscordServer[] Servers => servers.ToArray();
|
||||||
public DiscordUser Me => users.FirstOrDefault();
|
public DiscordUser Me => users.FirstOrDefault();
|
||||||
|
|
||||||
|
private DiscordParams Params;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Discord()
|
public Discord(DiscordParams parameters = null)
|
||||||
{
|
{
|
||||||
|
Params = parameters ?? new DiscordParams();
|
||||||
RestClient = new RestClient(this);
|
RestClient = new RestClient(this);
|
||||||
ShardClient = new GatewayShardClient(this);
|
ShardClient = new GatewayShardClient(this);
|
||||||
|
|
||||||
|
#region Assigning event handlers
|
||||||
ShardClient.OnChannelCreate += ShardManager_OnChannelCreate;
|
ShardClient.OnChannelCreate += ShardManager_OnChannelCreate;
|
||||||
ShardClient.OnChannelUpdate += ShardManager_OnChannelUpdate;
|
ShardClient.OnChannelUpdate += ShardManager_OnChannelUpdate;
|
||||||
ShardClient.OnChannelDelete += ShardManager_OnChannelDelete;
|
ShardClient.OnChannelDelete += ShardManager_OnChannelDelete;
|
||||||
|
@ -252,6 +248,7 @@ namespace Maki
|
||||||
ShardClient.OnSocketClose += ShardManager_OnSocketClose;
|
ShardClient.OnSocketClose += ShardManager_OnSocketClose;
|
||||||
ShardClient.OnSocketError += ShardManager_OnSocketError;
|
ShardClient.OnSocketError += ShardManager_OnSocketError;
|
||||||
ShardClient.OnSocketMessage += ShardManager_OnSocketMessage;
|
ShardClient.OnSocketMessage += ShardManager_OnSocketMessage;
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearContainers()
|
private void ClearContainers()
|
||||||
|
@ -376,6 +373,7 @@ namespace Maki
|
||||||
Gateway = string.Empty;
|
Gateway = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Event Handlers
|
||||||
private void ShardManager_OnChannelCreate(GatewayShard shard, Channel channel)
|
private void ShardManager_OnChannelCreate(GatewayShard shard, Channel channel)
|
||||||
{
|
{
|
||||||
DiscordServer server = servers.Find(x => x.Id == channel.GuildId);
|
DiscordServer server = servers.Find(x => x.Id == channel.GuildId);
|
||||||
|
@ -819,38 +817,22 @@ namespace Maki
|
||||||
|
|
||||||
private void ShardManager_OnSocketOpen(GatewayShard shard)
|
private void ShardManager_OnSocketOpen(GatewayShard shard)
|
||||||
{
|
{
|
||||||
//MultiLineWrite($"Connection opened on shard {shard.Id}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShardManager_OnSocketClose(GatewayShard shard, bool wasClean, ushort code, string reason)
|
private void ShardManager_OnSocketClose(GatewayShard shard, bool wasClean, ushort code, string reason)
|
||||||
{
|
{
|
||||||
//MultiLineWrite($"Connection closed on shard {shard.Id} ({wasClean}/{code}/{reason})");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShardManager_OnSocketError(GatewayShard shard, Exception ex)
|
private void ShardManager_OnSocketError(GatewayShard shard, Exception ex)
|
||||||
{
|
{
|
||||||
//MultiLineWrite($"Socket error on shard {shard.Id}", ex.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShardManager_OnSocketMessage(GatewayShard shard, string text)
|
private void ShardManager_OnSocketMessage(GatewayShard shard, string text)
|
||||||
{
|
{
|
||||||
if (LogGateway)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists("Json"))
|
|
||||||
Directory.CreateDirectory("Json");
|
|
||||||
|
|
||||||
File.WriteAllText(
|
|
||||||
$"Json/{DateTime.Now:yyyy-MM-dd HH-mm-ss.fffffff}.json",
|
|
||||||
JsonConvert.SerializeObject(
|
|
||||||
JsonConvert.DeserializeObject(text),
|
|
||||||
Formatting.Indented
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IDisposable
|
#region IDisposable
|
||||||
|
|
||||||
private bool isDisposed = false;
|
private bool isDisposed = false;
|
||||||
|
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
|
@ -874,7 +856,6 @@ namespace Maki
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(true);
|
GC.SuppressFinalize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
Maki/DiscordParams.cs
Normal file
7
Maki/DiscordParams.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Maki
|
||||||
|
{
|
||||||
|
public class DiscordParams
|
||||||
|
{
|
||||||
|
public int BackLogSize = 5;
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="DiscordGame.cs" />
|
<Compile Include="DiscordGame.cs" />
|
||||||
<Compile Include="DiscordMember.cs" />
|
<Compile Include="DiscordMember.cs" />
|
||||||
<Compile Include="DiscordMessage.cs" />
|
<Compile Include="DiscordMessage.cs" />
|
||||||
|
<Compile Include="DiscordParams.cs" />
|
||||||
<Compile Include="DiscordRole.cs" />
|
<Compile Include="DiscordRole.cs" />
|
||||||
<Compile Include="DiscordServer.cs" />
|
<Compile Include="DiscordServer.cs" />
|
||||||
<Compile Include="DiscordUserStatus.cs" />
|
<Compile Include="DiscordUserStatus.cs" />
|
||||||
|
|
|
@ -110,10 +110,7 @@ namespace Maki.Rest
|
||||||
response.ErrorCode = (RestErrorCode)error.Code;
|
response.ErrorCode = (RestErrorCode)error.Code;
|
||||||
response.ErrorMessage = error.Message;
|
response.ErrorMessage = error.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.LogRest)
|
|
||||||
Console.WriteLine(response.RawResponse);
|
|
||||||
|
|
||||||
if (response.Status == 200)
|
if (response.Status == 200)
|
||||||
response.Response = JsonConvert.DeserializeObject<T>(response.RawResponse);
|
response.Response = JsonConvert.DeserializeObject<T>(response.RawResponse);
|
||||||
|
|
||||||
|
|
Reference in a new issue