Browse Source

Style cleanup

tags/1.0
RogueException 7 years ago
parent
commit
14dfc48df3
6 changed files with 35 additions and 36 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Builders/CommandBuilder.cs
  2. +1
    -1
      src/Discord.Net.Commands/Builders/ModuleBuilder.cs
  3. +1
    -1
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  4. +2
    -2
      src/Discord.Net.Commands/Info/CommandInfo.cs
  5. +5
    -5
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  6. +25
    -26
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 1
- 1
src/Discord.Net.Commands/Builders/CommandBuilder.cs View File

@@ -80,7 +80,7 @@ namespace Discord.Commands.Builders
{
for (int i = 0; i < aliases.Length; i++)
{
var alias = aliases[i] ?? "";
string alias = aliases[i] ?? "";
if (!_aliases.Contains(alias))
_aliases.Add(alias);
}


+ 1
- 1
src/Discord.Net.Commands/Builders/ModuleBuilder.cs View File

@@ -66,7 +66,7 @@ namespace Discord.Commands.Builders
{
for (int i = 0; i < aliases.Length; i++)
{
var alias = aliases[i] ?? "";
string alias = aliases[i] ?? "";
if (!_aliases.Contains(alias))
_aliases.Add(alias);
}


+ 1
- 1
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -20,7 +20,7 @@ namespace Discord.Commands
info.GetCustomAttribute<DontAutoLoadAttribute>() == null;
}

List<TypeInfo> result = new List<TypeInfo>();
var result = new List<TypeInfo>();

foreach (var typeInfo in assembly.DefinedTypes)
{


+ 2
- 2
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -154,7 +154,7 @@ namespace Discord.Commands
for (int position = 0; position < Parameters.Count; position++)
{
var parameter = Parameters[position];
var argument = args[position];
object argument = args[position];
var result = await parameter.CheckPreconditionsAsync(context, argument, services).ConfigureAwait(false);
if (!result.IsSuccess)
return ExecuteResult.FromError(result);
@@ -232,7 +232,7 @@ namespace Discord.Commands
argCount--;

int i = 0;
foreach (var arg in argList)
foreach (object arg in argList)
{
if (i == argCount)
throw new InvalidOperationException("Command was invoked with too many parameters");


+ 5
- 5
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -30,7 +30,7 @@ namespace Discord.API

protected readonly JsonSerializer _serializer;
protected readonly SemaphoreSlim _stateLock;
private readonly RestClientProvider RestClientProvider;
private readonly RestClientProvider _restClientProvider;

protected bool _isDisposed;
private CancellationTokenSource _loginCancelToken;
@@ -48,7 +48,7 @@ namespace Discord.API
public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry,
JsonSerializer serializer = null)
{
RestClientProvider = restClientProvider;
_restClientProvider = restClientProvider;
UserAgent = userAgent;
DefaultRetryMode = defaultRetryMode;
_serializer = serializer ?? new JsonSerializer { DateFormatString = "yyyy-MM-ddTHH:mm:ssZ", ContractResolver = new DiscordContractResolver() };
@@ -60,7 +60,7 @@ namespace Discord.API
}
internal void SetBaseUrl(string baseUrl)
{
RestClient = RestClientProvider(baseUrl);
RestClient = _restClientProvider(baseUrl);
RestClient.SetHeader("accept", "*/*");
RestClient.SetHeader("user-agent", UserAgent);
RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken));
@@ -189,7 +189,7 @@ namespace Discord.API
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var json = payload != null ? SerializeJson(payload) : null;
string json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(RestClient, method, endpoint, json, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
}
@@ -233,7 +233,7 @@ namespace Discord.API
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var json = payload != null ? SerializeJson(payload) : null;
string json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(RestClient, method, endpoint, json, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));
}


+ 25
- 26
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -34,7 +34,7 @@ namespace Discord.WebSocket
private int _lastSeq;
private ImmutableDictionary<string, RestVoiceRegion> _voiceRegions;
private Task _heartbeatTask, _guildDownloadTask;
private int _unavailableGuilds;
private int _unavailableGuildCount;
private long _lastGuildAvailableTime, _lastMessageTime;
private int _nextAudioId;
private DateTimeOffset? _statusSince;
@@ -60,7 +60,7 @@ namespace Discord.WebSocket
internal int? HandlerTimeout { get; private set; }

internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient;
public new SocketSelfUser CurrentUser { get { return base.CurrentUser as SocketSelfUser; } private set { base.CurrentUser = value; } }
public new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; private set => base.CurrentUser = value; }
public IReadOnlyCollection<SocketGuild> Guilds => State.Guilds;
public IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels;
public IReadOnlyCollection<SocketDMChannel> DMChannels
@@ -474,7 +474,7 @@ namespace Discord.WebSocket
AddPrivateChannel(data.PrivateChannels[i], state);

