Fixed several websocket and datastore issues
This commit is contained in:
@@ -46,8 +46,10 @@ namespace Discord.Net.Queue
|
|||||||
{
|
{
|
||||||
if (IsMultipart)
|
if (IsMultipart)
|
||||||
return await Client.Send(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false);
|
return await Client.Send(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false);
|
||||||
else
|
else if (Json != null)
|
||||||
return await Client.Send(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false);
|
return await Client.Send(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
return await Client.Send(Method, Endpoint, HeaderOnly).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ namespace Discord.Net.Rest
|
|||||||
UseProxy = false,
|
UseProxy = false,
|
||||||
PreAuthenticate = false
|
PreAuthenticate = false
|
||||||
});
|
});
|
||||||
|
|
||||||
SetHeader("accept-encoding", "gzip, deflate");
|
SetHeader("accept-encoding", "gzip, deflate");
|
||||||
|
|
||||||
|
_cancelTokenSource = new CancellationTokenSource();
|
||||||
|
_cancelToken = CancellationToken.None;
|
||||||
_parentToken = CancellationToken.None;
|
_parentToken = CancellationToken.None;
|
||||||
}
|
}
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ namespace Discord.Net.WebSockets
|
|||||||
_client = new ClientWebSocket();
|
_client = new ClientWebSocket();
|
||||||
_client.Options.Proxy = null;
|
_client.Options.Proxy = null;
|
||||||
_client.Options.KeepAliveInterval = TimeSpan.Zero;
|
_client.Options.KeepAliveInterval = TimeSpan.Zero;
|
||||||
|
|
||||||
|
_cancelTokenSource = new CancellationTokenSource();
|
||||||
|
_cancelToken = CancellationToken.None;
|
||||||
_parentToken = CancellationToken.None;
|
_parentToken = CancellationToken.None;
|
||||||
}
|
}
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
@@ -46,6 +49,7 @@ namespace Discord.Net.WebSockets
|
|||||||
|
|
||||||
public async Task Connect(string host)
|
public async Task Connect(string host)
|
||||||
{
|
{
|
||||||
|
//Assume locked
|
||||||
await Disconnect().ConfigureAwait(false);
|
await Disconnect().ConfigureAwait(false);
|
||||||
|
|
||||||
_cancelTokenSource = new CancellationTokenSource();
|
_cancelTokenSource = new CancellationTokenSource();
|
||||||
@@ -56,9 +60,11 @@ namespace Discord.Net.WebSockets
|
|||||||
}
|
}
|
||||||
public async Task Disconnect()
|
public async Task Disconnect()
|
||||||
{
|
{
|
||||||
|
//Assume locked
|
||||||
_cancelTokenSource.Cancel();
|
_cancelTokenSource.Cancel();
|
||||||
|
|
||||||
_client.Abort();
|
if (_client.State == WebSocketState.Open)
|
||||||
|
try { await _client?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } catch { }
|
||||||
|
|
||||||
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
|
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -75,6 +81,7 @@ namespace Discord.Net.WebSockets
|
|||||||
|
|
||||||
public async Task Send(byte[] data, int offset, int count, bool isText)
|
public async Task Send(byte[] data, int offset, int count, bool isText)
|
||||||
{
|
{
|
||||||
|
//TODO: If connection is temporarily down, retry?
|
||||||
int frameCount = (int)Math.Ceiling((double)count / SendChunkSize);
|
int frameCount = (int)Math.Ceiling((double)count / SendChunkSize);
|
||||||
|
|
||||||
for (int i = 0; i < frameCount; i++, offset += SendChunkSize)
|
for (int i = 0; i < frameCount; i++, offset += SendChunkSize)
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ namespace Discord.WebSocket
|
|||||||
return models.Select(x => new Connection(x));
|
return models.Select(x => new Connection(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Channel> GetChannel(ulong id)
|
public Channel GetChannel(ulong id)
|
||||||
{
|
{
|
||||||
return DataStore.GetChannel(id);
|
return DataStore.GetChannel(id);
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ namespace Discord.WebSocket
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Guild> GetGuild(ulong id)
|
public Guild GetGuild(ulong id)
|
||||||
{
|
{
|
||||||
return DataStore.GetGuild(id);
|
return DataStore.GetGuild(id);
|
||||||
}
|
}
|
||||||
@@ -303,11 +303,11 @@ namespace Discord.WebSocket
|
|||||||
return new Guild(this, model);
|
return new Guild(this, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<User> GetUser(ulong id)
|
public User GetUser(ulong id)
|
||||||
{
|
{
|
||||||
return DataStore.GetUser(id);
|
return DataStore.GetUser(id);
|
||||||
}
|
}
|
||||||
public async Task<User> GetUser(string username, ushort discriminator)
|
public User GetUser(string username, ushort discriminator)
|
||||||
{
|
{
|
||||||
return DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault();
|
return DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault();
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ namespace Discord.WebSocket
|
|||||||
return models.Select(x => new User(this, x));
|
return models.Select(x => new User(this, x));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<VoiceRegion> GetVoiceRegion(string id)
|
public VoiceRegion GetVoiceRegion(string id)
|
||||||
{
|
{
|
||||||
VoiceRegion region;
|
VoiceRegion region;
|
||||||
if (_voiceRegions.TryGetValue(id, out region))
|
if (_voiceRegions.TryGetValue(id, out region))
|
||||||
@@ -335,7 +335,6 @@ namespace Discord.WebSocket
|
|||||||
//Global
|
//Global
|
||||||
case "READY":
|
case "READY":
|
||||||
{
|
{
|
||||||
//TODO: None of this is really threadsafe - should only replace the cache collections when they have been fully populated
|
|
||||||
//TODO: Store guilds even if they're unavailable
|
//TODO: Store guilds even if they're unavailable
|
||||||
//TODO: Make downloading large guilds optional
|
//TODO: Make downloading large guilds optional
|
||||||
|
|
||||||
@@ -866,31 +865,31 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<IChannel> IDiscordClient.GetChannel(ulong id)
|
Task<IChannel> IDiscordClient.GetChannel(ulong id)
|
||||||
=> await GetChannel(id).ConfigureAwait(false);
|
=> Task.FromResult<IChannel>(GetChannel(id));
|
||||||
Task<IEnumerable<IDMChannel>> IDiscordClient.GetDMChannels()
|
Task<IEnumerable<IDMChannel>> IDiscordClient.GetDMChannels()
|
||||||
=> Task.FromResult<IEnumerable<IDMChannel>>(DMChannels.ToImmutableArray());
|
=> Task.FromResult<IEnumerable<IDMChannel>>(DMChannels.ToImmutableArray());
|
||||||
async Task<IEnumerable<IConnection>> IDiscordClient.GetConnections()
|
async Task<IEnumerable<IConnection>> IDiscordClient.GetConnections()
|
||||||
=> await GetConnections().ConfigureAwait(false);
|
=> await GetConnections().ConfigureAwait(false);
|
||||||
async Task<IInvite> IDiscordClient.GetInvite(string inviteIdOrXkcd)
|
async Task<IInvite> IDiscordClient.GetInvite(string inviteIdOrXkcd)
|
||||||
=> await GetInvite(inviteIdOrXkcd).ConfigureAwait(false);
|
=> await GetInvite(inviteIdOrXkcd).ConfigureAwait(false);
|
||||||
async Task<IGuild> IDiscordClient.GetGuild(ulong id)
|
Task<IGuild> IDiscordClient.GetGuild(ulong id)
|
||||||
=> await GetGuild(id).ConfigureAwait(false);
|
=> Task.FromResult<IGuild>(GetGuild(id));
|
||||||
Task<IEnumerable<IUserGuild>> IDiscordClient.GetGuilds()
|
Task<IEnumerable<IUserGuild>> IDiscordClient.GetGuilds()
|
||||||
=> Task.FromResult<IEnumerable<IUserGuild>>(Guilds.ToImmutableArray());
|
=> Task.FromResult<IEnumerable<IUserGuild>>(Guilds.ToImmutableArray());
|
||||||
async Task<IGuild> IDiscordClient.CreateGuild(string name, IVoiceRegion region, Stream jpegIcon)
|
async Task<IGuild> IDiscordClient.CreateGuild(string name, IVoiceRegion region, Stream jpegIcon)
|
||||||
=> await CreateGuild(name, region, jpegIcon).ConfigureAwait(false);
|
=> await CreateGuild(name, region, jpegIcon).ConfigureAwait(false);
|
||||||
async Task<IUser> IDiscordClient.GetUser(ulong id)
|
Task<IUser> IDiscordClient.GetUser(ulong id)
|
||||||
=> await GetUser(id).ConfigureAwait(false);
|
=> Task.FromResult<IUser>(GetUser(id));
|
||||||
async Task<IUser> IDiscordClient.GetUser(string username, ushort discriminator)
|
Task<IUser> IDiscordClient.GetUser(string username, ushort discriminator)
|
||||||
=> await GetUser(username, discriminator).ConfigureAwait(false);
|
=> Task.FromResult<IUser>(GetUser(username, discriminator));
|
||||||
Task<ISelfUser> IDiscordClient.GetCurrentUser()
|
Task<ISelfUser> IDiscordClient.GetCurrentUser()
|
||||||
=> Task.FromResult<ISelfUser>(CurrentUser);
|
=> Task.FromResult<ISelfUser>(CurrentUser);
|
||||||
async Task<IEnumerable<IUser>> IDiscordClient.QueryUsers(string query, int limit)
|
async Task<IEnumerable<IUser>> IDiscordClient.QueryUsers(string query, int limit)
|
||||||
=> await QueryUsers(query, limit).ConfigureAwait(false);
|
=> await QueryUsers(query, limit).ConfigureAwait(false);
|
||||||
Task<IEnumerable<IVoiceRegion>> IDiscordClient.GetVoiceRegions()
|
Task<IEnumerable<IVoiceRegion>> IDiscordClient.GetVoiceRegions()
|
||||||
=> Task.FromResult<IEnumerable<IVoiceRegion>>(VoiceRegions.ToImmutableArray());
|
=> Task.FromResult<IEnumerable<IVoiceRegion>>(VoiceRegions.ToImmutableArray());
|
||||||
async Task<IVoiceRegion> IDiscordClient.GetVoiceRegion(string id)
|
Task<IVoiceRegion> IDiscordClient.GetVoiceRegion(string id)
|
||||||
=> await GetVoiceRegion(id).ConfigureAwait(false);
|
=> Task.FromResult<IVoiceRegion>(GetVoiceRegion(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
Update(model);
|
Update(model);
|
||||||
}
|
}
|
||||||
private void Update(Model model)
|
private async void Update(Model model)
|
||||||
{
|
{
|
||||||
_afkChannelId = model.AFKChannelId;
|
_afkChannelId = model.AFKChannelId;
|
||||||
AFKTimeout = model.AFKTimeout;
|
AFKTimeout = model.AFKTimeout;
|
||||||
|
|||||||
Reference in New Issue
Block a user