Use the new Csharp 8 features (pattern matching and using assignments) and cleanup some insignificant resparper complaints

This commit is contained in:
runebaas 2020-02-08 15:58:17 +01:00
parent 21f813d342
commit 3568b61f38
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
27 changed files with 217 additions and 250 deletions

View file

@ -22,7 +22,7 @@ namespace Geekbot.net.Lib.Clients
ReloadClient();
}
public bool ReloadClient()
private bool ReloadClient()
{
var malCredentials = _globalSettings.GetKey("MalCredentials");
if (!string.IsNullOrEmpty(malCredentials))

View file

@ -4,7 +4,7 @@ using Discord.Commands;
namespace Geekbot.net.Lib.CommandPreconditions
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class DisableInDirectMessageAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)

View file

@ -7,7 +7,7 @@ namespace Geekbot.net.Lib.Converters
{
public class MtgManaConverter : IMtgManaConverter
{
private Dictionary<string, string> _manaDict;
private readonly Dictionary<string, string> _manaDict;
public MtgManaConverter()
{

View file

@ -20,26 +20,15 @@ namespace Geekbot.net.Lib.Highscores
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount)
{
Dictionary<ulong, int> list;
switch (type)
var list = type switch
{
case HighscoreTypes.messages:
list = GetMessageList(guildId, amount);
break;
case HighscoreTypes.karma:
list = GetKarmaList(guildId, amount);
break;
case HighscoreTypes.rolls:
list = GetRollsList(guildId, amount);
break;
case HighscoreTypes.cookies:
list = GetCookiesList(guildId, amount);
break;
default:
list = new Dictionary<ulong, int>();
break;
}
HighscoreTypes.messages => GetMessageList(guildId, amount),
HighscoreTypes.karma => GetKarmaList(guildId, amount),
HighscoreTypes.rolls => GetRollsList(guildId, amount),
HighscoreTypes.cookies => GetCookiesList(guildId, amount),
_ => new Dictionary<ulong, int>()
};
if (!list.Any())
{
throw new HighscoreListEmptyException($"No {type} found for guild {guildId}");
@ -103,8 +92,8 @@ namespace Geekbot.net.Lib.Highscores
.Take(amount)
.ToDictionary(key => key.UserId.AsUlong(), key => key.Rolls);
}
public Dictionary<ulong, int> GetCookiesList(ulong guildId, int amount)
private Dictionary<ulong, int> GetCookiesList(ulong guildId, int amount)
{
return _database.Cookies
.Where(k => k.GuildId.Equals(guildId.AsLong()))

View file

@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Geekbot.net.Lib.Levels
{
public class LevelCalc : ILevelCalc
{
private int[] _levels;
private readonly int[] _levels;
public LevelCalc()
{
@ -21,13 +22,7 @@ namespace Geekbot.net.Lib.Levels
public int GetLevel(int? messages)
{
var returnVal = 1;
foreach (var level in _levels)
{
if (level > messages) break;
returnVal++;
}
return returnVal;
return 1 + _levels.TakeWhile(level => !(level > messages)).Count();
}
}
}

View file

@ -37,7 +37,7 @@ namespace Geekbot.net.Lib.Logger
}
public static MessageDto ConvertSocketMessage(SocketMessage message, bool isPrivate = false)
{
SocketGuildChannel channel = isPrivate ? null : (SocketGuildChannel) message.Channel;
var channel = isPrivate ? null : (SocketGuildChannel) message.Channel;
return new MessageDto
{
Message = new MessageDto.MessageContent

View file

@ -63,8 +63,11 @@ namespace Geekbot.net.Lib.ReactionListener
_listener[messageId].Add(emoji, role.Id);
return Task.CompletedTask;
}
var dict = new Dictionary<IEmote, ulong>();
dict.Add(emoji, role.Id);
var dict = new Dictionary<IEmote, ulong>
{
{emoji, role.Id}
};
_listener.Add(messageId, dict);
return Task.CompletedTask;
}