Removed old bucket system, cleaned up api calls. Fixed compile errors.
This commit is contained in:
@@ -156,8 +156,9 @@ namespace Discord.API
|
||||
}
|
||||
|
||||
//Core
|
||||
private async Task SendGatewayInternalAsync(GatewayOpCode opCode, object payload,
|
||||
BucketGroup group, int bucketId, ulong guildId, RequestOptions options)
|
||||
public Task SendGatewayAsync(GatewayOpCode opCode, object payload, RequestOptions options = null)
|
||||
=> SendGatewayInternalAsync(opCode, payload, options);
|
||||
private async Task SendGatewayInternalAsync(GatewayOpCode opCode, object payload, RequestOptions options)
|
||||
{
|
||||
CheckState();
|
||||
|
||||
@@ -166,25 +167,19 @@ namespace Discord.API
|
||||
payload = new WebSocketMessage { Operation = (int)opCode, Payload = payload };
|
||||
if (payload != null)
|
||||
bytes = Encoding.UTF8.GetBytes(SerializeJson(payload));
|
||||
await RequestQueue.SendAsync(new WebSocketRequest(_gatewayClient, bytes, true, options), group, bucketId, guildId).ConfigureAwait(false);
|
||||
await RequestQueue.SendAsync(new WebSocketRequest(_gatewayClient, bytes, true, options)).ConfigureAwait(false);
|
||||
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Gateway
|
||||
public Task SendGatewayAsync(GatewayOpCode opCode, object payload,
|
||||
GlobalBucket bucket = GlobalBucket.GeneralGateway, RequestOptions options = null)
|
||||
=> SendGatewayInternalAsync(opCode, payload, BucketGroup.Global, (int)bucket, 0, options);
|
||||
|
||||
public Task SendGatewayAsync(GatewayOpCode opCode, object payload,
|
||||
GuildBucket bucket, ulong guildId, RequestOptions options = null)
|
||||
=> SendGatewayInternalAsync(opCode, payload, BucketGroup.Guild, (int)bucket, guildId, options);
|
||||
|
||||
public async Task<GetGatewayResponse> GetGatewayAsync(RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
return await SendAsync<GetGatewayResponse>("GET", "gateway", options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendIdentifyAsync(int largeThreshold = 100, bool useCompression = true, int shardID = 0, int totalShards = 1, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var props = new Dictionary<string, string>
|
||||
{
|
||||
["$device"] = "Discord.Net"
|
||||
@@ -203,6 +198,7 @@ namespace Discord.API
|
||||
}
|
||||
public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var msg = new ResumeParams()
|
||||
{
|
||||
Token = _authToken,
|
||||
@@ -213,10 +209,12 @@ namespace Discord.API
|
||||
}
|
||||
public async Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendStatusUpdateAsync(long? idleSince, Game game, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var args = new StatusUpdateParams
|
||||
{
|
||||
IdleSince = idleSince,
|
||||
@@ -226,10 +224,12 @@ namespace Discord.API
|
||||
}
|
||||
public async Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var payload = new VoiceStateUpdateParams
|
||||
{
|
||||
GuildId = guildId,
|
||||
@@ -241,6 +241,7 @@ namespace Discord.API
|
||||
}
|
||||
public async Task SendGuildSyncAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
{
|
||||
internal class DataStore
|
||||
internal class ClientState
|
||||
{
|
||||
private const int CollectionConcurrencyLevel = 1; //WebSocket updater/event handler. //TODO: Needs profiling, increase to 2?
|
||||
private const double AverageChannelsPerGuild = 10.22; //Source: Googie2149
|
||||
@@ -29,7 +29,7 @@ namespace Discord.WebSocket
|
||||
_groupChannels.Select(x => GetChannel(x) as IPrivateChannel))
|
||||
.ToReadOnlyCollection(() => _dmChannels.Count + _groupChannels.Count);
|
||||
|
||||
public DataStore(int guildCount, int dmChannelCount)
|
||||
public ClientState(int guildCount, int dmChannelCount)
|
||||
{
|
||||
double estimatedChannelCount = guildCount * AverageChannelsPerGuild + dmChannelCount;
|
||||
double estimatedUsersCount = guildCount * AverageUsersPerGuild;
|
||||
@@ -19,7 +19,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
{
|
||||
public partial class DiscordSocketClient : DiscordClient, IDiscordClient
|
||||
public partial class DiscordSocketClient : BaseDiscordClient, IDiscordClient
|
||||
{
|
||||
private readonly ConcurrentQueue<ulong> _largeGuilds;
|
||||
private readonly Logger _gatewayLogger;
|
||||
@@ -49,14 +49,14 @@ namespace Discord.WebSocket
|
||||
internal int MessageCacheSize { get; private set; }
|
||||
internal int LargeThreshold { get; private set; }
|
||||
internal AudioMode AudioMode { get; private set; }
|
||||
internal DataStore DataStore { get; private set; }
|
||||
internal ClientState State { get; private set; }
|
||||
internal int ConnectionTimeout { get; private set; }
|
||||
internal WebSocketProvider WebSocketProvider { get; private set; }
|
||||
|
||||
public new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient;
|
||||
public new SocketSelfUser CurrentUser => base.CurrentUser as SocketSelfUser;
|
||||
public IReadOnlyCollection<IPrivateChannel> PrivateChannels => DataStore.PrivateChannels;
|
||||
internal IReadOnlyCollection<SocketGuild> Guilds => DataStore.Guilds;
|
||||
public IReadOnlyCollection<IPrivateChannel> PrivateChannels => State.PrivateChannels;
|
||||
internal IReadOnlyCollection<SocketGuild> Guilds => State.Guilds;
|
||||
|
||||
/// <summary> Creates a new REST/WebSocket discord client. </summary>
|
||||
public DiscordSocketClient() : this(new DiscordSocketConfig()) { }
|
||||
@@ -72,7 +72,7 @@ namespace Discord.WebSocket
|
||||
AudioMode = config.AudioMode;
|
||||
WebSocketProvider = config.WebSocketProvider;
|
||||
ConnectionTimeout = config.ConnectionTimeout;
|
||||
DataStore = new DataStore(0, 0);
|
||||
State = new ClientState(0, 0);
|
||||
|
||||
_nextAudioId = 1;
|
||||
_gatewayLogger = LogManager.CreateLogger("Gateway");
|
||||
@@ -111,7 +111,7 @@ namespace Discord.WebSocket
|
||||
|
||||
protected override async Task OnLoginAsync(TokenType tokenType, string token)
|
||||
{
|
||||
var voiceRegions = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||
var voiceRegions = await ApiClient.GetVoiceRegionsAsync(new RequestOptions { IgnoreState = true}).ConfigureAwait(false);
|
||||
_voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id);
|
||||
}
|
||||
protected override async Task OnLogoutAsync()
|
||||
@@ -242,7 +242,7 @@ namespace Discord.WebSocket
|
||||
while (_largeGuilds.TryDequeue(out guildId)) { }
|
||||
|
||||
//Raise virtual GUILD_UNAVAILABLEs
|
||||
foreach (var guild in DataStore.Guilds)
|
||||
foreach (var guild in State.Guilds)
|
||||
{
|
||||
if (guild._available)
|
||||
await _guildUnavailableEvent.InvokeAsync(guild).ConfigureAwait(false);
|
||||
@@ -322,7 +322,7 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public SocketGuild GetGuild(ulong id)
|
||||
{
|
||||
return DataStore.GetGuild(id);
|
||||
return State.GetGuild(id);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public Task<RestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null)
|
||||
@@ -331,7 +331,7 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public IChannel GetChannel(ulong id)
|
||||
{
|
||||
return DataStore.GetChannel(id);
|
||||
return State.GetChannel(id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -345,12 +345,12 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public IUser GetUser(ulong id)
|
||||
{
|
||||
return DataStore.GetUser(id);
|
||||
return State.GetUser(id);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public IUser GetUser(string username, string discriminator)
|
||||
{
|
||||
return DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault();
|
||||
return State.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -486,7 +486,7 @@ namespace Discord.WebSocket
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<ReadyEvent>(_serializer);
|
||||
var dataStore = new DataStore(data.Guilds.Length, data.PrivateChannels.Length);
|
||||
var dataStore = new ClientState(data.Guilds.Length, data.PrivateChannels.Length);
|
||||
|
||||
var currentUser = SocketSelfUser.Create(this, data.User);
|
||||
int unavailableGuilds = 0;
|
||||
@@ -505,7 +505,7 @@ namespace Discord.WebSocket
|
||||
_sessionId = data.SessionId;
|
||||
base.CurrentUser = currentUser;
|
||||
_unavailableGuilds = unavailableGuilds;
|
||||
DataStore = dataStore;
|
||||
State = dataStore;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Discord.WebSocket
|
||||
internal SocketSelfUser(DiscordSocketClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
Status = UserStatus.Online;
|
||||
}
|
||||
internal new static SocketSelfUser Create(DiscordSocketClient discord, Model model)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Discord.WebSocket
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
public virtual Game? Game => null;
|
||||
public virtual UserStatus Status => UserStatus.Unknown;
|
||||
public virtual UserStatus Status { get; internal set; }
|
||||
|
||||
internal SocketUser(DiscordSocketClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
|
||||
Reference in New Issue
Block a user