Added and applied styles for private readonly fields, private fields to Extensions and Common folders.

- Some renamings and code cleanups
- Chained method calls, binary expressions and binary patterns will now break into newlines
- Type param constraints and base constructor calls will be on the new line
This commit is contained in:
Kwoth
2021-12-27 03:46:30 +01:00
parent 9ae030a5c5
commit 1b0392dfab
85 changed files with 1015 additions and 906 deletions

View File

@@ -43,8 +43,8 @@ public partial class Administration
[Priority(0)]
public async Task LanguageSet()
=> await ReplyConfirmLocalizedAsync(strs.lang_set_show(
Format.Bold(_cultureInfo.ToString()),
Format.Bold(_cultureInfo.NativeName)));
Format.Bold(Culture.ToString()),
Format.Bold(Culture.NativeName)));
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]

View File

@@ -1002,8 +1002,7 @@ public sealed class LogCommandService : ILogCommandService
{
try
{
var msg = optMsg.Value as IUserMessage;
if (msg is null || msg.IsAuthor(_client))
if (optMsg.Value is not IUserMessage msg || msg.IsAuthor(_client))
return;
if (_ignoreMessageIds.Contains(msg.Id))
@@ -1058,8 +1057,7 @@ public sealed class LogCommandService : ILogCommandService
if (imsg2 is not IUserMessage after || after.IsAuthor(_client))
return;
var before = (optmsg.HasValue ? optmsg.Value : null) as IUserMessage;
if (before is null)
if ((optmsg.HasValue ? optmsg.Value : null) is not IUserMessage before)
return;
if (ch is not ITextChannel channel)

View File

@@ -167,9 +167,7 @@ public class VcRoleService : INService
private Task ClientOnUserVoiceStateUpdated(SocketUser usr, SocketVoiceState oldState,
SocketVoiceState newState)
{
var gusr = usr as SocketGuildUser;
if (gusr is null)
if (usr is not SocketGuildUser gusr)
return Task.CompletedTask;
var oldVc = oldState.VoiceChannel;

View File

@@ -465,7 +465,7 @@ public partial class Administration
.AddField(GetText(strs.duration),
time.Time.Humanize(3,
minUnit: TimeUnit.Minute,
culture: _cultureInfo),
culture: Culture),
true);
if (dmFailed)

View File

@@ -152,8 +152,7 @@ public class ReactionEvent : ICurrencyEvent
{
if (_emote.Name != r.Emote.Name)
return;
var gu = (r.User.IsSpecified ? r.User.Value : null) as IGuildUser;
if (gu is null // no unknown users, as they could be bots, or alts
if ((r.User.IsSpecified ? r.User.Value : null) is not IGuildUser gu // no unknown users, as they could be bots, or alts
|| msg.Id != _msg.Id // same message
|| gu.IsBot // no bots
|| (DateTime.UtcNow - gu.CreatedAt).TotalDays <= 5 // no recently created accounts

View File

@@ -35,7 +35,7 @@ public partial class Gambling : GamblingModule<GamblingService>
private string n(long cur)
{
var flowersCi = (CultureInfo)_cultureInfo.Clone();
var flowersCi = (CultureInfo)Culture.Clone();
flowersCi.NumberFormat.CurrencySymbol = CurrencySign;
Log.Information(string.Join(",", flowersCi.NumberFormat.NativeDigits));
return cur.ToString("C0", flowersCi);
@@ -59,12 +59,12 @@ public partial class Gambling : GamblingModule<GamblingService>
}
var embed = _eb.Create()
.WithTitle(GetText(strs.economy_state))
.AddField(GetText(strs.currency_owned), ((BigInteger)(ec.Cash - ec.Bot)).ToString("N", _cultureInfo) + CurrencySign)
.AddField(GetText(strs.currency_owned), ((BigInteger)(ec.Cash - ec.Bot)).ToString("N", Culture) + CurrencySign)
.AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%")
.AddField(GetText(strs.currency_planted), (BigInteger)ec.Planted)
.AddField(GetText(strs.owned_waifus_total), (BigInteger)ec.Waifus + CurrencySign)
.AddField(GetText(strs.bot_currency), n(ec.Bot))
.AddField(GetText(strs.total), ((BigInteger)(ec.Cash + ec.Planted + ec.Waifus)).ToString("N", _cultureInfo) + CurrencySign)
.AddField(GetText(strs.total), ((BigInteger)(ec.Cash + ec.Planted + ec.Waifus)).ToString("N", Culture) + CurrencySign)
.WithOkColor();
// ec.Cash already contains ec.Bot as it's the total of all values in the CurrencyAmount column of the DiscordUser table
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);

View File

@@ -27,8 +27,7 @@ public class CurrencyEventsService : INService
EventOptions opts, Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embed)
{
var g = _client.GetGuild(guildId);
var ch = g?.GetChannel(channelId) as SocketTextChannel;
if (ch is null)
if (g?.GetChannel(channelId) is not SocketTextChannel ch)
return false;
ICurrencyEvent ce;

View File

@@ -159,8 +159,7 @@ public class PlantPickService : INService
private Task PotentialFlowerGeneration(IUserMessage imsg)
{
var msg = imsg as SocketUserMessage;
if (msg is null || msg.Author.IsBot)
if (imsg is not SocketUserMessage msg || msg.Author.IsBot)
return Task.CompletedTask;
if (imsg.Channel is not ITextChannel channel)

View File

@@ -196,8 +196,7 @@ public class TriviaGame
var umsg = imsg as SocketUserMessage;
var textChannel = umsg?.Channel as ITextChannel;
if (textChannel is null || textChannel.Guild != Guild)
if (umsg?.Channel is not ITextChannel textChannel || textChannel.Guild != Guild)
return;
var guildUser = (IGuildUser)umsg.Author;

View File

@@ -133,8 +133,7 @@ public class TypingGame
{
if (imsg.Author.IsBot)
return;
var msg = imsg as SocketUserMessage;
if (msg is null)
if (imsg is not SocketUserMessage msg)
return;
if (this.Channel is null || this.Channel.Id != msg.Channel.Id) return;

View File

@@ -97,9 +97,8 @@ public sealed class FilterService : IEarlyBehavior
var _ = Task.Run(() =>
{
var guild = (channel as ITextChannel)?.Guild;
var usrMsg = newMsg as IUserMessage;
if (guild is null || usrMsg is null)
if (guild is null || newMsg is not IUserMessage usrMsg)
return Task.CompletedTask;
return RunBehavior(guild, usrMsg);

View File

@@ -56,7 +56,7 @@ public partial class Searches
.WithDescription(string.IsNullOrWhiteSpace(kvp.Value.Desc)
? kvp.Value.ShortDesc
: kvp.Value.Desc)
.AddField(GetText(strs.rating), kvp.Value.Rating.ToString(_cultureInfo), true));
.AddField(GetText(strs.rating), kvp.Value.Rating.ToString(Culture), true));
return;
}
}

View File

@@ -626,9 +626,7 @@ public class SearchesService : INService
var results = elems.Select(elem =>
{
var anchor = elem.QuerySelector(".result__a") as IHtmlAnchorElement;
if (anchor is null)
if (elem.QuerySelector(".result__a") is not IHtmlAnchorElement anchor)
return null;
var href = anchor.Href;

View File

@@ -127,7 +127,7 @@ public partial class Utility
var diff = when - DateTime.UtcNow;
embed.AddField(
$"#{++i + (page * 10)} {rem.When:HH:mm yyyy-MM-dd} UTC " +
$"(in {diff.Humanize(2, minUnit: TimeUnit.Minute, culture: _cultureInfo)})",
$"(in {diff.Humanize(2, minUnit: TimeUnit.Minute, culture: Culture)})",
$@"`Target:` {(rem.IsPrivate ? "DM" : "Channel")}
`TargetId:` {rem.ChannelId}
`Message:` {rem.Message?.TrimTo(50)}", false);
@@ -230,7 +230,7 @@ public partial class Utility
"⏰ " + GetText(strs.remind(
Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username),
Format.Bold(message),
ts.Humanize(3, minUnit: TimeUnit.Second, culture: _cultureInfo),
ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture),
gTime, gTime))).ConfigureAwait(false);
}
catch

View File

@@ -106,14 +106,6 @@ public partial class Xp : NadekoModule<XpService>
}, allRewards.Count, 9);
}
public enum AddRemove
{
Add = 0,
Remove = 1,
Rm = 1,
Rem = 1,
}
[NadekoCommand, Aliases]
[UserPerm(GuildPerm.Administrator)]
[BotPerm(GuildPerm.ManageRoles)]