_sessionId = data.SessionId;
_unavailableGuilds = unavailableGuilds;
_unavailableGuildCount = unavailableGuilds;
CurrentUser = currentUser;
State = state;
}
@@ -537,10 +537,9 @@ namespace Discord.WebSocket
if (guild != null)
{
guild.Update(State, data);

var unavailableGuilds = _unavailableGuilds;
if (unavailableGuilds != 0)
_unavailableGuilds = unavailableGuilds - 1;
if (_unavailableGuildCount != 0)
_unavailableGuildCount--;
await GuildAvailableAsync(guild).ConfigureAwait(false);

if (guild.DownloadedMemberCount >= guild.MemberCount && !guild.DownloaderPromise.IsCompleted)
@@ -622,7 +621,7 @@ namespace Discord.WebSocket
var before = guild.Clone();
guild.Update(State, data);
//This is treated as an extension of GUILD_AVAILABLE
_unavailableGuilds--;
_unavailableGuildCount--;
_lastGuildAvailableTime = Environment.TickCount;
await GuildAvailableAsync(guild).ConfigureAwait(false);
await TimedInvokeAsync(_guildUpdatedEvent, nameof(GuildUpdated), before, guild).ConfigureAwait(false);
@@ -646,7 +645,7 @@ namespace Discord.WebSocket
if (guild != null)
{
await GuildUnavailableAsync(guild).ConfigureAwait(false);
_unavailableGuilds++;
_unavailableGuildCount++;
}
else
{
@@ -1212,10 +1211,10 @@ namespace Discord.WebSocket
var data = (payload as JToken).ToObject<API.Gateway.Reaction>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
SocketUserMessage cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
SocketReaction reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);

cachedMsg?.AddReaction(reaction);
@@ -1236,10 +1235,10 @@ namespace Discord.WebSocket
var data = (payload as JToken).ToObject<API.Gateway.Reaction>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
SocketUserMessage cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
SocketReaction reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);

cachedMsg?.RemoveReaction(reaction);
@@ -1260,7 +1259,7 @@ namespace Discord.WebSocket
var data = (payload as JToken).ToObject<RemoveAllReactionsEvent>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
SocketUserMessage cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);

@@ -1289,7 +1288,7 @@ namespace Discord.WebSocket
return;
}

foreach (var id in data.Ids)
foreach (ulong id in data.Ids)
{
var msg = SocketChannelHelper.RemoveMessage(channel, this, id);
bool isCached = msg != null;
@@ -1542,7 +1541,7 @@ namespace Discord.WebSocket
await _gatewayLogger.DebugAsync("Heartbeat Started").ConfigureAwait(false);
while (!cancelToken.IsCancellationRequested)
{
var now = Environment.TickCount;
int now = Environment.TickCount;

//Did server respond to our last heartbeat, or are we still receiving messages (long load?)
if (_heartbeatTimes.Count != 0 && (now - _lastMessageTime) > intervalMillis)
@@ -1589,7 +1588,7 @@ namespace Discord.WebSocket
try
{
await logger.DebugAsync("GuildDownloader Started").ConfigureAwait(false);
while ((_unavailableGuilds != 0) && (Environment.TickCount - _lastGuildAvailableTime < 2000))
while ((_unavailableGuildCount != 0) && (Environment.TickCount - _lastGuildAvailableTime < 2000))
await Task.Delay(500, cancelToken).ConfigureAwait(false);
await logger.DebugAsync("GuildDownloader Stopped").ConfigureAwait(false);
}
@@ -1750,27 +1749,27 @@ namespace Discord.WebSocket

private async Task UnknownGlobalUserAsync(string evnt, ulong userId)
{
var details = $"{evnt} User={userId}";
string details = $"{evnt} User={userId}";
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
}
private async Task UnknownChannelUserAsync(string evnt, ulong userId, ulong channelId)
{
var details = $"{evnt} User={userId} Channel={channelId}";
string details = $"{evnt} User={userId} Channel={channelId}";
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
}
private async Task UnknownGuildUserAsync(string evnt, ulong userId, ulong guildId)
{
var details = $"{evnt} User={userId} Guild={guildId}";
string details = $"{evnt} User={userId} Guild={guildId}";
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
}
private async Task IncompleteGuildUserAsync(string evnt, ulong userId, ulong guildId)
{
var details = $"{evnt} User={userId} Guild={guildId}";
string details = $"{evnt} User={userId} Guild={guildId}";
await _gatewayLogger.DebugAsync($"User has not been downloaded ({details}).").ConfigureAwait(false);
}
private async Task UnknownChannelAsync(string evnt, ulong channelId)
{
var details = $"{evnt} Channel={channelId}";
string details = $"{evnt} Channel={channelId}";
await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false);
}
private async Task UnknownChannelAsync(string evnt, ulong channelId, ulong guildId)
@@ -1780,22 +1779,22 @@ namespace Discord.WebSocket
await UnknownChannelAsync(evnt, channelId).ConfigureAwait(false);
return;
}
var details = $"{evnt} Channel={channelId} Guild={guildId}";
string details = $"{evnt} Channel={channelId} Guild={guildId}";
await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false);
}
private async Task UnknownRoleAsync(string evnt, ulong roleId, ulong guildId)
{
var details = $"{evnt} Role={roleId} Guild={guildId}";
string details = $"{evnt} Role={roleId} Guild={guildId}";
await _gatewayLogger.WarningAsync($"Unknown Role ({details}).").ConfigureAwait(false);
}
private async Task UnknownGuildAsync(string evnt, ulong guildId)
{
var details = $"{evnt} Guild={guildId}";
string details = $"{evnt} Guild={guildId}";
await _gatewayLogger.WarningAsync($"Unknown Guild ({details}).").ConfigureAwait(false);
}
private async Task UnsyncedGuildAsync(string evnt, ulong guildId)
{
var details = $"{evnt} Guild={guildId}";
string details = $"{evnt} Guild={guildId}";
await _gatewayLogger.DebugAsync($"Unsynced Guild ({details}).").ConfigureAwait(false);
}



Loading…
Cancel
Save