mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-27 04:00:34 +00:00
apply compiler suggestions
This commit is contained in:
parent
166e14981e
commit
4efffa300f
@ -226,7 +226,7 @@ namespace CompatBot.Commands
|
||||
embed.AddField($"Top {top.Count} Recent Game Lookups", statsBuilder.ToString().TrimEnd(), true);
|
||||
}
|
||||
|
||||
private void AppendSyscallsStats(DiscordEmbedBuilder embed)
|
||||
private static void AppendSyscallsStats(DiscordEmbedBuilder embed)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -247,7 +247,7 @@ namespace CompatBot.Commands
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendPawStats(DiscordEmbedBuilder embed)
|
||||
private static void AppendPawStats(DiscordEmbedBuilder embed)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -403,7 +403,7 @@ namespace CompatBot.Commands
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DoRequestAndRespond(CommandContext ctx, RequestBuilder requestBuilder)
|
||||
private static async Task DoRequestAndRespond(CommandContext ctx, RequestBuilder requestBuilder)
|
||||
{
|
||||
Config.Log.Info(requestBuilder.Build());
|
||||
CompatResult? result = null;
|
||||
@ -464,7 +464,7 @@ namespace CompatBot.Commands
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<string> FormatSearchResults(CommandContext ctx, CompatResult compatResult)
|
||||
private static IEnumerable<string> FormatSearchResults(CommandContext ctx, CompatResult compatResult)
|
||||
{
|
||||
var returnCode = ApiConfig.ReturnCodes[compatResult.ReturnCode];
|
||||
var request = compatResult.RequestBuilder;
|
||||
|
@ -13,7 +13,7 @@ namespace CompatBot.Commands
|
||||
=> NearestEvent(ctx, "Cyberpunk 2077");
|
||||
|
||||
[Command("2077"), Hidden]
|
||||
public Task Cp77(CommandContext ctx, [RemainingText] string junk)
|
||||
public Task Cp77(CommandContext ctx, [RemainingText] string? _ = null)
|
||||
=> NearestEvent(ctx, "Cyberpunk 2077");
|
||||
|
||||
[Command("countdown")]
|
||||
|
@ -97,7 +97,7 @@ namespace CompatBot.Commands
|
||||
await ctx.RespondAsync(result.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private byte[,] GenerateField(int width, int height, in int mineCount, in Random rng)
|
||||
private static byte[,] GenerateField(int width, int height, in int mineCount, in Random rng)
|
||||
{
|
||||
var len = width * height;
|
||||
var cells = new byte[len];
|
||||
|
@ -166,7 +166,7 @@ namespace CompatBot.Commands
|
||||
}
|
||||
*/
|
||||
|
||||
private List<DiscordMember> GetMembers(DiscordClient client)
|
||||
private static List<DiscordMember> GetMembers(DiscordClient client)
|
||||
{
|
||||
//owner -> white name
|
||||
//newbs -> veterans
|
||||
@ -177,7 +177,7 @@ namespace CompatBot.Commands
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private async void SpoofingCheck(CommandContext ctx)
|
||||
private static async void SpoofingCheck(CommandContext ctx)
|
||||
{
|
||||
if (!CheckLock.Wait(0))
|
||||
{
|
||||
|
@ -1,20 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace CompatBot.Commands
|
||||
{
|
||||
[Group("ama"), Hidden]
|
||||
[Description("Provides information about the RPCS3 AMA event")]
|
||||
internal sealed class Rpcs3Ama: EventsBaseCommand
|
||||
{
|
||||
[GroupCommand]
|
||||
public Task AmaCountdown(CommandContext ctx)
|
||||
=> NearestEvent(ctx, "RPCS3 AMA");
|
||||
|
||||
[Command("countdown")]
|
||||
[Description("Provides information about the RPCS3 AMA event")]
|
||||
public Task Countdown(CommandContext ctx)
|
||||
=> AmaCountdown(ctx);
|
||||
}
|
||||
}
|
@ -89,7 +89,7 @@ namespace CompatBot
|
||||
internal static class AllowedMentions
|
||||
{
|
||||
internal static readonly IMention[] UsersOnly = { UserMention.All };
|
||||
internal static readonly IMention[] Nothing = { };
|
||||
internal static readonly IMention[] Nothing = Array.Empty<IMention>();
|
||||
}
|
||||
|
||||
internal static string CurrentLogPath => Path.GetFullPath(Path.Combine(LogPath, "bot.log"));
|
||||
|
@ -22,7 +22,7 @@ namespace CompatBot.Database
|
||||
catch (SqliteException e)
|
||||
{
|
||||
Config.Log.Warn(e, "Database upgrade failed, probably importing an unversioned one.");
|
||||
if (!(dbContext is BotDb botDb))
|
||||
if (dbContext is not BotDb botDb)
|
||||
return false;
|
||||
|
||||
Config.Log.Info("Trying to apply a manual fixup...");
|
||||
|
@ -10,7 +10,7 @@ namespace CompatBot.Database
|
||||
public static void ConfigureDefaultPkConvention(this ModelBuilder modelBuilder, string keyProperty = "Id")
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyProperty))
|
||||
throw new ArgumentException(nameof(keyProperty));
|
||||
throw new ArgumentException("Key property name is mandatory", nameof(keyProperty));
|
||||
|
||||
foreach (var entity in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace CompatBot.EventHandlers
|
||||
private static readonly TimeSpan ThrottleDuration = TimeSpan.FromHours(1);
|
||||
private static readonly MemoryCache Throttling = new MemoryCache(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromMinutes(30)});
|
||||
|
||||
public static async Task OnMessageCreated(DiscordClient _c, MessageCreateEventArgs args)
|
||||
public static async Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
|
||||
{
|
||||
if (DefaultHandlerFilter.IsFluff(args.Message))
|
||||
return;
|
||||
@ -38,7 +38,7 @@ namespace CompatBot.EventHandlers
|
||||
MessageQueue[args.Channel.Id] = queue = new ConcurrentQueue<DiscordMessage>();
|
||||
queue.Enqueue(args.Message);
|
||||
while (queue.Count > 10)
|
||||
queue.TryDequeue(out _);
|
||||
queue.TryDequeue(out var _i);
|
||||
var content = args.Message.Content;
|
||||
if (string.IsNullOrEmpty(content))
|
||||
return;
|
||||
|
@ -18,7 +18,6 @@ namespace CompatBot.EventHandlers
|
||||
public static readonly Regex CommitMention = new Regex(@"(?<commit_mention>(https?://)github.com/RPCS3/rpcs3/commit/(?<commit_hash>[0-9a-f]+))\b", DefaultOptions);
|
||||
public static readonly Regex ImageMarkup = new Regex(@"(?<img_markup>!\[(?<img_caption>[^\]]+)\]\((?<img_link>\w+://[^\)]+)\))", DefaultOptions);
|
||||
private static readonly Regex IssueLink = new Regex(@"github.com/RPCS3/rpcs3/issues/(?<number>\d+)", DefaultOptions);
|
||||
private static readonly GithubClient.Client Client = new GithubClient.Client();
|
||||
|
||||
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
|
||||
{
|
||||
@ -77,7 +76,7 @@ namespace CompatBot.EventHandlers
|
||||
.SelectMany(match => new[] {match.Groups["number"].Value, match.Groups["also_number"].Value})
|
||||
.Distinct()
|
||||
.Select(n => {
|
||||
int.TryParse(n, out var i);
|
||||
_ = int.TryParse(n, out var i);
|
||||
return i;
|
||||
})
|
||||
.Where(n => n > 0)
|
||||
@ -89,7 +88,7 @@ namespace CompatBot.EventHandlers
|
||||
IssueLink.Matches(input)
|
||||
.Select(match =>
|
||||
{
|
||||
int.TryParse(match.Groups["number"].Value, out var n);
|
||||
_ = int.TryParse(match.Groups["number"].Value, out var n);
|
||||
return n;
|
||||
})
|
||||
);
|
||||
|
@ -84,7 +84,7 @@ namespace CompatBot.EventHandlers.LogParsing.SourceHandlers
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
private DriveService GetClient()
|
||||
private static DriveService GetClient()
|
||||
{
|
||||
var credential = GoogleCredential.FromFile(Config.GoogleApiConfigPath).CreateScoped(Scopes);
|
||||
var service = new DriveService(new BaseClientService.Initializer()
|
||||
|
@ -42,7 +42,7 @@ namespace CompatBot.EventHandlers
|
||||
if (tableIdx < 0)
|
||||
tableIdx = content.IndexOf("┻━┻");
|
||||
var faceIdx = content[..tableIdx].LastIndexOfAny(OpenParen);
|
||||
var face = content.Substring(faceIdx, tableIdx - faceIdx);
|
||||
var face = content[faceIdx..tableIdx];
|
||||
if (face.Length > 30)
|
||||
return;
|
||||
|
||||
|
@ -158,7 +158,6 @@ namespace CompatBot
|
||||
commands.RegisterCommands<Events>();
|
||||
commands.RegisterCommands<E3>();
|
||||
commands.RegisterCommands<Cyberpunk2077>();
|
||||
commands.RegisterCommands<Rpcs3Ama>();
|
||||
commands.RegisterCommands<BotStats>();
|
||||
commands.RegisterCommands<Syscall>();
|
||||
commands.RegisterCommands<ForcedNicknames>();
|
||||
@ -180,7 +179,7 @@ namespace CompatBot
|
||||
var msg = new StringBuilder($"Bot admin id{(owners.Count == 1 ? "": "s")}:");
|
||||
if (owners.Count > 1)
|
||||
msg.AppendLine();
|
||||
using var db = new BotDb();
|
||||
await using var db = new BotDb();
|
||||
foreach (var owner in owners)
|
||||
{
|
||||
msg.AppendLine($"\t{owner.Id} ({owner.Username ?? "???"}#{owner.Discriminator ?? "????"})");
|
||||
|
@ -22,7 +22,7 @@ namespace CompatBot.ThumbScrapper
|
||||
private static readonly HttpClient HttpClient = HttpClientFactory.Create(new CompressionMessageHandler());
|
||||
private static readonly Uri TitleDownloadLink = new Uri("https://www.gametdb.com/ps3tdb.zip?LANG=EN");
|
||||
private static readonly Regex CoverArtLink = new Regex(@"(?<cover_link>https?://art\.gametdb\.com/ps3/cover(?!full)[/\w\d]+\.jpg(\?\d+)?)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.ExplicitCapture);
|
||||
private static readonly List<string> PreferredOrder = new List<string>{"coverHQ", "coverM", "cover"};
|
||||
//private static readonly List<string> PreferredOrder = new List<string>{"coverHQ", "coverM", "cover"};
|
||||
|
||||
public static async Task RunAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ namespace CompatBot.Utils
|
||||
private readonly object sync = new object();
|
||||
private bool disposed;
|
||||
|
||||
public BufferCopyStream(Stream baseStream, int bufferSize = 4096)
|
||||
public BufferCopyStream(Stream? baseStream, int bufferSize = 4096)
|
||||
{
|
||||
if (baseStream == null)
|
||||
throw new ArgumentNullException(nameof(baseStream));
|
||||
|
@ -190,7 +190,7 @@ namespace CompatBot.Utils
|
||||
if (!emojiName.StartsWith(":"))
|
||||
emojiName = ":" + emojiName;
|
||||
if (!emojiName.EndsWith(":"))
|
||||
emojiName = emojiName + ":";
|
||||
emojiName += ":";
|
||||
return DiscordEmoji.FromName(client, emojiName);
|
||||
}
|
||||
catch
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace CompatBot.Utils
|
||||
{
|
||||
@ -14,7 +15,7 @@ namespace CompatBot.Utils
|
||||
do
|
||||
{
|
||||
var remaining = count - result;
|
||||
read = await stream.ReadAsync(buffer, result, remaining).ConfigureAwait(false);
|
||||
read = await stream.ReadAsync(buffer.AsMemory(result, remaining)).ConfigureAwait(false);
|
||||
result += read;
|
||||
} while (read > 0 && result < count);
|
||||
return result;
|
||||
|
@ -128,7 +128,7 @@ namespace CompatBot.Utils
|
||||
foreach (var segment in sequence)
|
||||
{
|
||||
encoding.GetChars(segment.Span, span);
|
||||
span = span.Slice(segment.Length);
|
||||
span = span[segment.Length ..];
|
||||
}
|
||||
}
|
||||
return string.Create((int)buffer.Length, buffer, Splice);
|
||||
|
@ -55,10 +55,10 @@ namespace CompatBot.Utils
|
||||
|
||||
public void TrimExcess()
|
||||
{
|
||||
if (Count <= MaxLength)
|
||||
if (Count <= FixedLengthBuffer<TKey, TValue>.MaxLength)
|
||||
return;
|
||||
|
||||
TrimOldItems(Count - MaxLength);
|
||||
TrimOldItems(Count - FixedLengthBuffer<TKey, TValue>.MaxLength);
|
||||
}
|
||||
|
||||
public List<TValue> GetOldItems(int count)
|
||||
@ -66,9 +66,9 @@ namespace CompatBot.Utils
|
||||
|
||||
public List<TValue> GetExcess()
|
||||
{
|
||||
if (Count <= MaxLength)
|
||||
if (Count <= FixedLengthBuffer<TKey, TValue>.MaxLength)
|
||||
return new List<TValue>(0);
|
||||
return GetOldItems(Count - MaxLength);
|
||||
return GetOldItems(Count - FixedLengthBuffer<TKey, TValue>.MaxLength);
|
||||
}
|
||||
|
||||
public TValue? Evict(TKey key)
|
||||
@ -117,10 +117,10 @@ namespace CompatBot.Utils
|
||||
public int Count => lookup.Count;
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public bool NeedTrimming => Count > MaxLength + 20;
|
||||
public bool NeedTrimming => Count > FixedLengthBuffer<TKey, TValue>.MaxLength + 20;
|
||||
public TValue this[TKey index] => lookup[index];
|
||||
|
||||
private int MaxLength => Config.ChannelMessageHistorySize;
|
||||
private static int MaxLength => Config.ChannelMessageHistorySize;
|
||||
private readonly Func<TValue, TKey> makeKey;
|
||||
private readonly List<TKey> keyList = new List<TKey>();
|
||||
private readonly Dictionary<TKey, TValue> lookup = new Dictionary<TKey, TValue>();
|
||||
|
@ -36,7 +36,7 @@ namespace CompatBot.Utils
|
||||
}
|
||||
case 'N':
|
||||
{
|
||||
DecodeMediaN(productCode.Slice(1), result);
|
||||
DecodeMediaN(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
case 'X':
|
||||
@ -51,18 +51,18 @@ namespace CompatBot.Utils
|
||||
}
|
||||
case 'P':
|
||||
{
|
||||
DecodeMediaP(productCode.Slice(1), result);
|
||||
DecodeMediaP(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
case 'C':
|
||||
{
|
||||
DecodeMediaC(productCode.Slice(1), result);
|
||||
DecodeMediaC(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
case char _ when productCode[..4] == "MRTC":
|
||||
{
|
||||
result.Add("Media Replication and Transfer Code (or something completely different, no one knows for sure)");
|
||||
DecodeRegionNumbers(productCode.Slice(4), result);
|
||||
DecodeRegionNumbers(productCode[4..], result);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
@ -71,7 +71,7 @@ namespace CompatBot.Utils
|
||||
return;
|
||||
}
|
||||
}
|
||||
DecodeRights(productCode.Slice(1), result);
|
||||
DecodeRights(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeRights(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -94,7 +94,7 @@ namespace CompatBot.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
DecodePhysicalRegion(productCode.Slice(1), result);
|
||||
DecodePhysicalRegion(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodePhysicalRegion(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -153,7 +153,7 @@ namespace CompatBot.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
DecodePhysicalContentType(productCode.Slice(1), result);
|
||||
DecodePhysicalContentType(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodePhysicalContentType(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -211,7 +211,7 @@ namespace CompatBot.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
DecodeRegionNumbers(productCode.Slice(1), result);
|
||||
DecodeRegionNumbers(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeRegionNumbers(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -282,7 +282,7 @@ namespace CompatBot.Utils
|
||||
return;
|
||||
}
|
||||
}
|
||||
DecodeDigitalRegion(productCode.Slice(1), result);
|
||||
DecodeDigitalRegion(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeDigitalRegion(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -335,7 +335,7 @@ namespace CompatBot.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
DecodeDigitalContentType(productCode.Slice(1), result);
|
||||
DecodeDigitalContentType(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeDigitalContentType(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -458,7 +458,7 @@ namespace CompatBot.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
DecodeRegionNumbers(productCode.Slice(1), result);
|
||||
DecodeRegionNumbers(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeMediaP(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -482,7 +482,7 @@ namespace CompatBot.Utils
|
||||
}
|
||||
case 'C':
|
||||
{
|
||||
DecodeMediaPC(productCode.Slice(1), result);
|
||||
DecodeMediaPC(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
@ -491,7 +491,7 @@ namespace CompatBot.Utils
|
||||
return;
|
||||
}
|
||||
}
|
||||
DecodePhysicalRegion(productCode.Slice(1), result);
|
||||
DecodePhysicalRegion(productCode[1..], result);
|
||||
}
|
||||
|
||||
private static void DecodeMediaPC(in ReadOnlySpan<char> productCode, List<string> result)
|
||||
@ -501,13 +501,13 @@ namespace CompatBot.Utils
|
||||
case 'S':
|
||||
{
|
||||
result.Add("Playstation Vita software");
|
||||
DecodeVitaRegion(productCode.Slice(1), result);
|
||||
DecodeVitaRegion(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
case 'P':
|
||||
{
|
||||
result.Add("Optical media with promotional videos");
|
||||
DecodePhysicalContentType(productCode.Slice(1), result);
|
||||
DecodePhysicalContentType(productCode[1..], result);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
|
@ -111,7 +111,5 @@ namespace CompatBot.Utils
|
||||
|
||||
public int Length => list.Count;
|
||||
public IEqualityComparer<T>? Comparer { get; }
|
||||
|
||||
T GetAt(int index) => list[index];
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ namespace Tests
|
||||
var result = await readPipeTask.ConfigureAwait(false);
|
||||
await fillPipeTask.ConfigureAwait(false);
|
||||
result.TotalBytes = source.LogFileSize;
|
||||
#if DEBUG
|
||||
Config.Log.Debug("~~~~~~~~~~~~~~~~~~~~");
|
||||
Config.Log.Debug("Extractor hit stats (CPU time, s / total hits):");
|
||||
foreach (var (key, (count, time)) in result.ExtractorHitStats.OrderByDescending(kvp => kvp.Value.regexTime))
|
||||
@ -54,6 +55,7 @@ namespace Tests
|
||||
Config.Log.Debug(msg);
|
||||
}
|
||||
Config.Log.Debug("~~~~~~~~~~~~~~~~~~~~");
|
||||
#endif
|
||||
Assert.That(result.CompletedCollection, Is.Not.Null.And.Not.Empty);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ namespace Tests
|
||||
var str = "abc";
|
||||
Assert.That(str[1..], Is.EqualTo(str.Substring(1)));
|
||||
Assert.That("a"[1..], Is.EqualTo("a".Substring(1)));
|
||||
Assert.That(str[0], Is.EqualTo('a'));
|
||||
Assert.That(str[^1], Is.EqualTo('c'));
|
||||
}
|
||||
}
|
||||
}
|
@ -95,7 +95,7 @@ namespace Tests
|
||||
Username = parts[0],
|
||||
Nickname = parts[1],
|
||||
JoinDate = DateTime.Parse(parts[2], CultureInfo.InvariantCulture),
|
||||
Roles = parts[3]?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? new string[0],
|
||||
Roles = parts[3]?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user