| @@ -35,7 +35,7 @@ namespace Discord | |||
| public DiscordClient(DiscordConfig config) | |||
| { | |||
| _log = new LogManager(config.LogLevel); | |||
| _log.Message += async msg => await Log.Raise(msg).ConfigureAwait(false); | |||
| _log.Message += async msg => await Log.RaiseAsync(msg).ConfigureAwait(false); | |||
| _discordLogger = _log.CreateLogger("Discord"); | |||
| _restLogger = _log.CreateLogger("Rest"); | |||
| @@ -44,34 +44,34 @@ namespace Discord | |||
| //TODO: Is there any better way to do this WebSocketProvider access? | |||
| ApiClient = new API.DiscordApiClient(config.RestClientProvider, (config as DiscordSocketConfig)?.WebSocketProvider, requestQueue: _requestQueue); | |||
| ApiClient.SentRequest += async (method, endpoint, millis) => await _log.Verbose("Rest", $"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | |||
| ApiClient.SentRequest += async (method, endpoint, millis) => await _log.VerboseAsync("Rest", $"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task Login(TokenType tokenType, string token, bool validateToken = true) | |||
| public async Task LoginAsync(TokenType tokenType, string token, bool validateToken = true) | |||
| { | |||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| { | |||
| await LoginInternal(tokenType, token, validateToken).ConfigureAwait(false); | |||
| await LoginInternalAsync(tokenType, token, validateToken).ConfigureAwait(false); | |||
| } | |||
| finally { _connectionLock.Release(); } | |||
| } | |||
| private async Task LoginInternal(TokenType tokenType, string token, bool validateToken) | |||
| private async Task LoginInternalAsync(TokenType tokenType, string token, bool validateToken) | |||
| { | |||
| if (LoginState != LoginState.LoggedOut) | |||
| await LogoutInternal().ConfigureAwait(false); | |||
| await LogoutInternalAsync().ConfigureAwait(false); | |||
| LoginState = LoginState.LoggingIn; | |||
| try | |||
| { | |||
| await ApiClient.Login(tokenType, token).ConfigureAwait(false); | |||
| await ApiClient.LoginAsync(tokenType, token).ConfigureAwait(false); | |||
| if (validateToken) | |||
| { | |||
| try | |||
| { | |||
| await ApiClient.ValidateToken().ConfigureAwait(false); | |||
| await ApiClient.ValidateTokenAsync().ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) | |||
| { | |||
| @@ -79,63 +79,63 @@ namespace Discord | |||
| } | |||
| } | |||
| await OnLogin().ConfigureAwait(false); | |||
| await OnLoginAsync().ConfigureAwait(false); | |||
| LoginState = LoginState.LoggedIn; | |||
| } | |||
| catch (Exception) | |||
| { | |||
| await LogoutInternal().ConfigureAwait(false); | |||
| await LogoutInternalAsync().ConfigureAwait(false); | |||
| throw; | |||
| } | |||
| await LoggedIn.Raise().ConfigureAwait(false); | |||
| await LoggedIn.RaiseAsync().ConfigureAwait(false); | |||
| } | |||
| protected virtual Task OnLogin() => Task.CompletedTask; | |||
| protected virtual Task OnLoginAsync() => Task.CompletedTask; | |||
| /// <inheritdoc /> | |||
| public async Task Logout() | |||
| public async Task LogoutAsync() | |||
| { | |||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| { | |||
| await LogoutInternal().ConfigureAwait(false); | |||
| await LogoutInternalAsync().ConfigureAwait(false); | |||
| } | |||
| finally { _connectionLock.Release(); } | |||
| } | |||
| private async Task LogoutInternal() | |||
| private async Task LogoutInternalAsync() | |||
| { | |||
| if (LoginState == LoginState.LoggedOut) return; | |||
| LoginState = LoginState.LoggingOut; | |||
| await ApiClient.Logout().ConfigureAwait(false); | |||
| await ApiClient.LogoutAsync().ConfigureAwait(false); | |||
| await OnLogout().ConfigureAwait(false); | |||
| await OnLogoutAsync().ConfigureAwait(false); | |||
| _currentUser = null; | |||
| LoginState = LoginState.LoggedOut; | |||
| await LoggedOut.Raise().ConfigureAwait(false); | |||
| await LoggedOut.RaiseAsync().ConfigureAwait(false); | |||
| } | |||
| protected virtual Task OnLogout() => Task.CompletedTask; | |||
| protected virtual Task OnLogoutAsync() => Task.CompletedTask; | |||
| /// <inheritdoc /> | |||
| public async Task<IReadOnlyCollection<IConnection>> GetConnections() | |||
| public async Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync() | |||
| { | |||
| var models = await ApiClient.GetCurrentUserConnections().ConfigureAwait(false); | |||
| var models = await ApiClient.GetMyConnectionsAsync().ConfigureAwait(false); | |||
| return models.Select(x => new Connection(x)).ToImmutableArray(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IChannel> GetChannel(ulong id) | |||
| public virtual async Task<IChannel> GetChannelAsync(ulong id) | |||
| { | |||
| var model = await ApiClient.GetChannel(id).ConfigureAwait(false); | |||
| var model = await ApiClient.GetChannelAsync(id).ConfigureAwait(false); | |||
| if (model != null) | |||
| { | |||
| if (model.GuildId != null) | |||
| { | |||
| var guildModel = await ApiClient.GetGuild(model.GuildId.Value).ConfigureAwait(false); | |||
| var guildModel = await ApiClient.GetGuildAsync(model.GuildId.Value).ConfigureAwait(false); | |||
| if (guildModel != null) | |||
| { | |||
| var guild = new Guild(this, guildModel); | |||
| @@ -148,97 +148,97 @@ namespace Discord | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IReadOnlyCollection<IDMChannel>> GetDMChannels() | |||
| public virtual async Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync() | |||
| { | |||
| var models = await ApiClient.GetCurrentUserDMs().ConfigureAwait(false); | |||
| var models = await ApiClient.GetMyDMsAsync().ConfigureAwait(false); | |||
| return models.Select(x => new DMChannel(this, new User(this, x.Recipient), x)).ToImmutableArray(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IInvite> GetInvite(string inviteIdOrXkcd) | |||
| public virtual async Task<IInvite> GetInviteAsync(string inviteIdOrXkcd) | |||
| { | |||
| var model = await ApiClient.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); | |||
| var model = await ApiClient.GetInviteAsync(inviteIdOrXkcd).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new Invite(this, model); | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IGuild> GetGuild(ulong id) | |||
| public virtual async Task<IGuild> GetGuildAsync(ulong id) | |||
| { | |||
| var model = await ApiClient.GetGuild(id).ConfigureAwait(false); | |||
| var model = await ApiClient.GetGuildAsync(id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new Guild(this, model); | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<GuildEmbed?> GetGuildEmbed(ulong id) | |||
| public virtual async Task<GuildEmbed?> GetGuildEmbedAsync(ulong id) | |||
| { | |||
| var model = await ApiClient.GetGuildEmbed(id).ConfigureAwait(false); | |||
| var model = await ApiClient.GetGuildEmbedAsync(id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new GuildEmbed(model); | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IReadOnlyCollection<IUserGuild>> GetGuilds() | |||
| public virtual async Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync() | |||
| { | |||
| var models = await ApiClient.GetCurrentUserGuilds().ConfigureAwait(false); | |||
| var models = await ApiClient.GetMyGuildsAsync().ConfigureAwait(false); | |||
| return models.Select(x => new UserGuild(this, x)).ToImmutableArray(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IGuild> CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null) | |||
| public virtual async Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) | |||
| { | |||
| var args = new CreateGuildParams(); | |||
| var model = await ApiClient.CreateGuild(args).ConfigureAwait(false); | |||
| var model = await ApiClient.CreateGuildAsync(args).ConfigureAwait(false); | |||
| return new Guild(this, model); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IUser> GetUser(ulong id) | |||
| public virtual async Task<IUser> GetUserAsync(ulong id) | |||
| { | |||
| var model = await ApiClient.GetUser(id).ConfigureAwait(false); | |||
| var model = await ApiClient.GetUserAsync(id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new User(this, model); | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IUser> GetUser(string username, string discriminator) | |||
| public virtual async Task<IUser> GetUserAsync(string username, string discriminator) | |||
| { | |||
| var model = await ApiClient.GetUser(username, discriminator).ConfigureAwait(false); | |||
| var model = await ApiClient.GetUserAsync(username, discriminator).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new User(this, model); | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<ISelfUser> GetCurrentUser() | |||
| public virtual async Task<ISelfUser> GetCurrentUserAsync() | |||
| { | |||
| var user = _currentUser; | |||
| if (user == null) | |||
| { | |||
| var model = await ApiClient.GetCurrentUser().ConfigureAwait(false); | |||
| var model = await ApiClient.GetSelfAsync().ConfigureAwait(false); | |||
| user = new SelfUser(this, model); | |||
| _currentUser = user; | |||
| } | |||
| return user; | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IReadOnlyCollection<IUser>> QueryUsers(string query, int limit) | |||
| public virtual async Task<IReadOnlyCollection<IUser>> QueryUsersAsync(string query, int limit) | |||
| { | |||
| var models = await ApiClient.QueryUsers(query, limit).ConfigureAwait(false); | |||
| var models = await ApiClient.QueryUsersAsync(query, limit).ConfigureAwait(false); | |||
| return models.Select(x => new User(this, x)).ToImmutableArray(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegions() | |||
| public virtual async Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync() | |||
| { | |||
| var models = await ApiClient.GetVoiceRegions().ConfigureAwait(false); | |||
| var models = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); | |||
| return models.Select(x => new VoiceRegion(x)).ToImmutableArray(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public virtual async Task<IVoiceRegion> GetVoiceRegion(string id) | |||
| public virtual async Task<IVoiceRegion> GetVoiceRegionAsync(string id) | |||
| { | |||
| var models = await ApiClient.GetVoiceRegions().ConfigureAwait(false); | |||
| var models = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); | |||
| return models.Select(x => new VoiceRegion(x)).Where(x => x.Id == id).FirstOrDefault(); | |||
| } | |||
| @@ -251,7 +251,7 @@ namespace Discord | |||
| public void Dispose() => Dispose(true); | |||
| ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; | |||
| Task IDiscordClient.Connect() { throw new NotSupportedException(); } | |||
| Task IDiscordClient.Disconnect() { throw new NotSupportedException(); } | |||
| Task IDiscordClient.ConnectAsync() { throw new NotSupportedException(); } | |||
| Task IDiscordClient.DisconnectAsync() { throw new NotSupportedException(); } | |||
| } | |||
| } | |||
| @@ -115,38 +115,38 @@ namespace Discord | |||
| _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; | |||
| ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.Debug($"Sent {(GatewayOpCode)opCode}"); | |||
| ApiClient.ReceivedGatewayEvent += ProcessMessage; | |||
| ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.DebugAsync($"Sent {(GatewayOpCode)opCode}"); | |||
| ApiClient.ReceivedGatewayEvent += ProcessMessageAsync; | |||
| GatewaySocket = config.WebSocketProvider(); | |||
| _voiceRegions = ImmutableDictionary.Create<string, VoiceRegion>(); | |||
| _largeGuilds = new ConcurrentQueue<ulong>(); | |||
| } | |||
| protected override async Task OnLogin() | |||
| protected override async Task OnLoginAsync() | |||
| { | |||
| var voiceRegions = await ApiClient.GetVoiceRegions().ConfigureAwait(false); | |||
| var voiceRegions = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); | |||
| _voiceRegions = voiceRegions.Select(x => new VoiceRegion(x)).ToImmutableDictionary(x => x.Id); | |||
| } | |||
| protected override async Task OnLogout() | |||
| protected override async Task OnLogoutAsync() | |||
| { | |||
| if (ConnectionState != ConnectionState.Disconnected) | |||
| await DisconnectInternal().ConfigureAwait(false); | |||
| await DisconnectInternalAsync().ConfigureAwait(false); | |||
| _voiceRegions = ImmutableDictionary.Create<string, VoiceRegion>(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task Connect() | |||
| public async Task ConnectAsync() | |||
| { | |||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| { | |||
| await ConnectInternal().ConfigureAwait(false); | |||
| await ConnectInternalAsync().ConfigureAwait(false); | |||
| } | |||
| finally { _connectionLock.Release(); } | |||
| } | |||
| private async Task ConnectInternal() | |||
| private async Task ConnectInternalAsync() | |||
| { | |||
| if (LoginState != LoginState.LoggedIn) | |||
| throw new InvalidOperationException("You must log in before connecting."); | |||
| @@ -156,47 +156,47 @@ namespace Discord | |||
| { | |||
| _connectTask = new TaskCompletionSource<bool>(); | |||
| _heartbeatCancelToken = new CancellationTokenSource(); | |||
| await ApiClient.Connect().ConfigureAwait(false); | |||
| await ApiClient.ConnectAsync().ConfigureAwait(false); | |||
| await _connectTask.Task.ConfigureAwait(false); | |||
| ConnectionState = ConnectionState.Connected; | |||
| } | |||
| catch (Exception) | |||
| { | |||
| await DisconnectInternal().ConfigureAwait(false); | |||
| await DisconnectInternalAsync().ConfigureAwait(false); | |||
| throw; | |||
| } | |||
| await Connected.Raise().ConfigureAwait(false); | |||
| await Connected.RaiseAsync().ConfigureAwait(false); | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task Disconnect() | |||
| public async Task DisconnectAsync() | |||
| { | |||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| { | |||
| await DisconnectInternal().ConfigureAwait(false); | |||
| await DisconnectInternalAsync().ConfigureAwait(false); | |||
| } | |||
| finally { _connectionLock.Release(); } | |||
| } | |||
| private async Task DisconnectInternal() | |||
| private async Task DisconnectInternalAsync() | |||
| { | |||
| ulong guildId; | |||
| if (ConnectionState == ConnectionState.Disconnected) return; | |||
| ConnectionState = ConnectionState.Disconnecting; | |||
| await ApiClient.Disconnect().ConfigureAwait(false); | |||
| await ApiClient.DisconnectAsync().ConfigureAwait(false); | |||
| await _heartbeatTask.ConfigureAwait(false); | |||
| while (_largeGuilds.TryDequeue(out guildId)) { } | |||
| ConnectionState = ConnectionState.Disconnected; | |||
| await Disconnected.Raise().ConfigureAwait(false); | |||
| await Disconnected.RaiseAsync().ConfigureAwait(false); | |||
| } | |||
| /// <inheritdoc /> | |||
| public override Task<IVoiceRegion> GetVoiceRegion(string id) | |||
| public override Task<IVoiceRegion> GetVoiceRegionAsync(string id) | |||
| { | |||
| VoiceRegion region; | |||
| if (_voiceRegions.TryGetValue(id, out region)) | |||
| @@ -205,7 +205,7 @@ namespace Discord | |||
| } | |||
| /// <inheritdoc /> | |||
| public override Task<IGuild> GetGuild(ulong id) | |||
| public override Task<IGuild> GetGuildAsync(ulong id) | |||
| { | |||
| return Task.FromResult<IGuild>(DataStore.GetGuild(id)); | |||
| } | |||
| @@ -237,7 +237,7 @@ namespace Discord | |||
| } | |||
| /// <inheritdoc /> | |||
| public override Task<IChannel> GetChannel(ulong id) | |||
| public override Task<IChannel> GetChannelAsync(ulong id) | |||
| { | |||
| return Task.FromResult<IChannel>(DataStore.GetChannel(id)); | |||
| } | |||
| @@ -284,12 +284,12 @@ namespace Discord | |||
| } | |||
| /// <inheritdoc /> | |||
| public override Task<IUser> GetUser(ulong id) | |||
| public override Task<IUser> GetUserAsync(ulong id) | |||
| { | |||
| return Task.FromResult<IUser>(DataStore.GetUser(id)); | |||
| } | |||
| /// <inheritdoc /> | |||
| public override Task<IUser> GetUser(string username, string discriminator) | |||
| public override Task<IUser> GetUserAsync(string username, string discriminator) | |||
| { | |||
| return Task.FromResult<IUser>(DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault()); | |||
| } | |||
| @@ -310,10 +310,10 @@ namespace Discord | |||
| } | |||
| /// <summary> Downloads the members list for all large guilds. </summary> | |||
| public Task DownloadAllMembers() | |||
| => DownloadMembers(DataStore.Guilds.Where(x => !x.HasAllMembers)); | |||
| public Task DownloadAllMembersAsync() | |||
| => DownloadMembersAsync(DataStore.Guilds.Where(x => !x.HasAllMembers)); | |||
| /// <summary> Downloads the members list for the provided guilds, if they don't have a complete list. </summary> | |||
| public async Task DownloadMembers(IEnumerable<IGuild> guilds) | |||
| public async Task DownloadMembersAsync(IEnumerable<IGuild> guilds) | |||
| { | |||
| const short batchSize = 50; | |||
| var cachedGuilds = guilds.Select(x => x as CachedGuild).ToArray(); | |||
| @@ -321,7 +321,7 @@ namespace Discord | |||
| return; | |||
| else if (cachedGuilds.Length == 1) | |||
| { | |||
| await cachedGuilds[0].DownloadMembers().ConfigureAwait(false); | |||
| await cachedGuilds[0].DownloadMembersAsync().ConfigureAwait(false); | |||
| return; | |||
| } | |||
| @@ -341,7 +341,7 @@ namespace Discord | |||
| batchTasks[j] = guild.DownloaderPromise; | |||
| } | |||
| await ApiClient.SendRequestMembers(batchIds).ConfigureAwait(false); | |||
| await ApiClient.SendRequestMembersAsync(batchIds).ConfigureAwait(false); | |||
| if (isLast && batchCount > 1) | |||
| await Task.WhenAll(batchTasks.Take(count)).ConfigureAwait(false); | |||
| @@ -350,7 +350,7 @@ namespace Discord | |||
| } | |||
| } | |||
| private async Task ProcessMessage(GatewayOpCode opCode, int? seq, string type, object payload) | |||
| private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string type, object payload) | |||
| { | |||
| #if BENCHMARK | |||
| Stopwatch stopwatch = Stopwatch.StartNew(); | |||
| @@ -365,22 +365,22 @@ namespace Discord | |||
| { | |||
| case GatewayOpCode.Hello: | |||
| { | |||
| await _gatewayLogger.Debug($"Received Hello").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Hello").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<HelloEvent>(_serializer); | |||
| await ApiClient.SendIdentify().ConfigureAwait(false); | |||
| _heartbeatTask = RunHeartbeat(data.HeartbeatInterval, _heartbeatCancelToken.Token); | |||
| await ApiClient.SendIdentifyAsync().ConfigureAwait(false); | |||
| _heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _heartbeatCancelToken.Token); | |||
| } | |||
| break; | |||
| case GatewayOpCode.HeartbeatAck: | |||
| { | |||
| await _gatewayLogger.Debug($"Received HeartbeatAck").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received HeartbeatAck").ConfigureAwait(false); | |||
| var latency = (int)(Environment.TickCount - _heartbeatTime); | |||
| await _gatewayLogger.Debug($"Latency = {latency} ms").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Latency = {latency} ms").ConfigureAwait(false); | |||
| Latency = latency; | |||
| await LatencyUpdated.Raise(latency).ConfigureAwait(false); | |||
| await LatencyUpdated.RaiseAsync(latency).ConfigureAwait(false); | |||
| } | |||
| break; | |||
| case GatewayOpCode.Dispatch: | |||
| @@ -389,7 +389,7 @@ namespace Discord | |||
| //Global | |||
| case "READY": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (READY)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (READY)").ConfigureAwait(false); | |||
| //TODO: Make downloading large guilds optional | |||
| var data = (payload as JToken).ToObject<ReadyEvent>(_serializer); | |||
| @@ -405,7 +405,7 @@ namespace Discord | |||
| _sessionId = data.SessionId; | |||
| DataStore = dataStore; | |||
| await Ready.Raise().ConfigureAwait(false); | |||
| await Ready.RaiseAsync().ConfigureAwait(false); | |||
| _connectTask.TrySetResult(true); //Signal the .Connect() call to complete | |||
| } | |||
| @@ -420,17 +420,17 @@ namespace Discord | |||
| if (data.Unavailable == false) | |||
| type = "GUILD_AVAILABLE"; | |||
| await _gatewayLogger.Debug($"Received Dispatch ({type})").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); | |||
| if (data.Unavailable != false) | |||
| await JoinedGuild.Raise(guild).ConfigureAwait(false); | |||
| await JoinedGuild.RaiseAsync(guild).ConfigureAwait(false); | |||
| await GuildAvailable.Raise(guild).ConfigureAwait(false); | |||
| await GuildAvailable.RaiseAsync(guild).ConfigureAwait(false); | |||
| } | |||
| break; | |||
| case "GUILD_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Guild>(_serializer); | |||
| var guild = DataStore.GetGuild(data.Id); | |||
| @@ -438,10 +438,10 @@ namespace Discord | |||
| { | |||
| var before = _enablePreUpdateEvents ? guild.Clone() : null; | |||
| guild.Update(data, UpdateSource.WebSocket); | |||
| await GuildUpdated.Raise(before, guild).ConfigureAwait(false); | |||
| await GuildUpdated.RaiseAsync(before, guild).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_UPDATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_UPDATE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_DELETE": | |||
| @@ -449,26 +449,26 @@ namespace Discord | |||
| var data = (payload as JToken).ToObject<ExtendedGuild>(_serializer); | |||
| if (data.Unavailable == true) | |||
| type = "GUILD_UNAVAILABLE"; | |||
| await _gatewayLogger.Debug($"Received Dispatch ({type})").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); | |||
| var guild = DataStore.RemoveGuild(data.Id); | |||
| if (guild != null) | |||
| { | |||
| await GuildUnavailable.Raise(guild).ConfigureAwait(false); | |||
| await GuildUnavailable.RaiseAsync(guild).ConfigureAwait(false); | |||
| if (data.Unavailable != true) | |||
| await LeftGuild.Raise(guild).ConfigureAwait(false); | |||
| await LeftGuild.RaiseAsync(guild).ConfigureAwait(false); | |||
| foreach (var member in guild.Members) | |||
| member.User.RemoveRef(); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning($"{type} referenced an unknown guild.").ConfigureAwait(false); | |||
| await _gatewayLogger.WarningAsync($"{type} referenced an unknown guild.").ConfigureAwait(false); | |||
| } | |||
| break; | |||
| //Channels | |||
| case "CHANNEL_CREATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_CREATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_CREATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Channel>(_serializer); | |||
| ICachedChannel channel = null; | |||
| @@ -481,17 +481,17 @@ namespace Discord | |||
| DataStore.AddChannel(channel); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("CHANNEL_CREATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("CHANNEL_CREATE referenced an unknown guild."); | |||
| } | |||
| else | |||
| channel = AddCachedDMChannel(data); | |||
| if (channel != null) | |||
| await ChannelCreated.Raise(channel); | |||
| await ChannelCreated.RaiseAsync(channel); | |||
| } | |||
| break; | |||
| case "CHANNEL_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Channel>(_serializer); | |||
| var channel = DataStore.GetChannel(data.Id); | |||
| @@ -499,44 +499,44 @@ namespace Discord | |||
| { | |||
| var before = _enablePreUpdateEvents ? channel.Clone() : null; | |||
| channel.Update(data, UpdateSource.WebSocket); | |||
| await ChannelUpdated.Raise(before, channel); | |||
| await ChannelUpdated.RaiseAsync(before, channel); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("CHANNEL_UPDATE referenced an unknown channel."); | |||
| await _gatewayLogger.WarningAsync("CHANNEL_UPDATE referenced an unknown channel."); | |||
| } | |||
| break; | |||
| case "CHANNEL_DELETE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_DELETE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_DELETE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Channel>(_serializer); | |||
| var channel = RemoveCachedChannel(data.Id); | |||
| if (channel != null) | |||
| await ChannelDestroyed.Raise(channel); | |||
| await ChannelDestroyed.RaiseAsync(channel); | |||
| else | |||
| await _gatewayLogger.Warning("CHANNEL_DELETE referenced an unknown channel."); | |||
| await _gatewayLogger.WarningAsync("CHANNEL_DELETE referenced an unknown channel."); | |||
| } | |||
| break; | |||
| //Members | |||
| case "GUILD_MEMBER_ADD": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_ADD)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_ADD)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildMemberAddEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| if (guild != null) | |||
| { | |||
| var user = guild.AddCachedUser(data); | |||
| await UserJoined.Raise(user).ConfigureAwait(false); | |||
| await UserJoined.RaiseAsync(user).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBER_ADD referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBER_ADD referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_MEMBER_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildMemberUpdateEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| @@ -547,18 +547,18 @@ namespace Discord | |||
| { | |||
| var before = _enablePreUpdateEvents ? user.Clone() : null; | |||
| user.Update(data, UpdateSource.WebSocket); | |||
| await UserUpdated.Raise(before, user); | |||
| await UserUpdated.RaiseAsync(before, user); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBER_UPDATE referenced an unknown user."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBER_UPDATE referenced an unknown user."); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBER_UPDATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBER_UPDATE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_MEMBER_REMOVE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_REMOVE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_REMOVE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildMemberRemoveEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| @@ -568,18 +568,18 @@ namespace Discord | |||
| if (user != null) | |||
| { | |||
| user.User.RemoveRef(); | |||
| await UserLeft.Raise(user); | |||
| await UserLeft.RaiseAsync(user); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBER_REMOVE referenced an unknown user."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBER_REMOVE referenced an unknown user."); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBER_REMOVE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBER_REMOVE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_MEMBERS_CHUNK": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBERS_CHUNK)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBERS_CHUNK)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildMembersChunkEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| @@ -591,33 +591,33 @@ namespace Discord | |||
| if (guild.DownloadedMemberCount >= guild.MemberCount) //Finished downloading for there | |||
| { | |||
| guild.CompleteDownloadMembers(); | |||
| await GuildDownloadedMembers.Raise(guild).ConfigureAwait(false); | |||
| await GuildDownloadedMembers.RaiseAsync(guild).ConfigureAwait(false); | |||
| } | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_MEMBERS_CHUNK referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_MEMBERS_CHUNK referenced an unknown guild."); | |||
| } | |||
| break; | |||
| //Roles | |||
| case "GUILD_ROLE_CREATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_CREATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_CREATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildRoleCreateEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| if (guild != null) | |||
| { | |||
| var role = guild.AddCachedRole(data.Role); | |||
| await RoleCreated.Raise(role).ConfigureAwait(false); | |||
| await RoleCreated.RaiseAsync(role).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_ROLE_CREATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_ROLE_CREATE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_ROLE_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildRoleUpdateEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| @@ -628,18 +628,18 @@ namespace Discord | |||
| { | |||
| var before = _enablePreUpdateEvents ? role.Clone() : null; | |||
| role.Update(data.Role, UpdateSource.WebSocket); | |||
| await RoleUpdated.Raise(before, role).ConfigureAwait(false); | |||
| await RoleUpdated.RaiseAsync(before, role).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_ROLE_UPDATE referenced an unknown role."); | |||
| await _gatewayLogger.WarningAsync("GUILD_ROLE_UPDATE referenced an unknown role."); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_ROLE_UPDATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_ROLE_UPDATE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_ROLE_DELETE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_DELETE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_DELETE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildRoleDeleteEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| @@ -647,45 +647,45 @@ namespace Discord | |||
| { | |||
| var role = guild.RemoveCachedRole(data.RoleId); | |||
| if (role != null) | |||
| await RoleDeleted.Raise(role).ConfigureAwait(false); | |||
| await RoleDeleted.RaiseAsync(role).ConfigureAwait(false); | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_ROLE_DELETE referenced an unknown role."); | |||
| await _gatewayLogger.WarningAsync("GUILD_ROLE_DELETE referenced an unknown role."); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_ROLE_DELETE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_ROLE_DELETE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| //Bans | |||
| case "GUILD_BAN_ADD": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_BAN_ADD)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_BAN_ADD)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildBanEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| if (guild != null) | |||
| await UserBanned.Raise(new User(this, data)); | |||
| await UserBanned.RaiseAsync(new User(this, data)); | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_BAN_ADD referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_BAN_ADD referenced an unknown guild."); | |||
| } | |||
| break; | |||
| case "GUILD_BAN_REMOVE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (GUILD_BAN_REMOVE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_BAN_REMOVE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<GuildBanEvent>(_serializer); | |||
| var guild = DataStore.GetGuild(data.GuildId); | |||
| if (guild != null) | |||
| await UserUnbanned.Raise(new User(this, data)); | |||
| await UserUnbanned.RaiseAsync(new User(this, data)); | |||
| else | |||
| await _gatewayLogger.Warning("GUILD_BAN_REMOVE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("GUILD_BAN_REMOVE referenced an unknown guild."); | |||
| } | |||
| break; | |||
| //Messages | |||
| case "MESSAGE_CREATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Message>(_serializer); | |||
| var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; | |||
| @@ -696,18 +696,18 @@ namespace Discord | |||
| if (author != null) | |||
| { | |||
| var msg = channel.AddCachedMessage(author, data); | |||
| await MessageReceived.Raise(msg).ConfigureAwait(false); | |||
| await MessageReceived.RaiseAsync(msg).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("MESSAGE_CREATE referenced an unknown user."); | |||
| await _gatewayLogger.WarningAsync("MESSAGE_CREATE referenced an unknown user."); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("MESSAGE_CREATE referenced an unknown channel."); | |||
| await _gatewayLogger.WarningAsync("MESSAGE_CREATE referenced an unknown channel."); | |||
| } | |||
| break; | |||
| case "MESSAGE_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Message>(_serializer); | |||
| var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; | |||
| @@ -716,32 +716,32 @@ namespace Discord | |||
| var msg = channel.GetCachedMessage(data.Id); | |||
| var before = _enablePreUpdateEvents ? msg.Clone() : null; | |||
| msg.Update(data, UpdateSource.WebSocket); | |||
| await MessageUpdated.Raise(before, msg).ConfigureAwait(false); | |||
| await MessageUpdated.RaiseAsync(before, msg).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("MESSAGE_UPDATE referenced an unknown channel."); | |||
| await _gatewayLogger.WarningAsync("MESSAGE_UPDATE referenced an unknown channel."); | |||
| } | |||
| break; | |||
| case "MESSAGE_DELETE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Message>(_serializer); | |||
| var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; | |||
| if (channel != null) | |||
| { | |||
| var msg = channel.RemoveCachedMessage(data.Id); | |||
| await MessageDeleted.Raise(msg).ConfigureAwait(false); | |||
| await MessageDeleted.RaiseAsync(msg).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("MESSAGE_DELETE referenced an unknown channel."); | |||
| await _gatewayLogger.WarningAsync("MESSAGE_DELETE referenced an unknown channel."); | |||
| } | |||
| break; | |||
| //Statuses | |||
| case "PRESENCE_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.Presence>(_serializer); | |||
| if (data.GuildId == null) | |||
| @@ -755,7 +755,7 @@ namespace Discord | |||
| var guild = DataStore.GetGuild(data.GuildId.Value); | |||
| if (guild == null) | |||
| { | |||
| await _gatewayLogger.Warning("PRESENCE_UPDATE referenced an unknown guild."); | |||
| await _gatewayLogger.WarningAsync("PRESENCE_UPDATE referenced an unknown guild."); | |||
| break; | |||
| } | |||
| if (data.Status == UserStatus.Offline) | |||
| @@ -767,7 +767,7 @@ namespace Discord | |||
| break; | |||
| case "TYPING_START": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (TYPING_START)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (TYPING_START)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<TypingStartEvent>(_serializer); | |||
| var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; | |||
| @@ -775,17 +775,17 @@ namespace Discord | |||
| { | |||
| var user = channel.GetCachedUser(data.UserId); | |||
| if (user != null) | |||
| await UserIsTyping.Raise(channel, user).ConfigureAwait(false); | |||
| await UserIsTyping.RaiseAsync(channel, user).ConfigureAwait(false); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("TYPING_START referenced an unknown channel.").ConfigureAwait(false); | |||
| await _gatewayLogger.WarningAsync("TYPING_START referenced an unknown channel.").ConfigureAwait(false); | |||
| } | |||
| break; | |||
| //Voice | |||
| case "VOICE_STATE_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.VoiceState>(_serializer); | |||
| if (data.GuildId.HasValue) | |||
| @@ -802,7 +802,7 @@ namespace Discord | |||
| user.Update(data, UpdateSource.WebSocket); | |||
| } | |||
| else | |||
| await _gatewayLogger.Warning("VOICE_STATE_UPDATE referenced an unknown guild.").ConfigureAwait(false); | |||
| await _gatewayLogger.WarningAsync("VOICE_STATE_UPDATE referenced an unknown guild.").ConfigureAwait(false); | |||
| } | |||
| } | |||
| break; | |||
| @@ -810,14 +810,14 @@ namespace Discord | |||
| //Settings | |||
| case "USER_UPDATE": | |||
| { | |||
| await _gatewayLogger.Debug($"Received Dispatch (USER_UPDATE)").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Received Dispatch (USER_UPDATE)").ConfigureAwait(false); | |||
| var data = (payload as JToken).ToObject<API.User>(_serializer); | |||
| if (data.Id == CurrentUser.Id) | |||
| { | |||
| var before = _enablePreUpdateEvents ? CurrentUser.Clone() : null; | |||
| CurrentUser.Update(data, UpdateSource.WebSocket); | |||
| await CurrentUserUpdated.Raise(before, CurrentUser).ConfigureAwait(false); | |||
| await CurrentUserUpdated.RaiseAsync(before, CurrentUser).ConfigureAwait(false); | |||
| } | |||
| } | |||
| break; | |||
| @@ -829,23 +829,23 @@ namespace Discord | |||
| case "GUILD_INTEGRATIONS_UPDATE": //TODO: Add | |||
| case "VOICE_SERVER_UPDATE": //TODO: Add | |||
| case "RESUMED": //TODO: Add | |||
| await _gatewayLogger.Debug($"Ignored Dispatch ({type})").ConfigureAwait(false); | |||
| await _gatewayLogger.DebugAsync($"Ignored Dispatch ({type})").ConfigureAwait(false); | |||
| return; | |||
| //Others | |||
| default: | |||
| await _gatewayLogger.Warning($"Unknown Dispatch ({type})").ConfigureAwait(false); | |||
| await _gatewayLogger.WarningAsync($"Unknown Dispatch ({type})").ConfigureAwait(false); | |||
| return; | |||
| } | |||
| break; | |||
| default: | |||
| await _gatewayLogger.Warning($"Unknown OpCode ({opCode})").ConfigureAwait(false); | |||
| await _gatewayLogger.WarningAsync($"Unknown OpCode ({opCode})").ConfigureAwait(false); | |||
| return; | |||
| } | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| await _gatewayLogger.Error($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); | |||
| await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); | |||
| return; | |||
| } | |||
| #if BENCHMARK | |||
| @@ -854,11 +854,11 @@ namespace Discord | |||
| { | |||
| stopwatch.Stop(); | |||
| double millis = Math.Round(stopwatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000.0, 2); | |||
| await _benchmarkLogger.Debug($"{millis} ms").ConfigureAwait(false); | |||
| await _benchmarkLogger.DebugAsync($"{millis} ms").ConfigureAwait(false); | |||
| } | |||
| #endif | |||
| } | |||
| private async Task RunHeartbeat(int intervalMillis, CancellationToken cancelToken) | |||
| private async Task RunHeartbeatAsync(int intervalMillis, CancellationToken cancelToken) | |||
| { | |||
| try | |||
| { | |||
| @@ -868,7 +868,7 @@ namespace Discord | |||
| //if (_heartbeatTime != 0) //TODO: Connection lost, reconnect | |||
| _heartbeatTime = Environment.TickCount; | |||
| await ApiClient.SendHeartbeat(_lastSeq).ConfigureAwait(false); | |||
| await ApiClient.SendHeartbeatAsync(_lastSeq).ConfigureAwait(false); | |||
| await Task.Delay(intervalMillis, cancelToken).ConfigureAwait(false); | |||
| } | |||
| } | |||
| @@ -33,21 +33,21 @@ namespace Discord | |||
| Recipient.Update(model.Recipient, UpdateSource.Rest); | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var model = await Discord.ApiClient.GetChannel(Id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelAsync(Id).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Close() | |||
| public async Task CloseAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteChannel(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteChannelAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public virtual async Task<IUser> GetUser(ulong id) | |||
| public virtual async Task<IUser> GetUserAsync(ulong id) | |||
| { | |||
| var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); | |||
| var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); | |||
| if (id == Recipient.Id) | |||
| return Recipient; | |||
| else if (id == currentUser.Id) | |||
| @@ -55,66 +55,66 @@ namespace Discord | |||
| else | |||
| return null; | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IUser>> GetUsers() | |||
| public virtual async Task<IReadOnlyCollection<IUser>> GetUsersAsync() | |||
| { | |||
| var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); | |||
| var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); | |||
| return ImmutableArray.Create<IUser>(currentUser, Recipient); | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IUser>> GetUsers(int limit, int offset) | |||
| public virtual async Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset) | |||
| { | |||
| var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); | |||
| var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); | |||
| return new IUser[] { currentUser, Recipient }.Skip(offset).Take(limit).ToImmutableArray(); | |||
| } | |||
| public async Task<IMessage> SendMessage(string text, bool isTTS) | |||
| public async Task<IMessage> SendMessageAsync(string text, bool isTTS) | |||
| { | |||
| var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.CreateDMMessage(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateDMMessageAsync(Id, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| public async Task<IMessage> SendFile(string filePath, string text, bool isTTS) | |||
| public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | |||
| { | |||
| string filename = Path.GetFileName(filePath); | |||
| using (var file = File.OpenRead(filePath)) | |||
| { | |||
| var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.UploadDMFile(Id, file, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.UploadDMFileAsync(Id, file, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| } | |||
| public async Task<IMessage> SendFile(Stream stream, string filename, string text, bool isTTS) | |||
| public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | |||
| { | |||
| var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.UploadDMFile(Id, stream, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.UploadDMFileAsync(Id, stream, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| public virtual async Task<IMessage> GetMessage(ulong id) | |||
| public virtual async Task<IMessage> GetMessageAsync(ulong id) | |||
| { | |||
| var model = await Discord.ApiClient.GetChannelMessage(Id, id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| return null; | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessages(int limit) | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | |||
| { | |||
| var args = new GetChannelMessagesParams { Limit = limit }; | |||
| var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessages(ulong fromMessageId, Direction dir, int limit) | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | |||
| { | |||
| var args = new GetChannelMessagesParams { Limit = limit }; | |||
| var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); | |||
| } | |||
| public async Task DeleteMessages(IEnumerable<IMessage> messages) | |||
| public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | |||
| { | |||
| await Discord.ApiClient.DeleteDMMessages(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteDMMessagesAsync(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); | |||
| } | |||
| public async Task TriggerTyping() | |||
| public async Task TriggerTypingAsync() | |||
| { | |||
| await Discord.ApiClient.TriggerTypingIndicator(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.TriggerTypingIndicatorAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public override string ToString() => '@' + Recipient.ToString(); | |||
| @@ -46,37 +46,37 @@ namespace Discord | |||
| _overwrites = newOverwrites; | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var model = await Discord.ApiClient.GetChannel(Id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelAsync(Id).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyGuildChannelParams> func) | |||
| public async Task ModifyAsync(Action<ModifyGuildChannelParams> func) | |||
| { | |||
| if (func != null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildChannelParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteChannel(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteChannelAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public abstract Task<IGuildUser> GetUser(ulong id); | |||
| public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsers(); | |||
| public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset); | |||
| public abstract Task<IGuildUser> GetUserAsync(ulong id); | |||
| public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(); | |||
| public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset); | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvites() | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync() | |||
| { | |||
| var models = await Discord.ApiClient.GetChannelInvites(Id).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetChannelInvitesAsync(Id).ConfigureAwait(false); | |||
| return models.Select(x => new InviteMetadata(Discord, x)).ToImmutableArray(); | |||
| } | |||
| public async Task<IInviteMetadata> CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
| public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
| { | |||
| var args = new CreateChannelInviteParams | |||
| { | |||
| @@ -85,7 +85,7 @@ namespace Discord | |||
| Temporary = isTemporary, | |||
| XkcdPass = withXkcd | |||
| }; | |||
| var model = await Discord.ApiClient.CreateChannelInvite(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateChannelInviteAsync(Id, args).ConfigureAwait(false); | |||
| return new InviteMetadata(Discord, model); | |||
| } | |||
| @@ -104,28 +104,28 @@ namespace Discord | |||
| return null; | |||
| } | |||
| public async Task AddPermissionOverwrite(IUser user, OverwritePermissions perms) | |||
| public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms) | |||
| { | |||
| var args = new ModifyChannelPermissionsParams { Allow = perms.AllowValue, Deny = perms.DenyValue }; | |||
| await Discord.ApiClient.ModifyChannelPermissions(Id, user.Id, args).ConfigureAwait(false); | |||
| await Discord.ApiClient.ModifyChannelPermissionsAsync(Id, user.Id, args).ConfigureAwait(false); | |||
| _overwrites[user.Id] = new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }); | |||
| } | |||
| public async Task AddPermissionOverwrite(IRole role, OverwritePermissions perms) | |||
| public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms) | |||
| { | |||
| var args = new ModifyChannelPermissionsParams { Allow = perms.AllowValue, Deny = perms.DenyValue }; | |||
| await Discord.ApiClient.ModifyChannelPermissions(Id, role.Id, args).ConfigureAwait(false); | |||
| await Discord.ApiClient.ModifyChannelPermissionsAsync(Id, role.Id, args).ConfigureAwait(false); | |||
| _overwrites[role.Id] = new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }); | |||
| } | |||
| public async Task RemovePermissionOverwrite(IUser user) | |||
| public async Task RemovePermissionOverwriteAsync(IUser user) | |||
| { | |||
| await Discord.ApiClient.DeleteChannelPermission(Id, user.Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteChannelPermissionAsync(Id, user.Id).ConfigureAwait(false); | |||
| Overwrite value; | |||
| _overwrites.TryRemove(user.Id, out value); | |||
| } | |||
| public async Task RemovePermissionOverwrite(IRole role) | |||
| public async Task RemovePermissionOverwriteAsync(IRole role) | |||
| { | |||
| await Discord.ApiClient.DeleteChannelPermission(Id, role.Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteChannelPermissionAsync(Id, role.Id).ConfigureAwait(false); | |||
| Overwrite value; | |||
| _overwrites.TryRemove(role.Id, out value); | |||
| @@ -137,8 +137,8 @@ namespace Discord | |||
| IGuild IGuildChannel.Guild => Guild; | |||
| IReadOnlyCollection<Overwrite> IGuildChannel.PermissionOverwrites => _overwrites.ToReadOnlyCollection(); | |||
| async Task<IUser> IChannel.GetUser(ulong id) => await GetUser(id).ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IUser>> IChannel.GetUsers() => await GetUsers().ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IUser>> IChannel.GetUsers(int limit, int offset) => await GetUsers(limit, offset).ConfigureAwait(false); | |||
| async Task<IUser> IChannel.GetUserAsync(ulong id) => await GetUserAsync(id).ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync() => await GetUsersAsync().ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(int limit, int offset) => await GetUsersAsync(limit, offset).ConfigureAwait(false); | |||
| } | |||
| } | |||
| @@ -6,10 +6,10 @@ namespace Discord | |||
| public interface IChannel : ISnowflakeEntity | |||
| { | |||
| /// <summary> Gets a collection of all users in this channel. </summary> | |||
| Task<IReadOnlyCollection<IUser>> GetUsers(); | |||
| Task<IReadOnlyCollection<IUser>> GetUsersAsync(); | |||
| /// <summary> Gets a paginated collection of all users in this channel. </summary> | |||
| Task<IReadOnlyCollection<IUser>> GetUsers(int limit, int offset = 0); | |||
| Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset = 0); | |||
| /// <summary> Gets a user in this channel with the provided id.</summary> | |||
| Task<IUser> GetUser(ulong id); | |||
| Task<IUser> GetUserAsync(ulong id); | |||
| } | |||
| } | |||
| @@ -8,6 +8,6 @@ namespace Discord | |||
| IUser Recipient { get; } | |||
| /// <summary> Closes this private channel, removing it from your channel list. </summary> | |||
| Task Close(); | |||
| Task CloseAsync(); | |||
| } | |||
| } | |||
| @@ -20,32 +20,32 @@ namespace Discord | |||
| /// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
| /// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
| /// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
| Task<IInviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
| Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
| /// <summary> Returns a collection of all invites to this channel. </summary> | |||
| Task<IReadOnlyCollection<IInviteMetadata>> GetInvites(); | |||
| Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(); | |||
| /// <summary> Gets a collection of permission overwrites for this channel. </summary> | |||
| IReadOnlyCollection<Overwrite> PermissionOverwrites { get; } | |||
| /// <summary> Modifies this guild channel. </summary> | |||
| Task Modify(Action<ModifyGuildChannelParams> func); | |||
| Task ModifyAsync(Action<ModifyGuildChannelParams> func); | |||
| /// <summary> Gets the permission overwrite for a specific role, or null if one does not exist. </summary> | |||
| OverwritePermissions? GetPermissionOverwrite(IRole role); | |||
| /// <summary> Gets the permission overwrite for a specific user, or null if one does not exist. </summary> | |||
| OverwritePermissions? GetPermissionOverwrite(IUser user); | |||
| /// <summary> Removes the permission overwrite for the given role, if one exists. </summary> | |||
| Task RemovePermissionOverwrite(IRole role); | |||
| Task RemovePermissionOverwriteAsync(IRole role); | |||
| /// <summary> Removes the permission overwrite for the given user, if one exists. </summary> | |||
| Task RemovePermissionOverwrite(IUser user); | |||
| Task RemovePermissionOverwriteAsync(IUser user); | |||
| /// <summary> Adds or updates the permission overwrite for the given role. </summary> | |||
| Task AddPermissionOverwrite(IRole role, OverwritePermissions permissions); | |||
| Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions); | |||
| /// <summary> Adds or updates the permission overwrite for the given user. </summary> | |||
| Task AddPermissionOverwrite(IUser user, OverwritePermissions permissions); | |||
| Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions); | |||
| /// <summary> Gets a collection of all users in this channel. </summary> | |||
| new Task<IReadOnlyCollection<IGuildUser>> GetUsers(); | |||
| new Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(); | |||
| /// <summary> Gets a user in this channel with the provided id.</summary> | |||
| new Task<IGuildUser> GetUser(ulong id); | |||
| new Task<IGuildUser> GetUserAsync(ulong id); | |||
| } | |||
| } | |||
| @@ -10,24 +10,24 @@ namespace Discord | |||
| IReadOnlyCollection<IMessage> CachedMessages { get; } | |||
| /// <summary> Sends a message to this message channel. </summary> | |||
| Task<IMessage> SendMessage(string text, bool isTTS = false); | |||
| Task<IMessage> SendMessageAsync(string text, bool isTTS = false); | |||
| /// <summary> Sends a file to this text channel, with an optional caption. </summary> | |||
| Task<IMessage> SendFile(string filePath, string text = null, bool isTTS = false); | |||
| Task<IMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false); | |||
| /// <summary> Sends a file to this text channel, with an optional caption. </summary> | |||
| Task<IMessage> SendFile(Stream stream, string filename, string text = null, bool isTTS = false); | |||
| Task<IMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false); | |||
| /// <summary> Gets a message from this message channel with the given id, or null if not found. </summary> | |||
| Task<IMessage> GetMessage(ulong id); | |||
| Task<IMessage> GetMessageAsync(ulong id); | |||
| /// <summary> Gets the message from this channel's cache with the given id, or null if not found. </summary> | |||
| IMessage GetCachedMessage(ulong id); | |||
| /// <summary> Gets the last N messages from this message channel. </summary> | |||
| Task<IReadOnlyCollection<IMessage>> GetMessages(int limit = DiscordConfig.MaxMessagesPerBatch); | |||
| Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); | |||
| /// <summary> Gets a collection of messages in this channel. </summary> | |||
| Task<IReadOnlyCollection<IMessage>> GetMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||
| Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||
| /// <summary> Bulk deletes multiple messages. </summary> | |||
| Task DeleteMessages(IEnumerable<IMessage> messages); | |||
| Task DeleteMessagesAsync(IEnumerable<IMessage> messages); | |||
| /// <summary> Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds.</summary> | |||
| Task TriggerTyping(); | |||
| Task TriggerTypingAsync(); | |||
| } | |||
| } | |||
| @@ -10,6 +10,6 @@ namespace Discord | |||
| string Topic { get; } | |||
| /// <summary> Modifies this text channel. </summary> | |||
| Task Modify(Action<ModifyTextChannelParams> func); | |||
| Task ModifyAsync(Action<ModifyTextChannelParams> func); | |||
| } | |||
| } | |||
| @@ -12,6 +12,6 @@ namespace Discord | |||
| int UserLimit { get; } | |||
| /// <summary> Modifies this voice channel. </summary> | |||
| Task Modify(Action<ModifyVoiceChannelParams> func); | |||
| Task ModifyAsync(Action<ModifyVoiceChannelParams> func); | |||
| } | |||
| } | |||
| @@ -30,83 +30,83 @@ namespace Discord | |||
| base.Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyTextChannelParams> func) | |||
| public async Task ModifyAsync(Action<ModifyTextChannelParams> func) | |||
| { | |||
| if (func != null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyTextChannelParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public override async Task<IGuildUser> GetUser(ulong id) | |||
| public override async Task<IGuildUser> GetUserAsync(ulong id) | |||
| { | |||
| var user = await Guild.GetUser(id).ConfigureAwait(false); | |||
| var user = await Guild.GetUserAsync(id).ConfigureAwait(false); | |||
| if (user != null && Permissions.GetValue(Permissions.ResolveChannel(user, this, user.GuildPermissions.RawValue), ChannelPermission.ReadMessages)) | |||
| return user; | |||
| return null; | |||
| } | |||
| public override async Task<IReadOnlyCollection<IGuildUser>> GetUsers() | |||
| public override async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() | |||
| { | |||
| var users = await Guild.GetUsers().ConfigureAwait(false); | |||
| var users = await Guild.GetUsersAsync().ConfigureAwait(false); | |||
| return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray(); | |||
| } | |||
| public override async Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public override async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| { | |||
| var users = await Guild.GetUsers(limit, offset).ConfigureAwait(false); | |||
| var users = await Guild.GetUsersAsync(limit, offset).ConfigureAwait(false); | |||
| return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray(); | |||
| } | |||
| public async Task<IMessage> SendMessage(string text, bool isTTS) | |||
| public async Task<IMessage> SendMessageAsync(string text, bool isTTS) | |||
| { | |||
| var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.CreateMessage(Guild.Id, Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateMessageAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| public async Task<IMessage> SendFile(string filePath, string text, bool isTTS) | |||
| public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | |||
| { | |||
| string filename = Path.GetFileName(filePath); | |||
| using (var file = File.OpenRead(filePath)) | |||
| { | |||
| var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.UploadFile(Guild.Id, Id, file, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, file, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| } | |||
| public async Task<IMessage> SendFile(Stream stream, string filename, string text, bool isTTS) | |||
| public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | |||
| { | |||
| var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | |||
| var model = await Discord.ApiClient.UploadFile(Guild.Id, Id, stream, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, stream, args).ConfigureAwait(false); | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| } | |||
| public virtual async Task<IMessage> GetMessage(ulong id) | |||
| public virtual async Task<IMessage> GetMessageAsync(ulong id) | |||
| { | |||
| var model = await Discord.ApiClient.GetChannelMessage(Id, id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new Message(this, new User(Discord, model.Author), model); | |||
| return null; | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessages(int limit) | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | |||
| { | |||
| var args = new GetChannelMessagesParams { Limit = limit }; | |||
| var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessages(ulong fromMessageId, Direction dir, int limit) | |||
| public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | |||
| { | |||
| var args = new GetChannelMessagesParams { Limit = limit }; | |||
| var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); | |||
| } | |||
| public async Task DeleteMessages(IEnumerable<IMessage> messages) | |||
| public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | |||
| { | |||
| await Discord.ApiClient.DeleteMessages(Guild.Id, Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteMessagesAsync(Guild.Id, Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); | |||
| } | |||
| public async Task TriggerTyping() | |||
| public async Task TriggerTypingAsync() | |||
| { | |||
| await Discord.ApiClient.TriggerTypingIndicator(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.TriggerTypingIndicatorAsync(Id).ConfigureAwait(false); | |||
| } | |||
| private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | |||
| @@ -26,25 +26,25 @@ namespace Discord | |||
| UserLimit = model.UserLimit; | |||
| } | |||
| public async Task Modify(Action<ModifyVoiceChannelParams> func) | |||
| public async Task ModifyAsync(Action<ModifyVoiceChannelParams> func) | |||
| { | |||
| if (func != null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyVoiceChannelParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public override Task<IGuildUser> GetUser(ulong id) | |||
| public override Task<IGuildUser> GetUserAsync(ulong id) | |||
| { | |||
| throw new NotSupportedException(); | |||
| } | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers() | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() | |||
| { | |||
| throw new NotSupportedException(); | |||
| } | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| { | |||
| throw new NotSupportedException(); | |||
| } | |||
| @@ -103,114 +103,114 @@ namespace Discord | |||
| } | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var response = await Discord.ApiClient.GetGuild(Id).ConfigureAwait(false); | |||
| var response = await Discord.ApiClient.GetGuildAsync(Id).ConfigureAwait(false); | |||
| Update(response, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyGuildParams> func) | |||
| public async Task ModifyAsync(Action<ModifyGuildParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuild(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task ModifyEmbed(Action<ModifyGuildEmbedParams> func) | |||
| public async Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildEmbedParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuildEmbed(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildEmbedAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task ModifyChannels(IEnumerable<ModifyGuildChannelsParams> args) | |||
| public async Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args) | |||
| { | |||
| //TODO: Update channels | |||
| await Discord.ApiClient.ModifyGuildChannels(Id, args).ConfigureAwait(false); | |||
| await Discord.ApiClient.ModifyGuildChannelsAsync(Id, args).ConfigureAwait(false); | |||
| } | |||
| public async Task ModifyRoles(IEnumerable<ModifyGuildRolesParams> args) | |||
| public async Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args) | |||
| { | |||
| var models = await Discord.ApiClient.ModifyGuildRoles(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.ModifyGuildRolesAsync(Id, args).ConfigureAwait(false); | |||
| Update(models, UpdateSource.Rest); | |||
| } | |||
| public async Task Leave() | |||
| public async Task LeaveAsync() | |||
| { | |||
| await Discord.ApiClient.LeaveGuild(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteGuild(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public async Task<IReadOnlyCollection<IUser>> GetBans() | |||
| public async Task<IReadOnlyCollection<IUser>> GetBansAsync() | |||
| { | |||
| var models = await Discord.ApiClient.GetGuildBans(Id).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildBansAsync(Id).ConfigureAwait(false); | |||
| return models.Select(x => new User(Discord, x)).ToImmutableArray(); | |||
| } | |||
| public Task AddBan(IUser user, int pruneDays = 0) => AddBan(user, pruneDays); | |||
| public async Task AddBan(ulong userId, int pruneDays = 0) | |||
| public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); | |||
| public async Task AddBanAsync(ulong userId, int pruneDays = 0) | |||
| { | |||
| var args = new CreateGuildBanParams() { PruneDays = pruneDays }; | |||
| await Discord.ApiClient.CreateGuildBan(Id, userId, args).ConfigureAwait(false); | |||
| await Discord.ApiClient.CreateGuildBanAsync(Id, userId, args).ConfigureAwait(false); | |||
| } | |||
| public Task RemoveBan(IUser user) => RemoveBan(user.Id); | |||
| public async Task RemoveBan(ulong userId) | |||
| public Task RemoveBanAsync(IUser user) => RemoveBanAsync(user.Id); | |||
| public async Task RemoveBanAsync(ulong userId) | |||
| { | |||
| await Discord.ApiClient.RemoveGuildBan(Id, userId).ConfigureAwait(false); | |||
| await Discord.ApiClient.RemoveGuildBanAsync(Id, userId).ConfigureAwait(false); | |||
| } | |||
| public virtual async Task<IGuildChannel> GetChannel(ulong id) | |||
| public virtual async Task<IGuildChannel> GetChannelAsync(ulong id) | |||
| { | |||
| var model = await Discord.ApiClient.GetChannel(Id, id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelAsync(Id, id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return ToChannel(model); | |||
| return null; | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IGuildChannel>> GetChannels() | |||
| public virtual async Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync() | |||
| { | |||
| var models = await Discord.ApiClient.GetGuildChannels(Id).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildChannelsAsync(Id).ConfigureAwait(false); | |||
| return models.Select(x => ToChannel(x)).ToImmutableArray(); | |||
| } | |||
| public async Task<ITextChannel> CreateTextChannel(string name) | |||
| public async Task<ITextChannel> CreateTextChannelAsync(string name) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| var args = new CreateGuildChannelParams() { Name = name, Type = ChannelType.Text }; | |||
| var model = await Discord.ApiClient.CreateGuildChannel(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| return new TextChannel(this, model); | |||
| } | |||
| public async Task<IVoiceChannel> CreateVoiceChannel(string name) | |||
| public async Task<IVoiceChannel> CreateVoiceChannelAsync(string name) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| var args = new CreateGuildChannelParams { Name = name, Type = ChannelType.Voice }; | |||
| var model = await Discord.ApiClient.CreateGuildChannel(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| return new VoiceChannel(this, model); | |||
| } | |||
| public async Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrations() | |||
| public async Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrationsAsync() | |||
| { | |||
| var models = await Discord.ApiClient.GetGuildIntegrations(Id).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildIntegrationsAsync(Id).ConfigureAwait(false); | |||
| return models.Select(x => new GuildIntegration(this, x)).ToImmutableArray(); | |||
| } | |||
| public async Task<IGuildIntegration> CreateIntegration(ulong id, string type) | |||
| public async Task<IGuildIntegration> CreateIntegrationAsync(ulong id, string type) | |||
| { | |||
| var args = new CreateGuildIntegrationParams { Id = id, Type = type }; | |||
| var model = await Discord.ApiClient.CreateGuildIntegration(Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateGuildIntegrationAsync(Id, args).ConfigureAwait(false); | |||
| return new GuildIntegration(this, model); | |||
| } | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvites() | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync() | |||
| { | |||
| var models = await Discord.ApiClient.GetGuildInvites(Id).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildInvitesAsync(Id).ConfigureAwait(false); | |||
| return models.Select(x => new InviteMetadata(Discord, x)).ToImmutableArray(); | |||
| } | |||
| public async Task<IInviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
| public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
| { | |||
| if (maxAge <= 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); | |||
| if (maxUses <= 0) throw new ArgumentOutOfRangeException(nameof(maxUses)); | |||
| @@ -222,7 +222,7 @@ namespace Discord | |||
| Temporary = isTemporary, | |||
| XkcdPass = withXkcd | |||
| }; | |||
| var model = await Discord.ApiClient.CreateChannelInvite(DefaultChannelId, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateChannelInviteAsync(DefaultChannelId, args).ConfigureAwait(false); | |||
| return new InviteMetadata(Discord, model); | |||
| } | |||
| @@ -233,14 +233,14 @@ namespace Discord | |||
| return result; | |||
| return null; | |||
| } | |||
| public async Task<IRole> CreateRole(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false) | |||
| public async Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| var model = await Discord.ApiClient.CreateGuildRole(Id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateGuildRoleAsync(Id).ConfigureAwait(false); | |||
| var role = new Role(this, model); | |||
| await role.Modify(x => | |||
| await role.ModifyAsync(x => | |||
| { | |||
| x.Name = name; | |||
| x.Permissions = (permissions ?? role.Permissions).RawValue; | |||
| @@ -251,38 +251,38 @@ namespace Discord | |||
| return role; | |||
| } | |||
| public virtual async Task<IGuildUser> GetUser(ulong id) | |||
| public virtual async Task<IGuildUser> GetUserAsync(ulong id) | |||
| { | |||
| var model = await Discord.ApiClient.GetGuildMember(Id, id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetGuildMemberAsync(Id, id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new GuildUser(this, new User(Discord, model.User), model); | |||
| return null; | |||
| } | |||
| public virtual async Task<IGuildUser> GetCurrentUser() | |||
| public virtual async Task<IGuildUser> GetCurrentUserAsync() | |||
| { | |||
| var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); | |||
| return await GetUser(currentUser.Id).ConfigureAwait(false); | |||
| var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); | |||
| return await GetUserAsync(currentUser.Id).ConfigureAwait(false); | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsers() | |||
| public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() | |||
| { | |||
| var args = new GetGuildMembersParams(); | |||
| var models = await Discord.ApiClient.GetGuildMembers(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); | |||
| } | |||
| public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| { | |||
| var args = new GetGuildMembersParams { Limit = limit, Offset = offset }; | |||
| var models = await Discord.ApiClient.GetGuildMembers(Id, args).ConfigureAwait(false); | |||
| var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | |||
| return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); | |||
| } | |||
| public async Task<int> PruneUsers(int days = 30, bool simulate = false) | |||
| public async Task<int> PruneUsersAsync(int days = 30, bool simulate = false) | |||
| { | |||
| var args = new GuildPruneParams() { Days = days }; | |||
| GetGuildPruneCountResponse model; | |||
| if (simulate) | |||
| model = await Discord.ApiClient.GetGuildPruneCount(Id, args).ConfigureAwait(false); | |||
| model = await Discord.ApiClient.GetGuildPruneCountAsync(Id, args).ConfigureAwait(false); | |||
| else | |||
| model = await Discord.ApiClient.BeginGuildPrune(Id, args).ConfigureAwait(false); | |||
| model = await Discord.ApiClient.BeginGuildPruneAsync(Id, args).ConfigureAwait(false); | |||
| return model.Pruned; | |||
| } | |||
| @@ -306,7 +306,7 @@ namespace Discord | |||
| IRole IGuild.EveryoneRole => EveryoneRole; | |||
| IReadOnlyCollection<Emoji> IGuild.Emojis => Emojis; | |||
| IReadOnlyCollection<string> IGuild.Features => Features; | |||
| Task IGuild.DownloadUsers() { throw new NotSupportedException(); } | |||
| Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } | |||
| IRole IGuild.GetRole(ulong id) => GetRole(id); | |||
| } | |||
| @@ -47,23 +47,23 @@ namespace Discord | |||
| User = new User(Discord, model.User); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteGuildIntegration(Guild.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteGuildIntegrationAsync(Guild.Id, Id).ConfigureAwait(false); | |||
| } | |||
| public async Task Modify(Action<ModifyGuildIntegrationParams> func) | |||
| public async Task ModifyAsync(Action<ModifyGuildIntegrationParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildIntegrationParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyGuildIntegration(Guild.Id, Id, args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifyGuildIntegrationAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Sync() | |||
| public async Task SyncAsync() | |||
| { | |||
| await Discord.ApiClient.SyncGuildIntegration(Guild.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.SyncGuildIntegrationAsync(Guild.Id, Id).ConfigureAwait(false); | |||
| } | |||
| public override string ToString() => Name; | |||
| @@ -40,59 +40,59 @@ namespace Discord | |||
| IReadOnlyCollection<IRole> Roles { get; } | |||
| /// <summary> Modifies this guild. </summary> | |||
| Task Modify(Action<ModifyGuildParams> func); | |||
| Task ModifyAsync(Action<ModifyGuildParams> func); | |||
| /// <summary> Modifies this guild's embed. </summary> | |||
| Task ModifyEmbed(Action<ModifyGuildEmbedParams> func); | |||
| Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func); | |||
| /// <summary> Bulk modifies the channels of this guild. </summary> | |||
| Task ModifyChannels(IEnumerable<ModifyGuildChannelsParams> args); | |||
| Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args); | |||
| /// <summary> Bulk modifies the roles of this guild. </summary> | |||
| Task ModifyRoles(IEnumerable<ModifyGuildRolesParams> args); | |||
| Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args); | |||
| /// <summary> Leaves this guild. If you are the owner, use Delete instead. </summary> | |||
| Task Leave(); | |||
| Task LeaveAsync(); | |||
| /// <summary> Gets a collection of all users banned on this guild. </summary> | |||
| Task<IReadOnlyCollection<IUser>> GetBans(); | |||
| Task<IReadOnlyCollection<IUser>> GetBansAsync(); | |||
| /// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary> | |||
| Task AddBan(IUser user, int pruneDays = 0); | |||
| Task AddBanAsync(IUser user, int pruneDays = 0); | |||
| /// <summary> Bans the provided user id from this guild and optionally prunes their recent messages. </summary> | |||
| Task AddBan(ulong userId, int pruneDays = 0); | |||
| Task AddBanAsync(ulong userId, int pruneDays = 0); | |||
| /// <summary> Unbans the provided user if it is currently banned. </summary> | |||
| Task RemoveBan(IUser user); | |||
| Task RemoveBanAsync(IUser user); | |||
| /// <summary> Unbans the provided user id if it is currently banned. </summary> | |||
| Task RemoveBan(ulong userId); | |||
| Task RemoveBanAsync(ulong userId); | |||
| /// <summary> Gets a collection of all channels in this guild. </summary> | |||
| Task<IReadOnlyCollection<IGuildChannel>> GetChannels(); | |||
| Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync(); | |||
| /// <summary> Gets the channel in this guild with the provided id, or null if not found. </summary> | |||
| Task<IGuildChannel> GetChannel(ulong id); | |||
| Task<IGuildChannel> GetChannelAsync(ulong id); | |||
| /// <summary> Creates a new text channel. </summary> | |||
| Task<ITextChannel> CreateTextChannel(string name); | |||
| Task<ITextChannel> CreateTextChannelAsync(string name); | |||
| /// <summary> Creates a new voice channel. </summary> | |||
| Task<IVoiceChannel> CreateVoiceChannel(string name); | |||
| Task<IVoiceChannel> CreateVoiceChannelAsync(string name); | |||
| /// <summary> Gets a collection of all invites to this guild. </summary> | |||
| Task<IReadOnlyCollection<IInviteMetadata>> GetInvites(); | |||
| Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(); | |||
| /// <summary> Creates a new invite to this guild. </summary> | |||
| /// <param name="maxAge"> The time (in seconds) until the invite expires. Set to null to never expire. </param> | |||
| /// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
| /// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
| /// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
| Task<IInviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
| Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
| /// <summary> Gets the role in this guild with the provided id, or null if not found. </summary> | |||
| IRole GetRole(ulong id); | |||
| /// <summary> Creates a new role. </summary> | |||
| Task<IRole> CreateRole(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false); | |||
| Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false); | |||
| /// <summary> Gets a collection of all users in this guild. </summary> | |||
| Task<IReadOnlyCollection<IGuildUser>> GetUsers(); | |||
| Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(); | |||
| /// <summary> Gets the user in this guild with the provided id, or null if not found. </summary> | |||
| Task<IGuildUser> GetUser(ulong id); | |||
| Task<IGuildUser> GetUserAsync(ulong id); | |||
| /// <summary> Gets the current user for this guild. </summary> | |||
| Task<IGuildUser> GetCurrentUser(); | |||
| Task<IGuildUser> GetCurrentUserAsync(); | |||
| /// <summary> Downloads all users for this guild if the current list is incomplete. </summary> | |||
| Task DownloadUsers(); | |||
| Task DownloadUsersAsync(); | |||
| /// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary> | |||
| Task<int> PruneUsers(int days = 30, bool simulate = false); | |||
| Task<int> PruneUsersAsync(int days = 30, bool simulate = false); | |||
| } | |||
| } | |||
| @@ -33,13 +33,13 @@ namespace Discord | |||
| Permissions = new GuildPermissions(model.Permissions); | |||
| } | |||
| public async Task Leave() | |||
| public async Task LeaveAsync() | |||
| { | |||
| await Discord.ApiClient.LeaveGuild(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteGuild(Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); | |||
| } | |||
| public override string ToString() => Name; | |||
| @@ -5,6 +5,6 @@ namespace Discord | |||
| public interface IDeletable | |||
| { | |||
| /// <summary> Deletes this object and all its children. </summary> | |||
| Task Delete(); | |||
| Task DeleteAsync(); | |||
| } | |||
| } | |||
| @@ -5,6 +5,6 @@ namespace Discord | |||
| public interface IUpdateable | |||
| { | |||
| /// <summary> Updates this object's properties with its current state. </summary> | |||
| Task Update(); | |||
| Task UpdateAsync(); | |||
| } | |||
| } | |||
| @@ -19,6 +19,6 @@ namespace Discord | |||
| ulong GuildId { get; } | |||
| /// <summary> Accepts this invite and joins the target guild. This will fail on bot accounts. </summary> | |||
| Task Accept(); | |||
| Task AcceptAsync(); | |||
| } | |||
| } | |||
| @@ -37,13 +37,13 @@ namespace Discord | |||
| ChannelName = model.Channel.Name; | |||
| } | |||
| public async Task Accept() | |||
| public async Task AcceptAsync() | |||
| { | |||
| await Discord.ApiClient.AcceptInvite(Code).ConfigureAwait(false); | |||
| await Discord.ApiClient.AcceptInviteAsync(Code).ConfigureAwait(false); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteInvite(Code).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteInviteAsync(Code).ConfigureAwait(false); | |||
| } | |||
| public override string ToString() => XkcdUrl ?? Url; | |||
| @@ -34,6 +34,6 @@ namespace Discord | |||
| IReadOnlyCollection<IUser> MentionedUsers { get; } | |||
| /// <summary> Modifies this message. </summary> | |||
| Task Modify(Action<ModifyMessageParams> func); | |||
| Task ModifyAsync(Action<ModifyMessageParams> func); | |||
| } | |||
| } | |||
| @@ -97,14 +97,14 @@ namespace Discord | |||
| Text = MentionUtils.CleanUserMentions(model.Content, model.Mentions); | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var model = await Discord.ApiClient.GetChannelMessage(Channel.Id, Id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetChannelMessageAsync(Channel.Id, Id).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyMessageParams> func) | |||
| public async Task ModifyAsync(Action<ModifyMessageParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| @@ -114,18 +114,18 @@ namespace Discord | |||
| Model model; | |||
| if (guildChannel != null) | |||
| model = await Discord.ApiClient.ModifyMessage(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false); | |||
| model = await Discord.ApiClient.ModifyMessageAsync(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false); | |||
| else | |||
| model = await Discord.ApiClient.ModifyDMMessage(Channel.Id, Id, args).ConfigureAwait(false); | |||
| model = await Discord.ApiClient.ModifyDMMessageAsync(Channel.Id, Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| var guildChannel = Channel as GuildChannel; | |||
| if (guildChannel != null) | |||
| await Discord.ApiClient.DeleteMessage(guildChannel.Id, Channel.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteMessageAsync(guildChannel.Id, Channel.Id, Id).ConfigureAwait(false); | |||
| else | |||
| await Discord.ApiClient.DeleteDMMessage(Channel.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteDMMessageAsync(Channel.Id, Id).ConfigureAwait(false); | |||
| } | |||
| public override string ToString() => Text; | |||
| @@ -24,6 +24,6 @@ namespace Discord | |||
| ulong GuildId { get; } | |||
| /// <summary> Modifies this role. </summary> | |||
| Task Modify(Action<ModifyGuildRoleParams> func); | |||
| Task ModifyAsync(Action<ModifyGuildRoleParams> func); | |||
| } | |||
| } | |||
| @@ -44,18 +44,18 @@ namespace Discord | |||
| Permissions = new GuildPermissions(model.Permissions.Value); | |||
| } | |||
| public async Task Modify(Action<ModifyGuildRoleParams> func) | |||
| public async Task ModifyAsync(Action<ModifyGuildRoleParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildRoleParams(); | |||
| func(args); | |||
| var response = await Discord.ApiClient.ModifyGuildRole(Guild.Id, Id, args).ConfigureAwait(false); | |||
| var response = await Discord.ApiClient.ModifyGuildRoleAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| Update(response, UpdateSource.Rest); | |||
| } | |||
| public async Task Delete() | |||
| public async Task DeleteAsync() | |||
| { | |||
| await Discord.ApiClient.DeleteGuildRole(Guild.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.DeleteGuildRoleAsync(Guild.Id, Id).ConfigureAwait(false); | |||
| } | |||
| public Role Clone() => MemberwiseClone() as Role; | |||
| @@ -67,31 +67,31 @@ namespace Discord | |||
| IsMute = model.Mute; | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var model = await Discord.ApiClient.GetGuildMember(Guild.Id, Id).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetGuildMemberAsync(Guild.Id, Id).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyGuildMemberParams> func) | |||
| public async Task ModifyAsync(Action<ModifyGuildMemberParams> func) | |||
| { | |||
| if (func == null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyGuildMemberParams(); | |||
| func(args); | |||
| bool isCurrentUser = (await Discord.GetCurrentUser().ConfigureAwait(false)).Id == Id; | |||
| bool isCurrentUser = (await Discord.GetCurrentUserAsync().ConfigureAwait(false)).Id == Id; | |||
| if (isCurrentUser && args.Nickname.IsSpecified) | |||
| { | |||
| var nickArgs = new ModifyCurrentUserNickParams { Nickname = args.Nickname.Value ?? "" }; | |||
| await Discord.ApiClient.ModifyCurrentUserNick(Guild.Id, nickArgs).ConfigureAwait(false); | |||
| await Discord.ApiClient.ModifyMyNickAsync(Guild.Id, nickArgs).ConfigureAwait(false); | |||
| args.Nickname = new Optional<string>(); //Remove | |||
| } | |||
| if (!isCurrentUser || args.Deaf.IsSpecified || args.Mute.IsSpecified || args.Roles.IsSpecified) | |||
| { | |||
| await Discord.ApiClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false); | |||
| await Discord.ApiClient.ModifyGuildMemberAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| if (args.Deaf.IsSpecified) | |||
| IsDeaf = args.Deaf.Value; | |||
| if (args.Mute.IsSpecified) | |||
| @@ -102,9 +102,9 @@ namespace Discord | |||
| Roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray(); | |||
| } | |||
| } | |||
| public async Task Kick() | |||
| public async Task KickAsync() | |||
| { | |||
| await Discord.ApiClient.RemoveGuildMember(Guild.Id, Id).ConfigureAwait(false); | |||
| await Discord.ApiClient.RemoveGuildMemberAsync(Guild.Id, Id).ConfigureAwait(false); | |||
| } | |||
| public ChannelPermissions GetPermissions(IGuildChannel channel) | |||
| @@ -113,7 +113,7 @@ namespace Discord | |||
| return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue)); | |||
| } | |||
| public Task<IDMChannel> CreateDMChannel() => User.CreateDMChannel(); | |||
| public Task<IDMChannel> CreateDMChannelAsync() => User.CreateDMChannelAsync(); | |||
| IGuild IGuildUser.Guild => Guild; | |||
| IReadOnlyCollection<IRole> IGuildUser.Roles => Roles; | |||
| @@ -28,8 +28,8 @@ namespace Discord | |||
| ChannelPermissions GetPermissions(IGuildChannel channel); | |||
| /// <summary> Kicks this user from this guild. </summary> | |||
| Task Kick(); | |||
| Task KickAsync(); | |||
| /// <summary> Modifies this user's properties in this guild. </summary> | |||
| Task Modify(Action<ModifyGuildMemberParams> func); | |||
| Task ModifyAsync(Action<ModifyGuildMemberParams> func); | |||
| } | |||
| } | |||
| @@ -11,6 +11,6 @@ namespace Discord | |||
| /// <summary> Returns true if this user's email has been verified. </summary> | |||
| bool IsVerified { get; } | |||
| Task Modify(Action<ModifyCurrentUserParams> func); | |||
| Task ModifyAsync(Action<ModifyCurrentUserParams> func); | |||
| } | |||
| } | |||
| @@ -15,6 +15,6 @@ namespace Discord | |||
| //TODO: CreateDMChannel is a candidate to move to IGuildUser, and User made a common class, depending on next friends list update | |||
| /// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | |||
| Task<IDMChannel> CreateDMChannel(); | |||
| Task<IDMChannel> CreateDMChannelAsync(); | |||
| } | |||
| } | |||
| @@ -24,20 +24,20 @@ namespace Discord | |||
| IsVerified = model.IsVerified; | |||
| } | |||
| public async Task Update() | |||
| public async Task UpdateAsync() | |||
| { | |||
| if (IsAttached) throw new NotSupportedException(); | |||
| var model = await Discord.ApiClient.GetCurrentUser().ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.GetSelfAsync().ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| public async Task Modify(Action<ModifyCurrentUserParams> func) | |||
| public async Task ModifyAsync(Action<ModifyCurrentUserParams> func) | |||
| { | |||
| if (func != null) throw new NullReferenceException(nameof(func)); | |||
| var args = new ModifyCurrentUserParams(); | |||
| func(args); | |||
| var model = await Discord.ApiClient.ModifyCurrentUser(args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.ModifySelfAsync(args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| } | |||
| } | |||
| @@ -38,10 +38,10 @@ namespace Discord | |||
| Username = model.Username; | |||
| } | |||
| public async Task<IDMChannel> CreateDMChannel() | |||
| public async Task<IDMChannel> CreateDMChannelAsync() | |||
| { | |||
| var args = new CreateDMChannelParams { RecipientId = Id }; | |||
| var model = await Discord.ApiClient.CreateDMChannel(args).ConfigureAwait(false); | |||
| var model = await Discord.ApiClient.CreateDMChannelAsync(args).ConfigureAwait(false); | |||
| return new DMChannel(Discord, this, model); | |||
| } | |||
| @@ -21,9 +21,9 @@ namespace Discord | |||
| _messages = new MessageCache(Discord, this); | |||
| } | |||
| public override Task<IUser> GetUser(ulong id) => Task.FromResult<IUser>(GetCachedUser(id)); | |||
| public override Task<IReadOnlyCollection<IUser>> GetUsers() => Task.FromResult<IReadOnlyCollection<IUser>>(Members); | |||
| public override Task<IReadOnlyCollection<IUser>> GetUsers(int limit, int offset) | |||
| public override Task<IUser> GetUserAsync(ulong id) => Task.FromResult<IUser>(GetCachedUser(id)); | |||
| public override Task<IReadOnlyCollection<IUser>> GetUsersAsync() => Task.FromResult<IReadOnlyCollection<IUser>>(Members); | |||
| public override Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset) | |||
| => Task.FromResult<IReadOnlyCollection<IUser>>(Members.Skip(offset).Take(limit).ToImmutableArray()); | |||
| public ICachedUser GetCachedUser(ulong id) | |||
| { | |||
| @@ -36,17 +36,17 @@ namespace Discord | |||
| return null; | |||
| } | |||
| public override async Task<IMessage> GetMessage(ulong id) | |||
| public override async Task<IMessage> GetMessageAsync(ulong id) | |||
| { | |||
| return await _messages.Download(id).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(id).ConfigureAwait(false); | |||
| } | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessages(int limit) | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | |||
| { | |||
| return await _messages.Download(null, Direction.Before, limit).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(null, Direction.Before, limit).ConfigureAwait(false); | |||
| } | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessages(ulong fromMessageId, Direction dir, int limit) | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | |||
| { | |||
| return await _messages.Download(fromMessageId, dir, limit).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(fromMessageId, dir, limit).ConfigureAwait(false); | |||
| } | |||
| public CachedMessage AddCachedMessage(ICachedUser author, MessageModel model) | |||
| { | |||
| @@ -107,8 +107,8 @@ namespace Discord | |||
| _voiceStates = voiceStates; | |||
| } | |||
| public override Task<IGuildChannel> GetChannel(ulong id) => Task.FromResult<IGuildChannel>(GetCachedChannel(id)); | |||
| public override Task<IReadOnlyCollection<IGuildChannel>> GetChannels() => Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels); | |||
| public override Task<IGuildChannel> GetChannelAsync(ulong id) => Task.FromResult<IGuildChannel>(GetCachedChannel(id)); | |||
| public override Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync() => Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels); | |||
| public ICachedGuildChannel AddCachedChannel(ChannelModel model, ConcurrentHashSet<ulong> channels = null) | |||
| { | |||
| var channel = ToChannel(model); | |||
| @@ -182,13 +182,13 @@ namespace Discord | |||
| return null; | |||
| } | |||
| public override Task<IGuildUser> GetUser(ulong id) => Task.FromResult<IGuildUser>(GetCachedUser(id)); | |||
| public override Task<IGuildUser> GetCurrentUser() | |||
| public override Task<IGuildUser> GetUserAsync(ulong id) => Task.FromResult<IGuildUser>(GetCachedUser(id)); | |||
| public override Task<IGuildUser> GetCurrentUserAsync() | |||
| => Task.FromResult<IGuildUser>(CurrentUser); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers() | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() | |||
| => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members); | |||
| //TODO: Is there a better way of exposing pagination? | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray()); | |||
| public CachedGuildUser AddCachedUser(MemberModel model, ConcurrentDictionary<ulong, CachedGuildUser> members = null, DataStore dataStore = null) | |||
| { | |||
| @@ -213,10 +213,10 @@ namespace Discord | |||
| return member; | |||
| return null; | |||
| } | |||
| public async Task DownloadMembers() | |||
| public async Task DownloadMembersAsync() | |||
| { | |||
| if (!HasAllMembers) | |||
| await Discord.ApiClient.SendRequestMembers(new ulong[] { Id }).ConfigureAwait(false); | |||
| await Discord.ApiClient.SendRequestMembersAsync(new ulong[] { Id }).ConfigureAwait(false); | |||
| await _downloaderPromise.Task.ConfigureAwait(false); | |||
| } | |||
| public void CompleteDownloadMembers() | |||
| @@ -23,9 +23,9 @@ namespace Discord | |||
| _messages = new MessageCache(Discord, this); | |||
| } | |||
| public override Task<IGuildUser> GetUser(ulong id) => Task.FromResult<IGuildUser>(GetCachedUser(id)); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers() => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public override Task<IGuildUser> GetUserAsync(ulong id) => Task.FromResult<IGuildUser>(GetCachedUser(id)); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.Skip(offset).Take(limit).ToImmutableArray()); | |||
| public CachedGuildUser GetCachedUser(ulong id) | |||
| { | |||
| @@ -35,17 +35,17 @@ namespace Discord | |||
| return null; | |||
| } | |||
| public override async Task<IMessage> GetMessage(ulong id) | |||
| public override async Task<IMessage> GetMessageAsync(ulong id) | |||
| { | |||
| return await _messages.Download(id).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(id).ConfigureAwait(false); | |||
| } | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessages(int limit = DiscordConfig.MaxMessagesPerBatch) | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||
| { | |||
| return await _messages.Download(null, Direction.Before, limit).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(null, Direction.Before, limit).ConfigureAwait(false); | |||
| } | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||
| public override async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||
| { | |||
| return await _messages.Download(fromMessageId, dir, limit).ConfigureAwait(false); | |||
| return await _messages.DownloadAsync(fromMessageId, dir, limit).ConfigureAwait(false); | |||
| } | |||
| public CachedMessage AddCachedMessage(ICachedUser author, MessageModel model) | |||
| @@ -19,11 +19,11 @@ namespace Discord | |||
| { | |||
| } | |||
| public override Task<IGuildUser> GetUser(ulong id) | |||
| public override Task<IGuildUser> GetUserAsync(ulong id) | |||
| => Task.FromResult(GetCachedUser(id)); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers() | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() | |||
| => Task.FromResult(Members); | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsers(int limit, int offset) | |||
| public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | |||
| => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray()); | |||
| public IGuildUser GetCachedUser(ulong id) | |||
| { | |||
| @@ -5,9 +5,9 @@ namespace Discord.Extensions | |||
| { | |||
| public static class DiscordClientExtensions | |||
| { | |||
| public static async Task<IVoiceRegion> GetOptimalVoiceRegion(this DiscordClient discord) | |||
| public static async Task<IVoiceRegion> GetOptimalVoiceRegionAsync(this DiscordClient discord) | |||
| { | |||
| var regions = await discord.GetVoiceRegions().ConfigureAwait(false); | |||
| var regions = await discord.GetVoiceRegionsAsync().ConfigureAwait(false); | |||
| return regions.FirstOrDefault(x => x.IsOptimal); | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ namespace Discord.Extensions | |||
| { | |||
| //TODO: Optimize these for if there is only 1 subscriber (can we do this?) | |||
| //TODO: Could we maintain our own list instead of generating one on every invocation? | |||
| public static async Task Raise(this Func<Task> eventHandler) | |||
| public static async Task RaiseAsync(this Func<Task> eventHandler) | |||
| { | |||
| var subscriptions = eventHandler?.GetInvocationList(); | |||
| if (subscriptions != null) | |||
| @@ -16,7 +16,7 @@ namespace Discord.Extensions | |||
| await (subscriptions[i] as Func<Task>).Invoke().ConfigureAwait(false); | |||
| } | |||
| } | |||
| public static async Task Raise<T>(this Func<T, Task> eventHandler, T arg) | |||
| public static async Task RaiseAsync<T>(this Func<T, Task> eventHandler, T arg) | |||
| { | |||
| var subscriptions = eventHandler?.GetInvocationList(); | |||
| if (subscriptions != null) | |||
| @@ -25,7 +25,7 @@ namespace Discord.Extensions | |||
| await (subscriptions[i] as Func<T, Task>).Invoke(arg).ConfigureAwait(false); | |||
| } | |||
| } | |||
| public static async Task Raise<T1, T2>(this Func<T1, T2, Task> eventHandler, T1 arg1, T2 arg2) | |||
| public static async Task RaiseAsync<T1, T2>(this Func<T1, T2, Task> eventHandler, T1 arg1, T2 arg2) | |||
| { | |||
| var subscriptions = eventHandler?.GetInvocationList(); | |||
| if (subscriptions != null) | |||
| @@ -34,7 +34,7 @@ namespace Discord.Extensions | |||
| await (subscriptions[i] as Func<T1, T2, Task>).Invoke(arg1, arg2).ConfigureAwait(false); | |||
| } | |||
| } | |||
| public static async Task Raise<T1, T2, T3>(this Func<T1, T2, T3, Task> eventHandler, T1 arg1, T2 arg2, T3 arg3) | |||
| public static async Task RaiseAsync<T1, T2, T3>(this Func<T1, T2, T3, Task> eventHandler, T1 arg1, T2 arg2, T3 arg3) | |||
| { | |||
| var subscriptions = eventHandler?.GetInvocationList(); | |||
| if (subscriptions != null) | |||
| @@ -43,7 +43,7 @@ namespace Discord.Extensions | |||
| await (subscriptions[i] as Func<T1, T2, T3, Task>).Invoke(arg1, arg2, arg3).ConfigureAwait(false); | |||
| } | |||
| } | |||
| public static async Task Raise<T1, T2, T3, T4>(this Func<T1, T2, T3, T4, Task> eventHandler, T1 arg1, T2 arg2, T3 arg3, T4 arg4) | |||
| public static async Task RaiseAsync<T1, T2, T3, T4>(this Func<T1, T2, T3, T4, Task> eventHandler, T1 arg1, T2 arg2, T3 arg3, T4 arg4) | |||
| { | |||
| var subscriptions = eventHandler?.GetInvocationList(); | |||
| if (subscriptions != null) | |||
| @@ -4,9 +4,9 @@ namespace Discord.Extensions | |||
| { | |||
| public static class GuildExtensions | |||
| { | |||
| public static async Task<ITextChannel> GetTextChannel(this IGuild guild, ulong id) | |||
| => await guild.GetChannel(id).ConfigureAwait(false) as ITextChannel; | |||
| public static async Task<IVoiceChannel> GetVoiceChannel(this IGuild guild, ulong id) | |||
| => await guild.GetChannel(id).ConfigureAwait(false) as IVoiceChannel; | |||
| public static async Task<ITextChannel> GetTextChannelAsync(this IGuild guild, ulong id) | |||
| => await guild.GetChannelAsync(id).ConfigureAwait(false) as ITextChannel; | |||
| public static async Task<IVoiceChannel> GetVoiceChannelAsync(this IGuild guild, ulong id) | |||
| => await guild.GetChannelAsync(id).ConfigureAwait(false) as IVoiceChannel; | |||
| } | |||
| } | |||
| @@ -13,29 +13,29 @@ namespace Discord | |||
| DiscordApiClient ApiClient { get; } | |||
| Task Login(TokenType tokenType, string token, bool validateToken = true); | |||
| Task Logout(); | |||
| Task LoginAsync(TokenType tokenType, string token, bool validateToken = true); | |||
| Task LogoutAsync(); | |||
| Task Connect(); | |||
| Task Disconnect(); | |||
| Task ConnectAsync(); | |||
| Task DisconnectAsync(); | |||
| Task<IChannel> GetChannel(ulong id); | |||
| Task<IReadOnlyCollection<IDMChannel>> GetDMChannels(); | |||
| Task<IChannel> GetChannelAsync(ulong id); | |||
| Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(); | |||
| Task<IReadOnlyCollection<IConnection>> GetConnections(); | |||
| Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(); | |||
| Task<IGuild> GetGuild(ulong id); | |||
| Task<IReadOnlyCollection<IUserGuild>> GetGuilds(); | |||
| Task<IGuild> CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null); | |||
| Task<IGuild> GetGuildAsync(ulong id); | |||
| Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync(); | |||
| Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null); | |||
| Task<IInvite> GetInvite(string inviteIdOrXkcd); | |||
| Task<IInvite> GetInviteAsync(string inviteIdOrXkcd); | |||
| Task<IUser> GetUser(ulong id); | |||
| Task<IUser> GetUser(string username, string discriminator); | |||
| Task<ISelfUser> GetCurrentUser(); | |||
| Task<IReadOnlyCollection<IUser>> QueryUsers(string query, int limit); | |||
| Task<IUser> GetUserAsync(ulong id); | |||
| Task<IUser> GetUserAsync(string username, string discriminator); | |||
| Task<ISelfUser> GetCurrentUserAsync(); | |||
| Task<IReadOnlyCollection<IUser>> QueryUsersAsync(string query, int limit); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegions(); | |||
| Task<IVoiceRegion> GetVoiceRegion(string id); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(); | |||
| Task<IVoiceRegion> GetVoiceRegionAsync(string id); | |||
| } | |||
| } | |||
| @@ -7,28 +7,28 @@ namespace Discord.Logging | |||
| { | |||
| LogSeverity Level { get; } | |||
| Task Log(LogSeverity severity, string message, Exception exception = null); | |||
| Task Log(LogSeverity severity, FormattableString message, Exception exception = null); | |||
| Task Log(LogSeverity severity, Exception exception); | |||
| Task LogAsync(LogSeverity severity, string message, Exception exception = null); | |||
| Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null); | |||
| Task LogAsync(LogSeverity severity, Exception exception); | |||
| Task Error(string message, Exception exception = null); | |||
| Task Error(FormattableString message, Exception exception = null); | |||
| Task Error(Exception exception); | |||
| Task ErrorAsync(string message, Exception exception = null); | |||
| Task ErrorAsync(FormattableString message, Exception exception = null); | |||
| Task ErrorAsync(Exception exception); | |||
| Task Warning(string message, Exception exception = null); | |||
| Task Warning(FormattableString message, Exception exception = null); | |||
| Task Warning(Exception exception); | |||
| Task WarningAsync(string message, Exception exception = null); | |||
| Task WarningAsync(FormattableString message, Exception exception = null); | |||
| Task WarningAsync(Exception exception); | |||
| Task Info(string message, Exception exception = null); | |||
| Task Info(FormattableString message, Exception exception = null); | |||
| Task Info(Exception exception); | |||
| Task InfoAsync(string message, Exception exception = null); | |||
| Task InfoAsync(FormattableString message, Exception exception = null); | |||
| Task InfoAsync(Exception exception); | |||
| Task Verbose(string message, Exception exception = null); | |||
| Task Verbose(FormattableString message, Exception exception = null); | |||
| Task Verbose(Exception exception); | |||
| Task VerboseAsync(string message, Exception exception = null); | |||
| Task VerboseAsync(FormattableString message, Exception exception = null); | |||
| Task VerboseAsync(Exception exception); | |||
| Task Debug(string message, Exception exception = null); | |||
| Task Debug(FormattableString message, Exception exception = null); | |||
| Task Debug(Exception exception); | |||
| Task DebugAsync(string message, Exception exception = null); | |||
| Task DebugAsync(FormattableString message, Exception exception = null); | |||
| Task DebugAsync(Exception exception); | |||
| } | |||
| } | |||
| @@ -15,101 +15,101 @@ namespace Discord.Logging | |||
| Level = minSeverity; | |||
| } | |||
| public async Task Log(LogSeverity severity, string source, string message, Exception ex = null) | |||
| public async Task LogAsync(LogSeverity severity, string source, string message, Exception ex = null) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, source, message, ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false); | |||
| } | |||
| public async Task Log(LogSeverity severity, string source, FormattableString message, Exception ex = null) | |||
| public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false); | |||
| } | |||
| public async Task Log(LogSeverity severity, string source, Exception ex) | |||
| public async Task LogAsync(LogSeverity severity, string source, Exception ex) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, source, null, ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, source, null, ex)).ConfigureAwait(false); | |||
| } | |||
| async Task ILogger.Log(LogSeverity severity, string message, Exception ex) | |||
| async Task ILogger.LogAsync(LogSeverity severity, string message, Exception ex) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, "Discord", message, ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, "Discord", message, ex)).ConfigureAwait(false); | |||
| } | |||
| async Task ILogger.Log(LogSeverity severity, FormattableString message, Exception ex) | |||
| async Task ILogger.LogAsync(LogSeverity severity, FormattableString message, Exception ex) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, "Discord", message.ToString(), ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, "Discord", message.ToString(), ex)).ConfigureAwait(false); | |||
| } | |||
| async Task ILogger.Log(LogSeverity severity, Exception ex) | |||
| async Task ILogger.LogAsync(LogSeverity severity, Exception ex) | |||
| { | |||
| if (severity <= Level) | |||
| await Message.Raise(new LogMessage(severity, "Discord", null, ex)).ConfigureAwait(false); | |||
| await Message.RaiseAsync(new LogMessage(severity, "Discord", null, ex)).ConfigureAwait(false); | |||
| } | |||
| public Task Error(string source, string message, Exception ex = null) | |||
| => Log(LogSeverity.Error, source, message, ex); | |||
| public Task Error(string source, FormattableString message, Exception ex = null) | |||
| => Log(LogSeverity.Error, source, message, ex); | |||
| public Task Error(string source, Exception ex) | |||
| => Log(LogSeverity.Error, source, ex); | |||
| Task ILogger.Error(string message, Exception ex) | |||
| => Log(LogSeverity.Error, "Discord", message, ex); | |||
| Task ILogger.Error(FormattableString message, Exception ex) | |||
| => Log(LogSeverity.Error, "Discord", message, ex); | |||
| Task ILogger.Error(Exception ex) | |||
| => Log(LogSeverity.Error, "Discord", ex); | |||
| public Task ErrorAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Error, source, message, ex); | |||
| public Task ErrorAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Error, source, message, ex); | |||
| public Task ErrorAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Error, source, ex); | |||
| Task ILogger.ErrorAsync(string message, Exception ex) | |||
| => LogAsync(LogSeverity.Error, "Discord", message, ex); | |||
| Task ILogger.ErrorAsync(FormattableString message, Exception ex) | |||
| => LogAsync(LogSeverity.Error, "Discord", message, ex); | |||
| Task ILogger.ErrorAsync(Exception ex) | |||
| => LogAsync(LogSeverity.Error, "Discord", ex); | |||
| public Task Warning(string source, string message, Exception ex = null) | |||
| => Log(LogSeverity.Warning, source, message, ex); | |||
| public Task Warning(string source, FormattableString message, Exception ex = null) | |||
| => Log(LogSeverity.Warning, source, message, ex); | |||
| public Task Warning(string source, Exception ex) | |||
| => Log(LogSeverity.Warning, source, ex); | |||
| Task ILogger.Warning(string message, Exception ex) | |||
| => Log(LogSeverity.Warning, "Discord", message, ex); | |||
| Task ILogger.Warning(FormattableString message, Exception ex) | |||
| => Log(LogSeverity.Warning, "Discord", message, ex); | |||
| Task ILogger.Warning(Exception ex) | |||
| => Log(LogSeverity.Warning, "Discord", ex); | |||
| public Task WarningAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Warning, source, message, ex); | |||
| public Task WarningAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Warning, source, message, ex); | |||
| public Task WarningAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Warning, source, ex); | |||
| Task ILogger.WarningAsync(string message, Exception ex) | |||
| => LogAsync(LogSeverity.Warning, "Discord", message, ex); | |||
| Task ILogger.WarningAsync(FormattableString message, Exception ex) | |||
| => LogAsync(LogSeverity.Warning, "Discord", message, ex); | |||
| Task ILogger.WarningAsync(Exception ex) | |||
| => LogAsync(LogSeverity.Warning, "Discord", ex); | |||
| public Task Info(string source, string message, Exception ex = null) | |||
| => Log(LogSeverity.Info, source, message, ex); | |||
| public Task Info(string source, FormattableString message, Exception ex = null) | |||
| => Log(LogSeverity.Info, source, message, ex); | |||
| public Task Info(string source, Exception ex) | |||
| => Log(LogSeverity.Info, source, ex); | |||
| Task ILogger.Info(string message, Exception ex) | |||
| => Log(LogSeverity.Info, "Discord", message, ex); | |||
| Task ILogger.Info(FormattableString message, Exception ex) | |||
| => Log(LogSeverity.Info, "Discord", message, ex); | |||
| Task ILogger.Info(Exception ex) | |||
| => Log(LogSeverity.Info, "Discord", ex); | |||
| public Task InfoAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Info, source, message, ex); | |||
| public Task InfoAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Info, source, message, ex); | |||
| public Task InfoAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Info, source, ex); | |||
| Task ILogger.InfoAsync(string message, Exception ex) | |||
| => LogAsync(LogSeverity.Info, "Discord", message, ex); | |||
| Task ILogger.InfoAsync(FormattableString message, Exception ex) | |||
| => LogAsync(LogSeverity.Info, "Discord", message, ex); | |||
| Task ILogger.InfoAsync(Exception ex) | |||
| => LogAsync(LogSeverity.Info, "Discord", ex); | |||
| public Task Verbose(string source, string message, Exception ex = null) | |||
| => Log(LogSeverity.Verbose, source, message, ex); | |||
| public Task Verbose(string source, FormattableString message, Exception ex = null) | |||
| => Log(LogSeverity.Verbose, source, message, ex); | |||
| public Task Verbose(string source, Exception ex) | |||
| => Log(LogSeverity.Verbose, source, ex); | |||
| Task ILogger.Verbose(string message, Exception ex) | |||
| => Log(LogSeverity.Verbose, "Discord", message, ex); | |||
| Task ILogger.Verbose(FormattableString message, Exception ex) | |||
| => Log(LogSeverity.Verbose, "Discord", message, ex); | |||
| Task ILogger.Verbose(Exception ex) | |||
| => Log(LogSeverity.Verbose, "Discord", ex); | |||
| public Task VerboseAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Verbose, source, message, ex); | |||
| public Task VerboseAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Verbose, source, message, ex); | |||
| public Task VerboseAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Verbose, source, ex); | |||
| Task ILogger.VerboseAsync(string message, Exception ex) | |||
| => LogAsync(LogSeverity.Verbose, "Discord", message, ex); | |||
| Task ILogger.VerboseAsync(FormattableString message, Exception ex) | |||
| => LogAsync(LogSeverity.Verbose, "Discord", message, ex); | |||
| Task ILogger.VerboseAsync(Exception ex) | |||
| => LogAsync(LogSeverity.Verbose, "Discord", ex); | |||
| public Task Debug(string source, string message, Exception ex = null) | |||
| => Log(LogSeverity.Debug, source, message, ex); | |||
| public Task Debug(string source, FormattableString message, Exception ex = null) | |||
| => Log(LogSeverity.Debug, source, message, ex); | |||
| public Task Debug(string source, Exception ex) | |||
| => Log(LogSeverity.Debug, source, ex); | |||
| Task ILogger.Debug(string message, Exception ex) | |||
| => Log(LogSeverity.Debug, "Discord", message, ex); | |||
| Task ILogger.Debug(FormattableString message, Exception ex) | |||
| => Log(LogSeverity.Debug, "Discord", message, ex); | |||
| Task ILogger.Debug(Exception ex) | |||
| => Log(LogSeverity.Debug, "Discord", ex); | |||
| public Task DebugAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Debug, source, message, ex); | |||
| public Task DebugAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Debug, source, message, ex); | |||
| public Task DebugAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Debug, source, ex); | |||
| Task ILogger.DebugAsync(string message, Exception ex) | |||
| => LogAsync(LogSeverity.Debug, "Discord", message, ex); | |||
| Task ILogger.DebugAsync(FormattableString message, Exception ex) | |||
| => LogAsync(LogSeverity.Debug, "Discord", message, ex); | |||
| Task ILogger.DebugAsync(Exception ex) | |||
| => LogAsync(LogSeverity.Debug, "Discord", ex); | |||
| public Logger CreateLogger(string name) => new Logger(this, name); | |||
| } | |||
| @@ -3,7 +3,7 @@ using System.Threading.Tasks; | |||
| namespace Discord.Logging | |||
| { | |||
| internal class Logger | |||
| internal class Logger : ILogger | |||
| { | |||
| private readonly LogManager _manager; | |||
| @@ -16,44 +16,44 @@ namespace Discord.Logging | |||
| Name = name; | |||
| } | |||
| public Task Log(LogSeverity severity, string message, Exception exception = null) | |||
| => _manager.Log(severity, Name, message, exception); | |||
| public Task Log(LogSeverity severity, FormattableString message, Exception exception = null) | |||
| => _manager.Log(severity, Name, message, exception); | |||
| public Task Error(string message, Exception exception = null) | |||
| => _manager.Error(Name, message, exception); | |||
| public Task Error(FormattableString message, Exception exception = null) | |||
| => _manager.Error(Name, message, exception); | |||
| public Task Error(Exception exception) | |||
| => _manager.Error(Name, exception); | |||
| public Task Warning(string message, Exception exception = null) | |||
| => _manager.Warning(Name, message, exception); | |||
| public Task Warning(FormattableString message, Exception exception = null) | |||
| => _manager.Warning(Name, message, exception); | |||
| public Task Warning(Exception exception) | |||
| => _manager.Warning(Name, exception); | |||
| public Task Info(string message, Exception exception = null) | |||
| => _manager.Info(Name, message, exception); | |||
| public Task Info(FormattableString message, Exception exception = null) | |||
| => _manager.Info(Name, message, exception); | |||
| public Task Info(Exception exception) | |||
| => _manager.Info(Name, exception); | |||
| public Task Verbose(string message, Exception exception = null) | |||
| => _manager.Verbose(Name, message, exception); | |||
| public Task Verbose(FormattableString message, Exception exception = null) | |||
| => _manager.Verbose(Name, message, exception); | |||
| public Task Verbose(Exception exception) | |||
| => _manager.Verbose(Name, exception); | |||
| public Task Debug(string message, Exception exception = null) | |||
| => _manager.Debug(Name, message, exception); | |||
| public Task Debug(FormattableString message, Exception exception = null) | |||
| => _manager.Debug(Name, message, exception); | |||
| public Task Debug(Exception exception) | |||
| => _manager.Debug(Name, exception); | |||
| public Task LogAsync(LogSeverity severity, string message, Exception exception = null) | |||
| => _manager.LogAsync(severity, Name, message, exception); | |||
| public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) | |||
| => _manager.LogAsync(severity, Name, message, exception); | |||
| public Task ErrorAsync(string message, Exception exception = null) | |||
| => _manager.ErrorAsync(Name, message, exception); | |||
| public Task ErrorAsync(FormattableString message, Exception exception = null) | |||
| => _manager.ErrorAsync(Name, message, exception); | |||
| public Task ErrorAsync(Exception exception) | |||
| => _manager.ErrorAsync(Name, exception); | |||
| public Task WarningAsync(string message, Exception exception = null) | |||
| => _manager.WarningAsync(Name, message, exception); | |||
| public Task WarningAsync(FormattableString message, Exception exception = null) | |||
| => _manager.WarningAsync(Name, message, exception); | |||
| public Task WarningAsync(Exception exception) | |||
| => _manager.WarningAsync(Name, exception); | |||
| public Task InfoAsync(string message, Exception exception = null) | |||
| => _manager.InfoAsync(Name, message, exception); | |||
| public Task InfoAsync(FormattableString message, Exception exception = null) | |||
| => _manager.InfoAsync(Name, message, exception); | |||
| public Task InfoAsync(Exception exception) | |||
| => _manager.InfoAsync(Name, exception); | |||
| public Task VerboseAsync(string message, Exception exception = null) | |||
| => _manager.VerboseAsync(Name, message, exception); | |||
| public Task VerboseAsync(FormattableString message, Exception exception = null) | |||
| => _manager.VerboseAsync(Name, message, exception); | |||
| public Task VerboseAsync(Exception exception) | |||
| => _manager.VerboseAsync(Name, exception); | |||
| public Task DebugAsync(string message, Exception exception = null) | |||
| => _manager.DebugAsync(Name, message, exception); | |||
| public Task DebugAsync(FormattableString message, Exception exception = null) | |||
| => _manager.DebugAsync(Name, message, exception); | |||
| public Task DebugAsync(Exception exception) | |||
| => _manager.DebugAsync(Name, exception); | |||
| } | |||
| } | |||
| @@ -11,6 +11,6 @@ namespace Discord.Net.Queue | |||
| CancellationToken CancelToken { get; } | |||
| int? TimeoutTick { get; } | |||
| Task<Stream> Send(); | |||
| Task<Stream> SendAsync(); | |||
| } | |||
| } | |||
| @@ -61,7 +61,7 @@ namespace Discord.Net.Queue | |||
| _cancelToken = CancellationToken.None; | |||
| _parentToken = CancellationToken.None; | |||
| } | |||
| public async Task SetCancelToken(CancellationToken cancelToken) | |||
| public async Task SetCancelTokenAsync(CancellationToken cancelToken) | |||
| { | |||
| await _lock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| @@ -72,17 +72,17 @@ namespace Discord.Net.Queue | |||
| finally { _lock.Release(); } | |||
| } | |||
| internal async Task<Stream> Send(RestRequest request, BucketGroup group, int bucketId, ulong guildId) | |||
| internal async Task<Stream> SendAsync(RestRequest request, BucketGroup group, int bucketId, ulong guildId) | |||
| { | |||
| request.CancelToken = _cancelToken; | |||
| var bucket = GetBucket(group, bucketId, guildId); | |||
| return await bucket.Send(request).ConfigureAwait(false); | |||
| return await bucket.SendAsync(request).ConfigureAwait(false); | |||
| } | |||
| internal async Task<Stream> Send(WebSocketRequest request, BucketGroup group, int bucketId, ulong guildId) | |||
| internal async Task<Stream> SendAsync(WebSocketRequest request, BucketGroup group, int bucketId, ulong guildId) | |||
| { | |||
| request.CancelToken = _cancelToken; | |||
| var bucket = GetBucket(group, bucketId, guildId); | |||
| return await bucket.Send(request).ConfigureAwait(false); | |||
| return await bucket.SendAsync(request).ConfigureAwait(false); | |||
| } | |||
| private RequestQueueBucket CreateBucket(BucketDefinition def) | |||
| @@ -119,7 +119,7 @@ namespace Discord.Net.Queue | |||
| return _guildBuckets[(int)type].GetOrAdd(guildId, _ => CreateBucket(_guildLimits[type])); | |||
| } | |||
| public async Task Clear() | |||
| public async Task ClearAsync() | |||
| { | |||
| await _lock.WaitAsync().ConfigureAwait(false); | |||
| try | |||
| @@ -28,13 +28,13 @@ namespace Discord.Net.Queue | |||
| Parent = parent; | |||
| } | |||
| public async Task<Stream> Send(IQueuedRequest request) | |||
| public async Task<Stream> SendAsync(IQueuedRequest request) | |||
| { | |||
| var endTick = request.TimeoutTick; | |||
| //Wait until a spot is open in our bucket | |||
| if (_semaphore != null) | |||
| await Enter(endTick).ConfigureAwait(false); | |||
| await EnterAsync(endTick).ConfigureAwait(false); | |||
| try | |||
| { | |||
| while (true) | |||
| @@ -63,10 +63,10 @@ namespace Discord.Net.Queue | |||
| { | |||
| //If there's a parent bucket, pass this request to them | |||
| if (Parent != null) | |||
| return await Parent.Send(request).ConfigureAwait(false); | |||
| return await Parent.SendAsync(request).ConfigureAwait(false); | |||
| //We have all our semaphores, send the request | |||
| return await request.Send().ConfigureAwait(false); | |||
| return await request.SendAsync().ConfigureAwait(false); | |||
| } | |||
| catch (HttpRateLimitException ex) | |||
| { | |||
| @@ -79,7 +79,7 @@ namespace Discord.Net.Queue | |||
| { | |||
| //Make sure we put this entry back after WindowMilliseconds | |||
| if (_semaphore != null) | |||
| QueueExit(); | |||
| QueueExitAsync(); | |||
| } | |||
| } | |||
| @@ -92,17 +92,17 @@ namespace Discord.Net.Queue | |||
| { | |||
| _resumeNotifier = new TaskCompletionSource<byte>(); | |||
| _pauseEndTick = unchecked(Environment.TickCount + milliseconds); | |||
| QueueResume(milliseconds); | |||
| QueueResumeAsync(milliseconds); | |||
| } | |||
| } | |||
| } | |||
| private async Task QueueResume(int millis) | |||
| private async Task QueueResumeAsync(int millis) | |||
| { | |||
| await Task.Delay(millis).ConfigureAwait(false); | |||
| _resumeNotifier.SetResult(0); | |||
| } | |||
| private async Task Enter(int? endTick) | |||
| private async Task EnterAsync(int? endTick) | |||
| { | |||
| if (endTick.HasValue) | |||
| { | |||
| @@ -113,7 +113,7 @@ namespace Discord.Net.Queue | |||
| else | |||
| await _semaphore.WaitAsync().ConfigureAwait(false); | |||
| } | |||
| private async Task QueueExit() | |||
| private async Task QueueExitAsync() | |||
| { | |||
| await Task.Delay(_windowMilliseconds).ConfigureAwait(false); | |||
| _semaphore.Release(); | |||
| @@ -47,14 +47,14 @@ namespace Discord.Net.Queue | |||
| Promise = new TaskCompletionSource<Stream>(); | |||
| } | |||
| public async Task<Stream> Send() | |||
| public async Task<Stream> SendAsync() | |||
| { | |||
| if (IsMultipart) | |||
| return await Client.Send(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false); | |||
| return await Client.SendAsync(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false); | |||
| else if (Json != null) | |||
| return await Client.Send(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false); | |||
| return await Client.SendAsync(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false); | |||
| else | |||
| return await Client.Send(Method, Endpoint, HeaderOnly).ConfigureAwait(false); | |||
| return await Client.SendAsync(Method, Endpoint, HeaderOnly).ConfigureAwait(false); | |||
| } | |||
| } | |||
| } | |||
| @@ -32,9 +32,9 @@ namespace Discord.Net.Queue | |||
| Promise = new TaskCompletionSource<Stream>(); | |||
| } | |||
| public async Task<Stream> Send() | |||
| public async Task<Stream> SendAsync() | |||
| { | |||
| await Client.Send(Data, DataIndex, DataCount, IsText).ConfigureAwait(false); | |||
| await Client.SendAsync(Data, DataIndex, DataCount, IsText).ConfigureAwait(false); | |||
| return null; | |||
| } | |||
| } | |||
| @@ -67,22 +67,22 @@ namespace Discord.Net.Rest | |||
| _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; | |||
| } | |||
| public async Task<Stream> Send(string method, string endpoint, bool headerOnly = false) | |||
| public async Task<Stream> SendAsync(string method, string endpoint, bool headerOnly = false) | |||
| { | |||
| string uri = Path.Combine(_baseUrl, endpoint); | |||
| using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | |||
| return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); | |||
| return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); | |||
| } | |||
| public async Task<Stream> Send(string method, string endpoint, string json, bool headerOnly = false) | |||
| public async Task<Stream> SendAsync(string method, string endpoint, string json, bool headerOnly = false) | |||
| { | |||
| string uri = Path.Combine(_baseUrl, endpoint); | |||
| using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | |||
| { | |||
| restRequest.Content = new StringContent(json, Encoding.UTF8, "application/json"); | |||
| return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); | |||
| return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); | |||
| } | |||
| } | |||
| public async Task<Stream> Send(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false) | |||
| public async Task<Stream> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false) | |||
| { | |||
| string uri = Path.Combine(_baseUrl, endpoint); | |||
| using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | |||
| @@ -110,11 +110,11 @@ namespace Discord.Net.Rest | |||
| } | |||
| } | |||
| restRequest.Content = content; | |||
| return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); | |||
| return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); | |||
| } | |||
| } | |||
| private async Task<Stream> SendInternal(HttpRequestMessage request, bool headerOnly) | |||
| private async Task<Stream> SendInternalAsync(HttpRequestMessage request, bool headerOnly) | |||
| { | |||
| while (true) | |||
| { | |||
| @@ -11,8 +11,8 @@ namespace Discord.Net.Rest | |||
| void SetHeader(string key, string value); | |||
| void SetCancelToken(CancellationToken cancelToken); | |||
| Task<Stream> Send(string method, string endpoint, bool headerOnly = false); | |||
| Task<Stream> Send(string method, string endpoint, string json, bool headerOnly = false); | |||
| Task<Stream> Send(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false); | |||
| Task<Stream> SendAsync(string method, string endpoint, bool headerOnly = false); | |||
| Task<Stream> SendAsync(string method, string endpoint, string json, bool headerOnly = false); | |||
| Task<Stream> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false); | |||
| } | |||
| } | |||
| @@ -50,18 +50,18 @@ namespace Discord.Net.WebSockets | |||
| Dispose(true); | |||
| } | |||
| public async Task Connect(string host) | |||
| public async Task ConnectAsync(string host) | |||
| { | |||
| //Assume locked | |||
| await Disconnect().ConfigureAwait(false); | |||
| await DisconnectAsync().ConfigureAwait(false); | |||
| _cancelTokenSource = new CancellationTokenSource(); | |||
| _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; | |||
| await _client.ConnectAsync(new Uri(host), _cancelToken).ConfigureAwait(false); | |||
| _task = Run(_cancelToken); | |||
| _task = RunAsync(_cancelToken); | |||
| } | |||
| public async Task Disconnect() | |||
| public async Task DisconnectAsync() | |||
| { | |||
| //Assume locked | |||
| _cancelTokenSource.Cancel(); | |||
| @@ -82,7 +82,7 @@ namespace Discord.Net.WebSockets | |||
| _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; | |||
| } | |||
| public async Task Send(byte[] data, int index, int count, bool isText) | |||
| public async Task SendAsync(byte[] data, int index, int count, bool isText) | |||
| { | |||
| await _sendLock.WaitAsync(_cancelToken); | |||
| try | |||
| @@ -118,7 +118,7 @@ namespace Discord.Net.WebSockets | |||
| } | |||
| //TODO: Check this code | |||
| private async Task Run(CancellationToken cancelToken) | |||
| private async Task RunAsync(CancellationToken cancelToken) | |||
| { | |||
| var buffer = new ArraySegment<byte>(new byte[ReceiveChunkSize]); | |||
| var stream = new MemoryStream(); | |||
| @@ -151,11 +151,11 @@ namespace Discord.Net.WebSockets | |||
| var array = stream.ToArray(); | |||
| if (result.MessageType == WebSocketMessageType.Binary) | |||
| await BinaryMessage.Raise(array, 0, array.Length).ConfigureAwait(false); | |||
| await BinaryMessage.RaiseAsync(array, 0, array.Length).ConfigureAwait(false); | |||
| else if (result.MessageType == WebSocketMessageType.Text) | |||
| { | |||
| string text = Encoding.UTF8.GetString(array, 0, array.Length); | |||
| await TextMessage.Raise(text).ConfigureAwait(false); | |||
| await TextMessage.RaiseAsync(text).ConfigureAwait(false); | |||
| } | |||
| stream.Position = 0; | |||
| @@ -12,9 +12,9 @@ namespace Discord.Net.WebSockets | |||
| void SetHeader(string key, string value); | |||
| void SetCancelToken(CancellationToken cancelToken); | |||
| Task Connect(string host); | |||
| Task Disconnect(); | |||
| Task ConnectAsync(string host); | |||
| Task DisconnectAsync(); | |||
| Task Send(byte[] data, int index, int count, bool isText); | |||
| Task SendAsync(byte[] data, int index, int count, bool isText); | |||
| } | |||
| } | |||
| @@ -81,17 +81,17 @@ namespace Discord | |||
| .ToImmutableArray(); | |||
| } | |||
| public async Task<CachedMessage> Download(ulong id) | |||
| public async Task<CachedMessage> DownloadAsync(ulong id) | |||
| { | |||
| var msg = Get(id); | |||
| if (msg != null) | |||
| return msg; | |||
| var model = await _discord.ApiClient.GetChannelMessage(_channel.Id, id).ConfigureAwait(false); | |||
| var model = await _discord.ApiClient.GetChannelMessageAsync(_channel.Id, id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new CachedMessage(_channel, new User(_discord, model.Author), model); | |||
| return null; | |||
| } | |||
| public async Task<IReadOnlyCollection<CachedMessage>> Download(ulong? fromId, Direction dir, int limit) | |||
| public async Task<IReadOnlyCollection<CachedMessage>> DownloadAsync(ulong? fromId, Direction dir, int limit) | |||
| { | |||
| //TODO: Test heavily, especially the ordering of messages | |||
| if (limit < 0) throw new ArgumentOutOfRangeException(nameof(limit)); | |||
| @@ -110,7 +110,7 @@ namespace Discord | |||
| RelativeDirection = dir, | |||
| RelativeMessageId = dir == Direction.Before ? cachedMessages[0].Id : cachedMessages[cachedMessages.Count - 1].Id | |||
| }; | |||
| var downloadedMessages = await _discord.ApiClient.GetChannelMessages(_channel.Id, args).ConfigureAwait(false); | |||
| var downloadedMessages = await _discord.ApiClient.GetChannelMessagesAsync(_channel.Id, args).ConfigureAwait(false); | |||
| return cachedMessages.Concat(downloadedMessages.Select(x => new CachedMessage(_channel, _channel.GetCachedUser(x.Id), x))).ToImmutableArray(); | |||
| } | |||
| } | |||