diff --git a/src/NadekoBot.Tests/IndexedCollectionTests.cs b/src/NadekoBot.Tests/IndexedCollectionTests.cs index e206f866c..02949852b 100644 --- a/src/NadekoBot.Tests/IndexedCollectionTests.cs +++ b/src/NadekoBot.Tests/IndexedCollectionTests.cs @@ -62,7 +62,10 @@ namespace NadekoBot.Tests collection.Clear(); Assert.IsTrue(collection.Count == 0, "Collection has not been cleared."); - Assert.Throws(() => collection.Contains(collection[0]), "Collection has not been cleared."); + Assert.Throws(() => + { + _ = collection[0]; + }, "Collection has not been cleared."); } [Test] diff --git a/src/NadekoBot/Common/Yml/CommentGatheringTypeInspector.cs b/src/NadekoBot/Common/Yml/CommentGatheringTypeInspector.cs index d64a736e2..8a00552f9 100644 --- a/src/NadekoBot/Common/Yml/CommentGatheringTypeInspector.cs +++ b/src/NadekoBot/Common/Yml/CommentGatheringTypeInspector.cs @@ -10,7 +10,7 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton private readonly ITypeInspector _innerTypeDescriptor; public CommentGatheringTypeInspector(ITypeInspector innerTypeDescriptor) - => this._innerTypeDescriptor = innerTypeDescriptor ?? throw new ArgumentNullException("innerTypeDescriptor"); + => _innerTypeDescriptor = innerTypeDescriptor ?? throw new ArgumentNullException("innerTypeDescriptor"); public override IEnumerable GetProperties(Type type, object container) => _innerTypeDescriptor.GetProperties(type, container).Select(d => new CommentsPropertyDescriptor(d)); @@ -43,7 +43,7 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton public CommentsPropertyDescriptor(IPropertyDescriptor baseDescriptor) { - this._baseDescriptor = baseDescriptor; + _baseDescriptor = baseDescriptor; Name = baseDescriptor.Name; } diff --git a/src/NadekoBot/Common/Yml/CommentsObjectDescriptor.cs b/src/NadekoBot/Common/Yml/CommentsObjectDescriptor.cs index 1408f2243..7778b3e2f 100644 --- a/src/NadekoBot/Common/Yml/CommentsObjectDescriptor.cs +++ b/src/NadekoBot/Common/Yml/CommentsObjectDescriptor.cs @@ -24,7 +24,7 @@ public sealed class CommentsObjectDescriptor : IObjectDescriptor public CommentsObjectDescriptor(IObjectDescriptor innerDescriptor, string comment) { - this._innerDescriptor = innerDescriptor; + _innerDescriptor = innerDescriptor; Comment = comment; } } \ No newline at end of file diff --git a/src/NadekoBot/Db/Extensions/QuoteExtensions.cs b/src/NadekoBot/Db/Extensions/QuoteExtensions.cs index 1854804b8..d679fd202 100644 --- a/src/NadekoBot/Db/Extensions/QuoteExtensions.cs +++ b/src/NadekoBot/Db/Extensions/QuoteExtensions.cs @@ -9,7 +9,7 @@ public static class QuoteExtensions public static IEnumerable GetForGuild(this DbSet quotes, ulong guildId) => quotes.AsQueryable().Where(x => x.GuildId == guildId); - public static IEnumerable GetGroup( + public static IReadOnlyCollection GetGroup( this DbSet quotes, ulong guildId, int page, diff --git a/src/NadekoBot/Modules/Administration/UserPunish/UserPunishService.cs b/src/NadekoBot/Modules/Administration/UserPunish/UserPunishService.cs index 706bb25f5..624948b20 100644 --- a/src/NadekoBot/Modules/Administration/UserPunish/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/UserPunish/UserPunishService.cs @@ -361,7 +361,7 @@ WHERE GuildId={guildId} .ToArray(); } - public (IEnumerable<(string Original, ulong? Id, string Reason)> Bans, int Missing) MassKill( + public (IReadOnlyCollection<(string Original, ulong? Id, string Reason)> Bans, int Missing) MassKill( SocketGuild guild, string people) { diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs index f0b53cc76..f4b75e2df 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs @@ -36,7 +36,7 @@ public partial class Gambling [NadekoOptionsAttribute(typeof(RaceOptions))] public partial Task Race(params string[] args) { - var (options, success) = OptionsParser.ParseFrom(new RaceOptions(), args); + var (options, _) = OptionsParser.ParseFrom(new RaceOptions(), args); var ar = new AnimalRace(options, _cs, _gamesConf.Data.RaceAnimals.Shuffle()); if (!_service.AnimalRaces.TryAdd(ctx.Guild.Id, ar)) @@ -46,7 +46,7 @@ public partial class Gambling var count = 0; - Task _client_MessageReceived(SocketMessage arg) + Task ClientMessageReceived(SocketMessage arg) { _= Task.Run(() => { @@ -61,9 +61,9 @@ public partial class Gambling return Task.CompletedTask; } - Task Ar_OnEnded(AnimalRace race) + Task ArOnEnded(AnimalRace race) { - _client.MessageReceived -= _client_MessageReceived; + _client.MessageReceived -= ClientMessageReceived; _service.AnimalRaces.TryRemove(ctx.Guild.Id, out _); var winner = race.FinishedUsers[0]; if (race.FinishedUsers[0].Bet > 0) @@ -77,9 +77,9 @@ public partial class Gambling ar.OnStartingFailed += Ar_OnStartingFailed; ar.OnStateUpdate += Ar_OnStateUpdate; - ar.OnEnded += Ar_OnEnded; + ar.OnEnded += ArOnEnded; ar.OnStarted += Ar_OnStarted; - _client.MessageReceived += _client_MessageReceived; + _client.MessageReceived += ClientMessageReceived; return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_starting(options.StartTime)), diff --git a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs index 50fe14d6b..925a9785e 100644 --- a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs +++ b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs @@ -34,7 +34,7 @@ public partial class Gambling if (!await CheckBetMandatory(amount)) return; - var newBj = new Blackjack(_cs, _db); + var newBj = new Blackjack(_cs); Blackjack bj; if (newBj == (bj = _service.Games.GetOrAdd(ctx.Channel.Id, newBj))) { diff --git a/src/NadekoBot/Modules/Gambling/BlackJack/Blackjack.cs b/src/NadekoBot/Modules/Gambling/BlackJack/Blackjack.cs index b7482e1c2..d484a1004 100644 --- a/src/NadekoBot/Modules/Gambling/BlackJack/Blackjack.cs +++ b/src/NadekoBot/Modules/Gambling/BlackJack/Blackjack.cs @@ -21,16 +21,14 @@ public class Blackjack public GameState State { get; set; } = GameState.Starting; public User CurrentUser { get; private set; } - private TaskCompletionSource _currentUserMove; + private TaskCompletionSource currentUserMove; private readonly ICurrencyService _cs; - private readonly DbService _db; private readonly SemaphoreSlim _locker = new(1, 1); - public Blackjack(ICurrencyService cs, DbService db) + public Blackjack(ICurrencyService cs) { _cs = cs; - _db = db; Dealer = new(); } @@ -58,7 +56,7 @@ public class Blackjack if (!Players.Any()) { State = GameState.Ended; - var end = GameEnded?.Invoke(this); + _ = GameEnded?.Invoke(this); return; } @@ -101,14 +99,14 @@ public class Blackjack { var pause = Task.Delay(20000); //10 seconds to decide CurrentUser = usr; - _currentUserMove = new(); + currentUserMove = new(); await PrintState(); // either wait for the user to make an action and // if he doesn't - stand - var finished = await Task.WhenAny(pause, _currentUserMove.Task); + var finished = await Task.WhenAny(pause, currentUserMove.Task); if (finished == pause) await Stand(usr); CurrentUser = null; - _currentUserMove = null; + currentUserMove = null; } public async Task Join(IUser user, long bet) @@ -156,7 +154,7 @@ public class Blackjack return false; u.State = User.UserState.Stand; - _currentUserMove.TrySetResult(true); + currentUserMove.TrySetResult(true); return true; } finally @@ -252,7 +250,7 @@ public class Blackjack else //with double you just get one card, and then you're done u.State = User.UserState.Stand; - _currentUserMove.TrySetResult(true); + currentUserMove.TrySetResult(true); return true; } @@ -292,7 +290,7 @@ public class Blackjack // user busted u.State = User.UserState.Bust; - _currentUserMove.TrySetResult(true); + currentUserMove.TrySetResult(true); return true; } diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs index 06d84917c..5111c5a70 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs @@ -59,7 +59,7 @@ public sealed class Connect4Game : IDisposable private readonly ICurrencyService _cs; private readonly NadekoRandom _rng; - private Timer _playerTimeoutTimer; + private Timer playerTimeoutTimer; /* [ ][ ][ ][ ][ ][ ] * [ ][ ][ ][ ][ ][ ] @@ -133,7 +133,7 @@ public sealed class Connect4Game : IDisposable } CurrentPhase = Phase.P1Move; //start the game - _playerTimeoutTimer = new(async _ => + playerTimeoutTimer = new(async _ => { await _locker.WaitAsync(); try @@ -330,7 +330,7 @@ public sealed class Connect4Game : IDisposable } private void ResetTimer() - => _playerTimeoutTimer.Change(TimeSpan.FromSeconds(_options.TurnTimer), + => playerTimeoutTimer.Change(TimeSpan.FromSeconds(_options.TurnTimer), TimeSpan.FromSeconds(_options.TurnTimer)); private void EndGame(Result result, ulong? winId) @@ -369,7 +369,7 @@ public sealed class Connect4Game : IDisposable OnGameFailedToStart = null; OnGameStateUpdated = null; OnGameEnded = null; - _playerTimeoutTimer?.Change(Timeout.Infinite, Timeout.Infinite); + playerTimeoutTimer?.Change(Timeout.Infinite, Timeout.Infinite); } diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs index 5a0ebcb04..7da075af5 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs @@ -11,19 +11,19 @@ public partial class Gambling [Group] public partial class Connect4Commands : GamblingSubmodule { - private static readonly string[] numbers = + private static readonly string[] _numbers = { ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:" }; private int RepostCounter { - get => _repostCounter; + get => repostCounter; set { if (value is < 0 or > 7) - _repostCounter = 0; - else _repostCounter = value; + repostCounter = 0; + else repostCounter = value; } } @@ -32,7 +32,7 @@ public partial class Gambling private IUserMessage msg; - private int _repostCounter; + private int repostCounter; public Connect4Commands(DiscordSocketClient client, ICurrencyService cs, GamblingConfigService gamb) : base(gamb) @@ -59,7 +59,7 @@ public partial class Gambling newGame.Dispose(); //means game already exists, try to join - var joined = await game.Join(ctx.User.Id, ctx.User.ToString(), options.Bet); + await game.Join(ctx.User.Id, ctx.User.ToString(), options.Bet); return; } @@ -73,9 +73,9 @@ public partial class Gambling } game.OnGameStateUpdated += Game_OnGameStateUpdated; - game.OnGameFailedToStart += Game_OnGameFailedToStart; - game.OnGameEnded += Game_OnGameEnded; - _client.MessageReceived += _client_MessageReceived; + game.OnGameFailedToStart += GameOnGameFailedToStart; + game.OnGameEnded += GameOnGameEnded; + _client.MessageReceived += ClientMessageReceived; game.Initialize(); if (options.Bet == 0) @@ -83,7 +83,7 @@ public partial class Gambling else await ReplyErrorLocalizedAsync(strs.connect4_created_bet(options.Bet + CurrencySign)); - Task _client_MessageReceived(SocketMessage arg) + Task ClientMessageReceived(SocketMessage arg) { if (ctx.Channel.Id != arg.Channel.Id) return Task.CompletedTask; @@ -110,22 +110,22 @@ public partial class Gambling return Task.CompletedTask; } - Task Game_OnGameFailedToStart(Connect4Game arg) + Task GameOnGameFailedToStart(Connect4Game arg) { if (_service.Connect4Games.TryRemove(ctx.Channel.Id, out var toDispose)) { - _client.MessageReceived -= _client_MessageReceived; + _client.MessageReceived -= ClientMessageReceived; toDispose.Dispose(); } return ErrorLocalizedAsync(strs.connect4_failed_to_start); } - Task Game_OnGameEnded(Connect4Game arg, Connect4Game.Result result) + Task GameOnGameEnded(Connect4Game arg, Connect4Game.Result result) { if (_service.Connect4Games.TryRemove(ctx.Channel.Id, out var toDispose)) { - _client.MessageReceived -= _client_MessageReceived; + _client.MessageReceived -= ClientMessageReceived; toDispose.Dispose(); } @@ -185,7 +185,7 @@ public partial class Gambling sb.AppendLine(); } - for (var i = 0; i < Connect4Game.NUMBER_OF_COLUMNS; i++) sb.Append(numbers[i]); + for (var i = 0; i < Connect4Game.NUMBER_OF_COLUMNS; i++) sb.Append(_numbers[i]); return sb.ToString(); } } diff --git a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs index 85874f2c1..20805ea65 100644 --- a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs @@ -11,10 +11,10 @@ public partial class Gambling [Group] public partial class DiceRollCommands : NadekoSubmodule { - private static readonly Regex dndRegex = new(@"^(?\d+)d(?\d+)(?:\+(?\d+))?(?:\-(?\d+))?$", + private static readonly Regex _dndRegex = new(@"^(?\d+)d(?\d+)(?:\+(?\d+))?(?:\-(?\d+))?$", RegexOptions.Compiled); - private static readonly Regex fudgeRegex = new(@"^(?\d+)d(?:F|f)$", RegexOptions.Compiled); + private static readonly Regex _fudgeRegex = new(@"^(?\d+)d(?:F|f)$", RegexOptions.Compiled); private static readonly char[] _fateRolls = { '-', ' ', '+' }; private readonly IImageCache _images; @@ -115,7 +115,7 @@ public partial class Gambling private async Task InternallDndRoll(string arg, bool ordered) { Match match; - if ((match = fudgeRegex.Match(arg)).Length != 0 + if ((match = _fudgeRegex.Match(arg)).Length != 0 && int.TryParse(match.Groups["n1"].ToString(), out var n1) && n1 is > 0 and < 500) { @@ -134,7 +134,7 @@ public partial class Gambling await ctx.Channel.EmbedAsync(embed); } - else if ((match = dndRegex.Match(arg)).Length != 0) + else if ((match = _dndRegex.Match(arg)).Length != 0) { var rng = new NadekoRandom(); if (int.TryParse(match.Groups["n1"].ToString(), out n1) diff --git a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs index 8323b7e85..6db0c00ff 100644 --- a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs @@ -117,7 +117,7 @@ public class GameStatusEvent : ICurrencyEvent private async Task OnMessageDeleted(Cacheable message, Cacheable cacheable) { - if (message.Id == this.msg.Id) await StopEvent(); + if (message.Id == msg.Id) await StopEvent(); } public async Task StopEvent() diff --git a/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs b/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs index b46ecd6fe..d4d9139f3 100644 --- a/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs @@ -99,11 +99,11 @@ public class ReactionEvent : ICurrencyEvent public async Task StartEvent() { if (Emote.TryParse(_config.Currency.Sign, out var parsedEmote)) - this.emote = parsedEmote; + emote = parsedEmote; else - this.emote = new Emoji(_config.Currency.Sign); + emote = new Emoji(_config.Currency.Sign); msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize)); - await msg.AddReactionAsync(this.emote); + await msg.AddReactionAsync(emote); _client.MessageDeleted += OnMessageDeleted; _client.ReactionAdded += HandleReaction; _t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); @@ -114,7 +114,7 @@ public class ReactionEvent : ICurrencyEvent private async Task OnMessageDeleted(Cacheable message, Cacheable cacheable) { - if (message.Id == this.msg.Id) await StopEvent(); + if (message.Id == msg.Id) await StopEvent(); } public async Task StopEvent() @@ -151,7 +151,7 @@ public class ReactionEvent : ICurrencyEvent if ((r.User.IsSpecified ? r.User.Value : null) is not IGuildUser gu // no unknown users, as they could be bots, or alts - || message.Id != this.msg.Id // same message + || message.Id != msg.Id // same message || gu.IsBot // no bots || (DateTime.UtcNow - gu.CreatedAt).TotalDays <= 5 // no recently created accounts || (_noRecentlyJoinedServer diff --git a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs index 797e29c97..a99acef57 100644 --- a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs @@ -22,7 +22,7 @@ public partial class Gambling Tails = 2 } - private static readonly NadekoRandom rng = new(); + private static readonly NadekoRandom _rng = new(); private readonly IImageCache _images; private readonly ICurrencyService _cs; @@ -47,9 +47,9 @@ public partial class Gambling var imgs = new Image[count]; for (var i = 0; i < count; i++) { - var headsArr = _images.Heads[rng.Next(0, _images.Heads.Count)]; - var tailsArr = _images.Tails[rng.Next(0, _images.Tails.Count)]; - if (rng.Next(0, 10) < 5) + var headsArr = _images.Heads[_rng.Next(0, _images.Heads.Count)]; + var tailsArr = _images.Tails[_rng.Next(0, _images.Tails.Count)]; + if (_rng.Next(0, 10) < 5) { imgs[i] = Image.Load(headsArr); headCount++; @@ -90,21 +90,21 @@ public partial class Gambling BetFlipGuess result; Uri imageToSend; var coins = _images.ImageUrls.Coins; - if (rng.Next(0, 1000) <= 499) + if (_rng.Next(0, 1000) <= 499) { - imageToSend = coins.Heads[rng.Next(0, coins.Heads.Length)]; + imageToSend = coins.Heads[_rng.Next(0, coins.Heads.Length)]; result = BetFlipGuess.Heads; } else { - imageToSend = coins.Tails[rng.Next(0, coins.Tails.Length)]; + imageToSend = coins.Tails[_rng.Next(0, coins.Tails.Length)]; result = BetFlipGuess.Tails; } string str; if (guess == result) { - var toWin = (long)(amount * _config.BetFlip.Multiplier); + var toWin = (long)(amount * Config.BetFlip.Multiplier); str = Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_guess(toWin + CurrencySign)); await _cs.AddAsync(ctx.User, "Betflip Gamble", toWin, false, true); } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 8b9ce9f65..4773c3156 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -100,8 +100,8 @@ public partial class Gambling : GamblingModule [Cmd] public async partial Task Timely() { - var val = _config.Timely.Amount; - var period = _config.Timely.Cooldown; + var val = Config.Timely.Amount; + var period = Config.Timely.Cooldown; if (val <= 0 || period <= 0) { await ReplyErrorLocalizedAsync(strs.timely_none); @@ -473,7 +473,7 @@ public partial class Gambling : GamblingModule return; } - var br = new Betroll(_config.BetRoll); + var br = new Betroll(Config.BetRoll); var result = br.Roll(); @@ -617,7 +617,7 @@ public partial class Gambling : GamblingModule || (pick == RpsPick.Rock && nadekoPick == RpsPick.Scissors) || (pick == RpsPick.Scissors && nadekoPick == RpsPick.Paper)) { - amount = (long)(amount * _config.BetFlip.Multiplier); + amount = (long)(amount * Config.BetFlip.Multiplier); await _cs.AddAsync(ctx.User.Id, "Rps-win", amount, true); embed.WithOkColor(); embed.AddField(GetText(strs.won), n(amount)); diff --git a/src/NadekoBot/Modules/Gambling/GamblingConfigService.cs b/src/NadekoBot/Modules/Gambling/GamblingConfigService.cs index e81391372..feb40e454 100644 --- a/src/NadekoBot/Modules/Gambling/GamblingConfigService.cs +++ b/src/NadekoBot/Modules/Gambling/GamblingConfigService.cs @@ -6,11 +6,12 @@ namespace NadekoBot.Modules.Gambling.Services; public sealed class GamblingConfigService : ConfigServiceBase { - private const string FilePath = "data/gambling.yml"; - private static readonly TypedKey changeKey = new("config.gambling.updated"); - public override string Name { get; } = "gambling"; + private const string FILE_PATH = "data/gambling.yml"; + private static readonly TypedKey _changeKey = new("config.gambling.updated"); + public override string Name + => "gambling"; - private readonly IEnumerable antiGiftSeed = new[] + private readonly IEnumerable _antiGiftSeed = new[] { new WaifuItemModel("πŸ₯€", 100, "WiltedRose", true), new WaifuItemModel("βœ‚οΈ", 1000, "Haircut", true), new WaifuItemModel("🧻", 10000, "ToiletPaper", true) @@ -18,7 +19,7 @@ public sealed class GamblingConfigService : ConfigServiceBase public GamblingConfigService(IConfigSeria serializer, IPubSub pubSub) - : base(FilePath, serializer, pubSub, changeKey) + : base(FILE_PATH, serializer, pubSub, _changeKey) { AddParsedProp("currency.name", gs => gs.Currency.Name, ConfigParsers.String, ConfigPrinters.ToString); AddParsedProp("currency.sign", gs => gs.Currency.Sign, ConfigParsers.String, ConfigPrinters.ToString); @@ -104,7 +105,7 @@ public sealed class GamblingConfigService : ConfigServiceBase if (data.Version < 2) ModifyConfig(c => { - c.Waifu.Items = c.Waifu.Items.Concat(antiGiftSeed).ToList(); + c.Waifu.Items = c.Waifu.Items.Concat(_antiGiftSeed).ToList(); c.Version = 2; }); diff --git a/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs b/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs index 9282f3ebe..f8c319748 100644 --- a/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs +++ b/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs @@ -5,14 +5,14 @@ namespace NadekoBot.Modules.Gambling.Common; public abstract class GamblingModule : NadekoModule { - protected GamblingConfig _config + protected GamblingConfig Config => _lazyConfig.Value; protected string CurrencySign - => _config.Currency.Sign; + => Config.Currency.Sign; protected string CurrencyName - => _config.Currency.Name; + => Config.Currency.Name; private readonly Lazy _lazyConfig; @@ -22,15 +22,15 @@ public abstract class GamblingModule : NadekoModule private async Task InternalCheckBet(long amount) { if (amount < 1) return false; - if (amount < _config.MinBet) + if (amount < Config.MinBet) { - await ReplyErrorLocalizedAsync(strs.min_bet_limit(Format.Bold(_config.MinBet.ToString()) + CurrencySign)); + await ReplyErrorLocalizedAsync(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)); return false; } - if (_config.MaxBet > 0 && amount > _config.MaxBet) + if (Config.MaxBet > 0 && amount > Config.MaxBet) { - await ReplyErrorLocalizedAsync(strs.max_bet_limit(Format.Bold(_config.MaxBet.ToString()) + CurrencySign)); + await ReplyErrorLocalizedAsync(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign)); return false; } diff --git a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs index 56e86a336..f5e56b1bc 100644 --- a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs @@ -9,11 +9,11 @@ public partial class Gambling [Group] public partial class PlantPickCommands : GamblingSubmodule { - private readonly ILogCommandService logService; + private readonly ILogCommandService _logService; public PlantPickCommands(ILogCommandService logService, GamblingConfigService gss) : base(gss) - => this.logService = logService; + => this._logService = logService; [Cmd] [RequireContext(ContextType.Guild)] @@ -32,7 +32,7 @@ public partial class Gambling if (((SocketGuild)ctx.Guild).CurrentUser.GuildPermissions.ManageMessages) try { - logService.AddDeleteIgnore(ctx.Message.Id); + _logService.AddDeleteIgnore(ctx.Message.Id); await ctx.Message.DeleteAsync(); } catch { } @@ -49,7 +49,7 @@ public partial class Gambling if (((SocketGuild)ctx.Guild).CurrentUser.GuildPermissions.ManageMessages) { - logService.AddDeleteIgnore(ctx.Message.Id); + _logService.AddDeleteIgnore(ctx.Message.Id); await ctx.Message.DeleteAsync(); } @@ -90,7 +90,7 @@ public partial class Gambling return ctx.SendPaginatedConfirmAsync(page, _ => { - var items = enabledIn.Skip(page * 9).Take(9); + var items = enabledIn.Skip(page * 9).Take(9).ToList(); if (!items.Any()) return _eb.Create().WithErrorColor().WithDescription("-"); diff --git a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs index 2b10abdb1..0a10a5b43 100644 --- a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs @@ -154,7 +154,7 @@ public partial class Gambling { await using (var uow = _db.GetDbContext()) { - var x = uow.Set().Remove(item); + uow.Set().Remove(item); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs index 96ad8db69..362aba756 100644 --- a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs @@ -18,8 +18,8 @@ public partial class Gambling [Group] public partial class SlotCommands : GamblingSubmodule { - private static long _totalBet; - private static long _totalPaidOut; + private static long totalBet; + private static long totalPaidOut; private static readonly HashSet _runningUsers = new(); @@ -28,7 +28,7 @@ public partial class Gambling //thanks to judge for helping me with this private readonly IImageCache _images; - private FontProvider _fonts; + private readonly FontProvider _fonts; private readonly DbService _db; public SlotCommands( @@ -51,8 +51,8 @@ public partial class Gambling public async partial Task SlotStats() { //i remembered to not be a moron - var paid = _totalPaidOut; - var bet = _totalBet; + var paid = totalPaidOut; + var bet = totalBet; if (bet <= 0) bet = 1; @@ -120,8 +120,8 @@ public partial class Gambling return; } - Interlocked.Add(ref _totalBet, amount); - Interlocked.Add(ref _totalPaidOut, result.Won); + Interlocked.Add(ref totalBet, amount); + Interlocked.Add(ref totalPaidOut, result.Won); long ownedAmount; await using (var uow = _db.GetDbContext()) @@ -130,12 +130,12 @@ public partial class Gambling ?? 0; } - using (var bgImage = Image.Load(_images.SlotBackground, out var format)) + using (var bgImage = Image.Load(_images.SlotBackground, out _)) { var numbers = new int[3]; result.Rolls.CopyTo(numbers, 0); - Color fontColor = _config.Slots.CurrencyFontColor; + Color fontColor = Config.Slots.CurrencyFontColor; bgImage.Mutate(x => x.DrawText(new() { diff --git a/src/NadekoBot/Modules/Gambling/VoteRewardService.cs b/src/NadekoBot/Modules/Gambling/VoteRewardService.cs index 936cfce30..9658fe1ad 100644 --- a/src/NadekoBot/Modules/Gambling/VoteRewardService.cs +++ b/src/NadekoBot/Modules/Gambling/VoteRewardService.cs @@ -100,7 +100,7 @@ public class VoteRewardService : INService, IReadyExecutor } catch (Exception ex) { - Log.Error(ex, "Critical error loading discords.com vote rewards."); + Log.Error(ex, "Critical error loading discords.com vote rewards"); } } } diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs index 0ea2e1df9..77b9dc16f 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs @@ -39,9 +39,9 @@ public partial class Gambling [RequireContext(ContextType.Guild)] public async partial Task WaifuClaim(int amount, [Leftover] IUser target) { - if (amount < _config.Waifu.MinPrice) + if (amount < Config.Waifu.MinPrice) { - await ReplyErrorLocalizedAsync(strs.waifu_isnt_cheap(_config.Waifu.MinPrice + CurrencySign)); + await ReplyErrorLocalizedAsync(strs.waifu_isnt_cheap(Config.Waifu.MinPrice + CurrencySign)); return; } @@ -278,7 +278,7 @@ public partial class Gambling [Priority(1)] public async partial Task WaifuGift(int page = 1) { - if (--page < 0 || page > (_config.Waifu.Items.Count - 1) / 9) + if (--page < 0 || page > (Config.Waifu.Items.Count - 1) / 9) return; var waifuItems = _service.GetWaifuItems(); @@ -294,7 +294,7 @@ public partial class Gambling .ToList() .ForEach(x => embed.AddField( $"{(!x.Negative ? string.Empty : "\\πŸ’”")} {x.ItemEmoji} {x.Name}", - Format.Bold(x.Price.ToString()) + _config.Currency.Sign, + Format.Bold(x.Price.ToString()) + Config.Currency.Sign, true)); return embed; diff --git a/src/NadekoBot/Modules/Gambling/Wheel/WheelOfFortuneCommands.cs b/src/NadekoBot/Modules/Gambling/Wheel/WheelOfFortuneCommands.cs index 55908e673..19ca587ba 100644 --- a/src/NadekoBot/Modules/Gambling/Wheel/WheelOfFortuneCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Wheel/WheelOfFortuneCommands.cs @@ -37,7 +37,7 @@ public partial class Gambling var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount); - var wofMultipliers = _config.WheelOfFortune.Multipliers; + var wofMultipliers = Config.WheelOfFortune.Multipliers; await SendConfirmAsync(Format.Bold($@"{ctx.User.ToString()} won: {result.Amount + CurrencySign} γ€Ž{wofMultipliers[1]}』 γ€Ž{wofMultipliers[0]}』 γ€Ž{wofMultipliers[7]}』 diff --git a/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs b/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs index 3cd00c796..fd7ec8dd0 100644 --- a/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs +++ b/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs @@ -28,7 +28,7 @@ public class Deck { 13, "King" } }; - private static Dictionary, bool>> _handValues; + private static Dictionary, bool>> handValues; public List CardPool { get; set; } private readonly Random _r = new NadekoRandom(); @@ -176,7 +176,7 @@ public class Deck return HasStraightFlush(cards) && !IsRoyalFlush(cards); } - _handValues = new() + handValues = new() { { "Royal Flush", IsRoyalFlush }, { "Straight Flush", IsStraightFlush }, @@ -192,9 +192,10 @@ public class Deck public static string GetHandValue(List cards) { - if (_handValues is null) + if (handValues is null) InitHandValues(); - foreach (var kvp in _handValues.Where(x => x.Value(cards))) return kvp.Key; + + foreach (var kvp in handValues.Where(x => x.Value(cards))) return kvp.Key; return "High card " + (cards.FirstOrDefault(c => c.Number == 1)?.GetValueText() ?? cards.Max().GetValueText()); } diff --git a/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs b/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs index 46e9e1db8..18475c080 100644 --- a/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs +++ b/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs @@ -38,8 +38,8 @@ public sealed class AcrophobiaGame : IDisposable public ImmutableArray StartingLetters { get; private set; } public Options Opts { get; } - private readonly Dictionary submissions = new(); - private readonly SemaphoreSlim locker = new(1, 1); + private readonly Dictionary _submissions = new(); + private readonly SemaphoreSlim _locker = new(1, 1); private readonly NadekoRandom _rng; private readonly HashSet _usersWhoVoted = new(); @@ -55,37 +55,37 @@ public sealed class AcrophobiaGame : IDisposable { await OnStarted(this); await Task.Delay(Opts.SubmissionTime * 1000); - await locker.WaitAsync(); + await _locker.WaitAsync(); try { - if (submissions.Count == 0) + if (_submissions.Count == 0) { CurrentPhase = Phase.Ended; await OnVotingStarted(this, ImmutableArray.Create>()); return; } - if (submissions.Count == 1) + if (_submissions.Count == 1) { CurrentPhase = Phase.Ended; - await OnVotingStarted(this, submissions.ToArray().ToImmutableArray()); + await OnVotingStarted(this, _submissions.ToArray().ToImmutableArray()); return; } CurrentPhase = Phase.Voting; - await OnVotingStarted(this, submissions.ToArray().ToImmutableArray()); + await OnVotingStarted(this, _submissions.ToArray().ToImmutableArray()); } - finally { locker.Release(); } + finally { _locker.Release(); } await Task.Delay(Opts.VoteTime * 1000); - await locker.WaitAsync(); + await _locker.WaitAsync(); try { CurrentPhase = Phase.Ended; - await OnEnded(this, submissions.ToArray().ToImmutableArray()); + await OnEnded(this, _submissions.ToArray().ToImmutableArray()); } - finally { locker.Release(); } + finally { _locker.Release(); } } private void InitializeStartingLetters() @@ -107,26 +107,26 @@ public sealed class AcrophobiaGame : IDisposable { var user = new AcrophobiaUser(userId, userName, input.ToLowerInvariant().ToTitleCase()); - await locker.WaitAsync(); + await _locker.WaitAsync(); try { switch (CurrentPhase) { case Phase.Submission: - if (submissions.ContainsKey(user) || !IsValidAnswer(input)) + if (_submissions.ContainsKey(user) || !IsValidAnswer(input)) break; - submissions.Add(user, 0); + _submissions.Add(user, 0); return true; case Phase.Voting: AcrophobiaUser toVoteFor; if (!int.TryParse(input, out var index) || --index < 0 - || index >= submissions.Count - || (toVoteFor = submissions.ToArray()[index].Key).UserId == user.UserId + || index >= _submissions.Count + || (toVoteFor = _submissions.ToArray()[index].Key).UserId == user.UserId || !_usersWhoVoted.Add(userId)) break; - ++submissions[toVoteFor]; + ++_submissions[toVoteFor]; _= Task.Run(() => OnUserVoted(userName)); return true; } @@ -135,7 +135,7 @@ public sealed class AcrophobiaGame : IDisposable } finally { - locker.Release(); + _locker.Release(); } } @@ -169,8 +169,8 @@ public sealed class AcrophobiaGame : IDisposable OnUserVoted = null; OnVotingStarted = null; _usersWhoVoted.Clear(); - submissions.Clear(); - locker.Dispose(); + _submissions.Clear(); + _locker.Dispose(); } public class Options : INadekoCommandOptions diff --git a/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs b/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs index 65d65fc94..7ceef0135 100644 --- a/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs +++ b/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs @@ -31,19 +31,19 @@ public partial class Games game.OnEnded += Game_OnEnded; game.OnVotingStarted += Game_OnVotingStarted; game.OnUserVoted += Game_OnUserVoted; - _client.MessageReceived += _client_MessageReceived; + _client.MessageReceived += ClientMessageReceived; await game.Run(); } finally { - _client.MessageReceived -= _client_MessageReceived; + _client.MessageReceived -= ClientMessageReceived; _service.AcrophobiaGames.TryRemove(channel.Id, out game); - game.Dispose(); + game?.Dispose(); } else await ReplyErrorLocalizedAsync(strs.acro_running); - Task _client_MessageReceived(SocketMessage msg) + Task ClientMessageReceived(SocketMessage msg) { if (msg.Channel.Id != ctx.Channel.Id) return Task.CompletedTask; diff --git a/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs b/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs index 0ea5567a1..1a917846d 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs @@ -48,7 +48,7 @@ public class ChatterBotService : IEarlyBehavior { if (!string.IsNullOrWhiteSpace(_creds.CleverbotApiKey)) return new OfficialCleverbotSession(_creds.CleverbotApiKey, _httpFactory); - return new CleverbotIOSession("GAh3wUfzDCpDpdpT", "RStKgqn7tcO9blbrv4KbXM8NDlb7H37C", _httpFactory); + return new CleverbotIoSession("GAh3wUfzDCpDpdpT", "RStKgqn7tcO9blbrv4KbXM8NDlb7H37C", _httpFactory); } public string PrepareMessage(IUserMessage msg, out IChatterBotSession cleverbot) diff --git a/src/NadekoBot/Modules/Games/ChatterBot/_Common/CleverbotResponse.cs b/src/NadekoBot/Modules/Games/ChatterBot/_Common/CleverbotResponse.cs index 9581ab73f..60b9eddda 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/_Common/CleverbotResponse.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/_Common/CleverbotResponse.cs @@ -7,13 +7,13 @@ public class CleverbotResponse public string Output { get; set; } } -public class CleverbotIOCreateResponse +public class CleverbotIoCreateResponse { public string Status { get; set; } public string Nick { get; set; } } -public class CleverbotIOAskResponse +public class CleverbotIoAskResponse { public string Status { get; set; } public string Response { get; set; } diff --git a/src/NadekoBot/Modules/Games/ChatterBot/_Common/OfficialCleverbotSession.cs b/src/NadekoBot/Modules/Games/ChatterBot/_Common/OfficialCleverbotSession.cs index 7343cbaed..1960f2343 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/_Common/OfficialCleverbotSession.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/_Common/OfficialCleverbotSession.cs @@ -10,7 +10,7 @@ public class OfficialCleverbotSession : IChatterBotSession private readonly string _apiKey; private readonly IHttpClientFactory _httpFactory; - private string _cs; + private string cs; public OfficialCleverbotSession(string apiKey, IHttpClientFactory factory) { @@ -21,12 +21,12 @@ public class OfficialCleverbotSession : IChatterBotSession public async Task Think(string input) { using var http = _httpFactory.CreateClient(); - var dataString = await http.GetStringAsync(string.Format(QueryString, input, _cs ?? "")); + var dataString = await http.GetStringAsync(string.Format(QueryString, input, cs ?? "")); try { var data = JsonConvert.DeserializeObject(dataString); - _cs = data?.Cs; + cs = data?.Cs; return data?.Output; } catch @@ -37,7 +37,7 @@ public class OfficialCleverbotSession : IChatterBotSession } } -public class CleverbotIOSession : IChatterBotSession +public class CleverbotIoSession : IChatterBotSession { private readonly string _key; private readonly string _user; @@ -47,7 +47,7 @@ public class CleverbotIOSession : IChatterBotSession private readonly string _createEndpoint = "https://cleverbot.io/1.0/create"; private readonly string _askEndpoint = "https://cleverbot.io/1.0/ask"; - public CleverbotIOSession(string user, string key, IHttpClientFactory factory) + public CleverbotIoSession(string user, string key, IHttpClientFactory factory) { _key = key; _user = user; @@ -58,14 +58,14 @@ public class CleverbotIOSession : IChatterBotSession private async Task GetNick() { - using var _http = _httpFactory.CreateClient(); + using var http = _httpFactory.CreateClient(); using var msg = new FormUrlEncodedContent(new[] { new KeyValuePair("user", _user), new KeyValuePair("key", _key) }); - using var data = await _http.PostAsync(_createEndpoint, msg); + using var data = await http.PostAsync(_createEndpoint, msg); var str = await data.Content.ReadAsStringAsync(); - var obj = JsonConvert.DeserializeObject(str); + var obj = JsonConvert.DeserializeObject(str); if (obj.Status != "success") throw new OperationCanceledException(obj.Status); @@ -74,15 +74,15 @@ public class CleverbotIOSession : IChatterBotSession public async Task Think(string input) { - using var _http = _httpFactory.CreateClient(); + using var http = _httpFactory.CreateClient(); using var msg = new FormUrlEncodedContent(new[] { new KeyValuePair("user", _user), new KeyValuePair("key", _key), new KeyValuePair("nick", await _nick), new KeyValuePair("text", input) }); - using var data = await _http.PostAsync(_askEndpoint, msg); + using var data = await http.PostAsync(_askEndpoint, msg); var str = await data.Content.ReadAsStringAsync(); - var obj = JsonConvert.DeserializeObject(str); + var obj = JsonConvert.DeserializeObject(str); if (obj.Status != "success") throw new OperationCanceledException(obj.Status); diff --git a/src/NadekoBot/Modules/Games/GamesConfigService.cs b/src/NadekoBot/Modules/Games/GamesConfigService.cs index 4984abbad..6041fb7d8 100644 --- a/src/NadekoBot/Modules/Games/GamesConfigService.cs +++ b/src/NadekoBot/Modules/Games/GamesConfigService.cs @@ -6,12 +6,12 @@ namespace NadekoBot.Modules.Games.Services; public sealed class GamesConfigService : ConfigServiceBase { - private const string FilePath = "data/games.yml"; - private static readonly TypedKey changeKey = new("config.games.updated"); + private const string FILE_PATH = "data/games.yml"; + private static readonly TypedKey _changeKey = new("config.games.updated"); public override string Name { get; } = "games"; public GamesConfigService(IConfigSeria serializer, IPubSub pubSub) - : base(FilePath, serializer, pubSub, changeKey) + : base(FILE_PATH, serializer, pubSub, _changeKey) { AddParsedProp("trivia.min_win_req", gs => gs.Trivia.MinimumWinReq, diff --git a/src/NadekoBot/Modules/Games/GamesService.cs b/src/NadekoBot/Modules/Games/GamesService.cs index 5fd52d761..fcf859f61 100644 --- a/src/NadekoBot/Modules/Games/GamesService.cs +++ b/src/NadekoBot/Modules/Games/GamesService.cs @@ -10,7 +10,7 @@ namespace NadekoBot.Modules.Games.Services; public class GamesService : INService { - private const string TypingArticlesPath = "data/typing_articles3.json"; + private const string TYPING_ARTICLES_PATH = "data/typing_articles3.json"; public ConcurrentDictionary GirlRatings { get; } = new(); @@ -54,11 +54,11 @@ public class GamesService : INService try { - TypingArticles = JsonConvert.DeserializeObject>(File.ReadAllText(TypingArticlesPath)); + TypingArticles = JsonConvert.DeserializeObject>(File.ReadAllText(TYPING_ARTICLES_PATH)); } catch (Exception ex) { - Log.Warning("Error while loading typing articles {0}", ex.ToString()); + Log.Warning(ex, "Error while loading typing articles: {ErrorMessage}", ex.Message); TypingArticles = new(); } } @@ -80,7 +80,7 @@ public class GamesService : INService Text = text.SanitizeMentions(true) }); - File.WriteAllText(TypingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); + File.WriteAllText(TYPING_ARTICLES_PATH, JsonConvert.SerializeObject(TypingArticles)); } public string GetEightballResponse(ulong userId, string question) @@ -90,7 +90,6 @@ public class GamesService : INService e.Size = question.Length; e.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(12); return EightBallResponses[_rng.Next(0, EightBallResponses.Count)]; - ; }); public TypingArticle RemoveTypingArticle(int index) @@ -102,7 +101,7 @@ public class GamesService : INService var removed = articles[index]; TypingArticles.RemoveAt(index); - File.WriteAllText(TypingArticlesPath, JsonConvert.SerializeObject(articles)); + File.WriteAllText(TYPING_ARTICLES_PATH, JsonConvert.SerializeObject(articles)); return removed; } diff --git a/src/NadekoBot/Modules/Games/GirlRating.cs b/src/NadekoBot/Modules/Games/GirlRating.cs index 23db54f78..163a39863 100644 --- a/src/NadekoBot/Modules/Games/GirlRating.cs +++ b/src/NadekoBot/Modules/Games/GirlRating.cs @@ -15,11 +15,8 @@ public class GirlRating public AsyncLazy Stream { get; } private readonly IImageCache _images; - private readonly IHttpClientFactory _httpFactory; - public GirlRating( IImageCache images, - IHttpClientFactory factory, double crazy, double hot, int roll, @@ -30,7 +27,6 @@ public class GirlRating Hot = hot; Roll = roll; Advice = advice; // convenient to have it here, even though atm there are only few different ones. - _httpFactory = factory; Stream = new(() => { diff --git a/src/NadekoBot/Modules/Games/Hangman/DefaultHangmanSource.cs b/src/NadekoBot/Modules/Games/Hangman/DefaultHangmanSource.cs index 81c47e674..ee1ec387a 100644 --- a/src/NadekoBot/Modules/Games/Hangman/DefaultHangmanSource.cs +++ b/src/NadekoBot/Modules/Games/Hangman/DefaultHangmanSource.cs @@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Games.Hangman; public sealed class DefaultHangmanSource : IHangmanSource { - private IReadOnlyDictionary _terms = new Dictionary(); + private IReadOnlyDictionary termsDict = new Dictionary(); private readonly Random _rng; public DefaultHangmanSource() @@ -18,7 +18,7 @@ public sealed class DefaultHangmanSource : IHangmanSource { if (!Directory.Exists("data/hangman")) { - Log.Error("Hangman game won't work. Folder 'data/hangman' is missing."); + Log.Error("Hangman game won't work. Folder 'data/hangman' is missing"); return; } @@ -31,16 +31,16 @@ public sealed class DefaultHangmanSource : IHangmanSource } catch (Exception ex) { - Log.Error(ex, "Loading {HangmanFile} failed.", file); + Log.Error(ex, "Loading {HangmanFile} failed", file); } - _terms = qs; + termsDict = qs; - Log.Information("Loaded {HangmanCategoryCount} hangman categories.", qs.Count); + Log.Information("Loaded {HangmanCategoryCount} hangman categories", qs.Count); } public IReadOnlyCollection GetCategories() - => _terms.Keys.ToList(); + => termsDict.Keys.ToList(); public bool GetTerm(string? category, [NotNullWhen(true)] out HangmanTerm? term) { @@ -50,7 +50,7 @@ public sealed class DefaultHangmanSource : IHangmanSource category = cats.ElementAt(_rng.Next(0, cats.Count)); } - if (_terms.TryGetValue(category, out var terms)) + if (termsDict.TryGetValue(category, out var terms)) { term = terms[_rng.Next(0, terms.Length)]; return true; diff --git a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs index b8730a199..58ee38ba5 100644 --- a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs @@ -28,19 +28,19 @@ public partial class Games .WithOkColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) - .WithFooter(state.missedLetters.Join(' ')); + .WithFooter(state.MissedLetters.Join(' ')); if (state.Phase == HangmanGame.Phase.Ended && state.Failed) return eb.Create() .WithErrorColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) - .WithFooter(state.missedLetters.Join(' ')); + .WithFooter(state.MissedLetters.Join(' ')); return eb.Create() .WithOkColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) - .WithFooter(state.missedLetters.Join(' ')); + .WithFooter(state.MissedLetters.Join(' ')); } [Cmd] diff --git a/src/NadekoBot/Modules/Games/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Hangman/HangmanGame.cs index 61651a6cd..e878687fd 100644 --- a/src/NadekoBot/Modules/Games/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Hangman/HangmanGame.cs @@ -104,7 +104,7 @@ public sealed class HangmanGame Phase Phase, string Word, GuessResult GuessResult, - List missedLetters, + List MissedLetters, string ImageUrl) { public bool Failed diff --git a/src/NadekoBot/Modules/Games/Hangman/HangmanService.cs b/src/NadekoBot/Modules/Games/Hangman/HangmanService.cs index e07a3156f..e379affb8 100644 --- a/src/NadekoBot/Modules/Games/Hangman/HangmanService.cs +++ b/src/NadekoBot/Modules/Games/Hangman/HangmanService.cs @@ -54,7 +54,7 @@ public sealed class HangmanService : IHangmanService, ILateExecutor { lock (_locker) { - if (_hangmanGames.TryRemove(channelId, out var game)) return new(true); + if (_hangmanGames.TryRemove(channelId, out _)) return new(true); } return new(false); diff --git a/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs b/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs index f7757ec55..4f7763dd9 100644 --- a/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs +++ b/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs @@ -13,8 +13,8 @@ public sealed class NunchiGame : IDisposable Ended } - private const int _killTimeout = 20 * 1000; - private const int _nextRoundTimeout = 5 * 1000; + private const int KILL_TIMEOUT = 20 * 1000; + private const int NEXT_ROUND_TIMEOUT = 5 * 1000; public event Func OnGameStarted; public event Func OnRoundStarted; @@ -26,19 +26,19 @@ public sealed class NunchiGame : IDisposable public Phase CurrentPhase { get; private set; } = Phase.Joining; public ImmutableArray<(ulong Id, string Name)> Participants - => _participants.ToImmutableArray(); + => participants.ToImmutableArray(); public int ParticipantCount - => _participants.Count; + => participants.Count; private readonly SemaphoreSlim _locker = new(1, 1); - private HashSet<(ulong Id, string Name)> _participants = new(); + private HashSet<(ulong Id, string Name)> participants = new(); private readonly HashSet<(ulong Id, string Name)> _passed = new(); - private Timer _killTimer; + private Timer killTimer; public NunchiGame(ulong creatorId, string creatorName) - => _participants.Add((creatorId, creatorName)); + => participants.Add((creatorId, creatorName)); public async Task Join(ulong userId, string userName) { @@ -48,7 +48,7 @@ public sealed class NunchiGame : IDisposable if (CurrentPhase != Phase.Joining) return false; - return _participants.Add((userId, userName)); + return participants.Add((userId, userName)); } finally { _locker.Release(); } } @@ -60,13 +60,13 @@ public sealed class NunchiGame : IDisposable await _locker.WaitAsync(); try { - if (_participants.Count < 3) + if (participants.Count < 3) { CurrentPhase = Phase.Ended; return false; } - _killTimer = new(async _ => + killTimer = new(async _ => { await _locker.WaitAsync(); try @@ -75,14 +75,14 @@ public sealed class NunchiGame : IDisposable return; //if some players took too long to type a number, boot them all out and start a new round - _participants = new HashSet<(ulong, string)>(_passed); + participants = new HashSet<(ulong, string)>(_passed); EndRound(); } finally { _locker.Release(); } }, null, - _killTimeout, - _killTimeout); + KILL_TIMEOUT, + KILL_TIMEOUT); CurrentPhase = Phase.Playing; _= OnGameStarted?.Invoke(this); @@ -105,7 +105,7 @@ public sealed class NunchiGame : IDisposable // if the user is not a member of the race, // or he already successfully typed the number // ignore the input - if (!_participants.Contains(userTuple) || !_passed.Add(userTuple)) + if (!participants.Contains(userTuple) || !_passed.Add(userTuple)) return; //if the number is correct @@ -113,20 +113,20 @@ public sealed class NunchiGame : IDisposable { //increment current number ++CurrentNumber; - if (_passed.Count == _participants.Count - 1) + if (_passed.Count == participants.Count - 1) { // if only n players are left, and n - 1 type the correct number, round is over // if only 2 players are left, game is over - if (_participants.Count == 2) + if (participants.Count == 2) { - _killTimer.Change(Timeout.Infinite, Timeout.Infinite); + killTimer.Change(Timeout.Infinite, Timeout.Infinite); CurrentPhase = Phase.Ended; _= OnGameEnded?.Invoke(this, userTuple.Name); } else // else just start the new round without the user who was the last { - var failure = _participants.Except(_passed).First(); + var failure = participants.Except(_passed).First(); OnUserGuessed?.Invoke(this); EndRound(failure); @@ -148,25 +148,25 @@ public sealed class NunchiGame : IDisposable private void EndRound((ulong, string)? failure = null) { - _killTimer.Change(_killTimeout, _killTimeout); + killTimer.Change(KILL_TIMEOUT, KILL_TIMEOUT); CurrentNumber = new NadekoRandom().Next(0, 100); // reset the counter _passed.Clear(); // reset all users who passed (new round starts) if (failure is not null) - _participants.Remove(failure.Value); // remove the dude who failed from the list of players + participants.Remove(failure.Value); // remove the dude who failed from the list of players var __ = OnRoundEnded?.Invoke(this, failure); - if (_participants.Count <= 1) // means we have a winner or everyone was booted out + if (participants.Count <= 1) // means we have a winner or everyone was booted out { - _killTimer.Change(Timeout.Infinite, Timeout.Infinite); + killTimer.Change(Timeout.Infinite, Timeout.Infinite); CurrentPhase = Phase.Ended; - _= OnGameEnded?.Invoke(this, _participants.Count > 0 ? _participants.First().Name : null); + _= OnGameEnded?.Invoke(this, participants.Count > 0 ? participants.First().Name : null); return; } CurrentPhase = Phase.WaitingForNextRound; var throwawayDelay = Task.Run(async () => { - await Task.Delay(_nextRoundTimeout); + await Task.Delay(NEXT_ROUND_TIMEOUT); CurrentPhase = Phase.Playing; var ___ = OnRoundStarted?.Invoke(this, CurrentNumber); }); diff --git a/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs b/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs index d99d005d1..11edb8c61 100644 --- a/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs +++ b/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs @@ -38,12 +38,12 @@ public partial class Games try { await ConfirmLocalizedAsync(strs.nunchi_created); } catch { } - nunchi.OnGameEnded += Nunchi_OnGameEnded; + nunchi.OnGameEnded += NunchiOnGameEnded; //nunchi.OnGameStarted += Nunchi_OnGameStarted; nunchi.OnRoundEnded += Nunchi_OnRoundEnded; nunchi.OnUserGuessed += Nunchi_OnUserGuessed; nunchi.OnRoundStarted += Nunchi_OnRoundStarted; - _client.MessageReceived += _client_MessageReceived; + _client.MessageReceived += ClientMessageReceived; var success = await nunchi.Initialize(); if (!success) @@ -53,7 +53,7 @@ public partial class Games await ConfirmLocalizedAsync(strs.nunchi_failed_to_start); } - Task _client_MessageReceived(SocketMessage arg) + Task ClientMessageReceived(SocketMessage arg) { _= Task.Run(async () => { @@ -73,11 +73,11 @@ public partial class Games return Task.CompletedTask; } - Task Nunchi_OnGameEnded(NunchiGame arg1, string arg2) + Task NunchiOnGameEnded(NunchiGame arg1, string arg2) { if (_service.NunchiGames.TryRemove(ctx.Guild.Id, out var game)) { - _client.MessageReceived -= _client_MessageReceived; + _client.MessageReceived -= ClientMessageReceived; game.Dispose(); } diff --git a/src/NadekoBot/Modules/Games/Polls/PollCommands.cs b/src/NadekoBot/Modules/Games/Polls/PollCommands.cs index e59db3f97..3efef1469 100644 --- a/src/NadekoBot/Modules/Games/Polls/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Polls/PollCommands.cs @@ -90,8 +90,8 @@ public partial class Games for (var i = 0; i < stats.Length; i++) { - var (Index, votes, Text) = stats[i]; - sb.AppendLine(GetText(strs.poll_result(Index + 1, Format.Bold(Text), Format.Bold(votes.ToString())))); + var (index, votes, text) = stats[i]; + sb.AppendLine(GetText(strs.poll_result(index + 1, Format.Bold(text), Format.Bold(votes.ToString())))); } return eb.WithDescription(sb.ToString()) diff --git a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs index 063972804..14e6b3fcf 100644 --- a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs @@ -10,19 +10,19 @@ public class TicTacToe private readonly ITextChannel _channel; private readonly IGuildUser[] _users; private readonly int?[,] _state; - private Phase _phase; - private int _curUserIndex; + private Phase phase; + private int curUserIndex; private readonly SemaphoreSlim _moveLock; - private IGuildUser _winner; + private IGuildUser winner; private readonly string[] _numbers = { ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:" }; - private IUserMessage _previousMessage; - private Timer _timeoutTimer; + private IUserMessage previousMessage; + private Timer timeoutTimer; private readonly IBotStrings _strings; private readonly DiscordSocketClient _client; private readonly Options _options; @@ -45,7 +45,7 @@ public class TicTacToe _users = new[] { firstUser, null }; _state = new int?[,] { { null, null, null }, { null, null, null }, { null, null, null } }; - _phase = Phase.Starting; + phase = Phase.Starting; _moveLock = new(1, 1); } @@ -81,16 +81,16 @@ public class TicTacToe if (!string.IsNullOrWhiteSpace(title)) embed.WithTitle(title); - if (_winner is null) + if (winner is null) { - if (_phase == Phase.Ended) + if (phase == Phase.Ended) embed.WithFooter(GetText(strs.ttt_no_moves)); else - embed.WithFooter(GetText(strs.ttt_users_move(_users[_curUserIndex]))); + embed.WithFooter(GetText(strs.ttt_users_move(_users[curUserIndex]))); } else { - embed.WithFooter(GetText(strs.ttt_has_won(_winner))); + embed.WithFooter(GetText(strs.ttt_has_won(winner))); } return embed; @@ -115,7 +115,7 @@ public class TicTacToe public async Task Start(IGuildUser user) { - if (_phase is Phase.Started or Phase.Ended) + if (phase is Phase.Started or Phase.Ended) { await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)); return; @@ -129,21 +129,21 @@ public class TicTacToe _users[1] = user; - _phase = Phase.Started; + phase = Phase.Started; - _timeoutTimer = new(async _ => + timeoutTimer = new(async _ => { await _moveLock.WaitAsync(); try { - if (_phase == Phase.Ended) + if (phase == Phase.Ended) return; - _phase = Phase.Ended; + phase = Phase.Ended; if (_users[1] is not null) { - _winner = _users[_curUserIndex ^= 1]; - var del = _previousMessage?.DeleteAsync(); + winner = _users[curUserIndex ^= 1]; + var del = previousMessage?.DeleteAsync(); try { await _channel.EmbedAsync(GetEmbed(GetText(strs.ttt_time_expired))); @@ -168,7 +168,7 @@ public class TicTacToe _client.MessageReceived += Client_MessageReceived; - _previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started))); + previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started))); } private bool IsDraw() @@ -187,8 +187,8 @@ public class TicTacToe await _moveLock.WaitAsync(); try { - var curUser = _users[_curUserIndex]; - if (_phase == Phase.Ended || msg.Author?.Id != curUser.Id) + var curUser = _users[curUserIndex]; + if (phase == Phase.Ended || msg.Author?.Id != curUser.Id) return; if (int.TryParse(msg.Content, out var index) @@ -196,69 +196,69 @@ public class TicTacToe && index <= 9 && _state[index / 3, index % 3] is null) { - _state[index / 3, index % 3] = _curUserIndex; + _state[index / 3, index % 3] = curUserIndex; // i'm lazy if (_state[index / 3, 0] == _state[index / 3, 1] && _state[index / 3, 1] == _state[index / 3, 2]) { - _state[index / 3, 0] = _curUserIndex + 2; - _state[index / 3, 1] = _curUserIndex + 2; - _state[index / 3, 2] = _curUserIndex + 2; + _state[index / 3, 0] = curUserIndex + 2; + _state[index / 3, 1] = curUserIndex + 2; + _state[index / 3, 2] = curUserIndex + 2; - _phase = Phase.Ended; + phase = Phase.Ended; } else if (_state[0, index % 3] == _state[1, index % 3] && _state[1, index % 3] == _state[2, index % 3]) { - _state[0, index % 3] = _curUserIndex + 2; - _state[1, index % 3] = _curUserIndex + 2; - _state[2, index % 3] = _curUserIndex + 2; + _state[0, index % 3] = curUserIndex + 2; + _state[1, index % 3] = curUserIndex + 2; + _state[2, index % 3] = curUserIndex + 2; - _phase = Phase.Ended; + phase = Phase.Ended; } - else if (_curUserIndex == _state[0, 0] + else if (curUserIndex == _state[0, 0] && _state[0, 0] == _state[1, 1] && _state[1, 1] == _state[2, 2]) { - _state[0, 0] = _curUserIndex + 2; - _state[1, 1] = _curUserIndex + 2; - _state[2, 2] = _curUserIndex + 2; + _state[0, 0] = curUserIndex + 2; + _state[1, 1] = curUserIndex + 2; + _state[2, 2] = curUserIndex + 2; - _phase = Phase.Ended; + phase = Phase.Ended; } - else if (_curUserIndex == _state[0, 2] + else if (curUserIndex == _state[0, 2] && _state[0, 2] == _state[1, 1] && _state[1, 1] == _state[2, 0]) { - _state[0, 2] = _curUserIndex + 2; - _state[1, 1] = _curUserIndex + 2; - _state[2, 0] = _curUserIndex + 2; + _state[0, 2] = curUserIndex + 2; + _state[1, 1] = curUserIndex + 2; + _state[2, 0] = curUserIndex + 2; - _phase = Phase.Ended; + phase = Phase.Ended; } var reason = string.Empty; - if (_phase == Phase.Ended) // if user won, stop receiving moves + if (phase == Phase.Ended) // if user won, stop receiving moves { reason = GetText(strs.ttt_matched_three); - _winner = _users[_curUserIndex]; + winner = _users[curUserIndex]; _client.MessageReceived -= Client_MessageReceived; OnEnded?.Invoke(this); } else if (IsDraw()) { reason = GetText(strs.ttt_a_draw); - _phase = Phase.Ended; + phase = Phase.Ended; _client.MessageReceived -= Client_MessageReceived; OnEnded?.Invoke(this); } - var sendstate = Task.Run(async () => + _ = Task.Run(async () => { var del1 = msg.DeleteAsync(); - var del2 = _previousMessage?.DeleteAsync(); - try { _previousMessage = await _channel.EmbedAsync(GetEmbed(reason)); } + var del2 = previousMessage?.DeleteAsync(); + try { previousMessage = await _channel.EmbedAsync(GetEmbed(reason)); } catch { } try { await del1; } @@ -270,9 +270,9 @@ public class TicTacToe } catch { } }); - _curUserIndex ^= 1; + curUserIndex ^= 1; - _timeoutTimer.Change(_options.TurnTimer * 1000, Timeout.Infinite); + timeoutTimer.Change(_options.TurnTimer * 1000, Timeout.Infinite); } } finally diff --git a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs index 26f7d7bf5..8f75e5689 100644 --- a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs +++ b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs @@ -6,10 +6,10 @@ namespace NadekoBot.Modules.Games.Common.Trivia; public class TriviaQuestion { - public const int maxStringLength = 22; + public const int MAX_STRING_LENGTH = 22; //represents the min size to judge levDistance with - private static readonly HashSet> strictness = new() + private static readonly HashSet> _strictness = new() { new(9, 0), new(14, 1), new(19, 2), new(22, 3) }; @@ -56,7 +56,7 @@ public class TriviaQuestion private static bool JudgeGuess(int guessLength, int answerLength, int levDistance) { - foreach (var level in strictness) + foreach (var level in _strictness) if (guessLength <= level.Item1 || answerLength <= level.Item1) { if (levDistance <= level.Item2) @@ -78,7 +78,7 @@ public class TriviaQuestion str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); //Trim the really long answers - str = str.Length <= maxStringLength ? str : str[..maxStringLength]; + str = str.Length <= MAX_STRING_LENGTH ? str : str[..MAX_STRING_LENGTH]; return str; } diff --git a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestionPool.cs b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestionPool.cs index 981b6d3b2..865eb6aed 100644 --- a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestionPool.cs +++ b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestionPool.cs @@ -10,14 +10,14 @@ public class TriviaQuestionPool => _cache.LocalData.PokemonMap; private readonly IDataCache _cache; - private readonly int maxPokemonId; + private readonly int _maxPokemonId; private readonly NadekoRandom _rng = new(); public TriviaQuestionPool(IDataCache cache) { _cache = cache; - maxPokemonId = 721; //xd + _maxPokemonId = 721; //xd } public TriviaQuestion GetRandomQuestion(HashSet exclude, bool isPokemon) @@ -27,7 +27,7 @@ public class TriviaQuestionPool if (isPokemon) { - var num = _rng.Next(1, maxPokemonId + 1); + var num = _rng.Next(1, _maxPokemonId + 1); return new("Who's That PokΓ©mon?", Map[num].ToTitleCase(), "Pokemon", @@ -36,7 +36,15 @@ public class TriviaQuestionPool } TriviaQuestion randomQuestion; - while (exclude.Contains(randomQuestion = Pool[_rng.Next(0, Pool.Length)])) ; + while (exclude.Contains(randomQuestion = Pool[_rng.Next(0, Pool.Length)])) + { + // if too many questions are excluded, clear the exclusion list and start over + if (exclude.Count > Pool.Length / 10 * 9) + { + exclude.Clear(); + break; + } + } return randomQuestion; } diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index d4fbc89bd..25af56c9b 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -16,15 +16,15 @@ public sealed partial class Music : NadekoModule Q = 2, Queue = 2, Playlist = 2, Pl = 2 } - public const string MusicIconUrl = "http://i.imgur.com/nhKS3PT.png"; + public const string MUSIC_ICON_URL = "http://i.imgur.com/nhKS3PT.png"; private const int LQ_ITEMS_PER_PAGE = 9; - private static readonly SemaphoreSlim voiceChannelLock = new(1, 1); + private static readonly SemaphoreSlim _voiceChannelLock = new(1, 1); private readonly ILogCommandService _logService; - public Music(ILogCommandService _logService) - => this._logService = _logService; + public Music(ILogCommandService logService) + => _logService = logService; private async Task ValidateAsync() { @@ -50,7 +50,7 @@ public sealed partial class Music : NadekoModule private async Task EnsureBotInVoiceChannelAsync(ulong voiceChannelId, IGuildUser botUser = null) { botUser ??= await ctx.Guild.GetCurrentUserAsync(); - await voiceChannelLock.WaitAsync(); + await _voiceChannelLock.WaitAsync(); try { if (botUser.VoiceChannel?.Id is null || !_service.TryGetMusicPlayer(ctx.Guild.Id, out _)) @@ -58,7 +58,7 @@ public sealed partial class Music : NadekoModule } finally { - voiceChannelLock.Release(); + _voiceChannelLock.Release(); } } @@ -111,7 +111,7 @@ public sealed partial class Music : NadekoModule { var embed = _eb.Create() .WithOkColor() - .WithAuthor(GetText(strs.queued_song) + " #" + (index + 1), MusicIconUrl) + .WithAuthor(GetText(strs.queued_song) + " #" + (index + 1), MUSIC_ICON_URL) .WithDescription($"{trackInfo.PrettyName()}\n{GetText(strs.queue)} ") .WithFooter(trackInfo.Platform.ToString()); @@ -272,7 +272,7 @@ public sealed partial class Music : NadekoModule return; } - IEmbedBuilder printAction(int curPage) + IEmbedBuilder PrintAction(int curPage) { var desc = string.Empty; var current = mp.GetCurrentTrack(out var currentIndex); @@ -317,7 +317,7 @@ public sealed partial class Music : NadekoModule var embed = _eb.Create() .WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)), - MusicIconUrl) + MUSIC_ICON_URL) .WithDescription(desc) .WithFooter($" {mp.PrettyVolume()} | 🎢 {tracks.Count} | βŒ› {mp.PrettyTotalTime()} ") .WithOkColor(); @@ -325,7 +325,7 @@ public sealed partial class Music : NadekoModule return embed; } - await ctx.SendPaginatedConfirmAsync(page, printAction, tracks.Count, LQ_ITEMS_PER_PAGE, false); + await ctx.SendPaginatedConfirmAsync(page, PrintAction, tracks.Count, LQ_ITEMS_PER_PAGE, false); } // search @@ -409,7 +409,7 @@ public sealed partial class Music : NadekoModule } var embed = _eb.Create() - .WithAuthor(GetText(strs.removed_song) + " #" + index, MusicIconUrl) + .WithAuthor(GetText(strs.removed_song) + " #" + index, MUSIC_ICON_URL) .WithDescription(song.PrettyName()) .WithFooter(song.PrettyInfo()) .WithErrorColor(); @@ -578,7 +578,7 @@ public sealed partial class Music : NadekoModule var embed = _eb.Create() .WithTitle(track.Title.TrimTo(65)) - .WithAuthor(GetText(strs.song_moved), MusicIconUrl) + .WithAuthor(GetText(strs.song_moved), MUSIC_ICON_URL) .AddField(GetText(strs.from_position), $"#{from + 1}", true) .AddField(GetText(strs.to_position), $"#{to + 1}", true) .WithOkColor(); @@ -667,7 +667,7 @@ public sealed partial class Music : NadekoModule var embed = _eb.Create() .WithOkColor() - .WithAuthor(GetText(strs.now_playing), MusicIconUrl) + .WithAuthor(GetText(strs.now_playing), MUSIC_ICON_URL) .WithDescription(currentTrack.PrettyName()) .WithThumbnailUrl(currentTrack.Thumbnail) .WithFooter( diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index 5931c558c..6ad262b27 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -23,7 +23,7 @@ public sealed partial class Music private async Task EnsureBotInVoiceChannelAsync(ulong voiceChannelId, IGuildUser botUser = null) { botUser ??= await ctx.Guild.GetCurrentUserAsync(); - await voiceChannelLock.WaitAsync(); + await _voiceChannelLock.WaitAsync(); try { if (botUser.VoiceChannel?.Id is null || !_service.TryGetMusicPlayer(ctx.Guild.Id, out _)) @@ -31,7 +31,7 @@ public sealed partial class Music } finally { - voiceChannelLock.Release(); + _voiceChannelLock.Release(); } } @@ -50,7 +50,7 @@ public sealed partial class Music } var embed = _eb.Create(ctx) - .WithAuthor(GetText(strs.playlists_page(num)), MusicIconUrl) + .WithAuthor(GetText(strs.playlists_page(num)), MUSIC_ICON_URL) .WithDescription(string.Join("\n", playlists.Select(r => GetText(strs.playlists(r.Id, r.Name, r.Author, r.Songs.Count))))) .WithOkColor(); diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index dd2439164..ca4258f63 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -189,7 +189,7 @@ public sealed class MusicService : IMusicService _ = lastFinishedMessage?.DeleteAsync(); var embed = _eb.Create() .WithOkColor() - .WithAuthor(GetText(guildId, strs.finished_song), Music.MusicIconUrl) + .WithAuthor(GetText(guildId, strs.finished_song), Music.MUSIC_ICON_URL) .WithDescription(trackInfo.PrettyName()) .WithFooter(trackInfo.PrettyTotalTime()); @@ -205,7 +205,7 @@ public sealed class MusicService : IMusicService _ = lastPlayingMessage?.DeleteAsync(); var embed = _eb.Create() .WithOkColor() - .WithAuthor(GetText(guildId, strs.playing_song(index + 1)), Music.MusicIconUrl) + .WithAuthor(GetText(guildId, strs.playing_song(index + 1)), Music.MUSIC_ICON_URL) .WithDescription(trackInfo.PrettyName()) .WithFooter($"{mp.PrettyVolume()} | {trackInfo.PrettyInfo()}"); diff --git a/src/NadekoBot/Modules/Music/_Common/Impl/MultimediaTimer.cs b/src/NadekoBot/Modules/Music/_Common/Impl/MultimediaTimer.cs index 9809232d8..4ee55d445 100644 --- a/src/NadekoBot/Modules/Music/_Common/Impl/MultimediaTimer.cs +++ b/src/NadekoBot/Modules/Music/_Common/Impl/MultimediaTimer.cs @@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Music.Common; public sealed class MultimediaTimer : IDisposable { - private LpTimeProcDelegate _lpTimeProc; + private LpTimeProcDelegate lpTimeProc; private readonly uint _eventId; private readonly Action _callback; private readonly object _state; @@ -18,8 +18,8 @@ public sealed class MultimediaTimer : IDisposable _callback = callback; _state = state; - _lpTimeProc = CallbackInternal; - _eventId = timeSetEvent((uint)period, 1, _lpTimeProc, 0, TimerMode.Periodic); + lpTimeProc = CallbackInternal; + _eventId = timeSetEvent((uint)period, 1, lpTimeProc, 0, TimerMode.Periodic); } /// @@ -58,13 +58,13 @@ public sealed class MultimediaTimer : IDisposable /// /// The timeKillEvent function cancels a specified timer event. /// - /// + /// /// Identifier of the timer event to cancel. /// This identifier was returned by the timeSetEvent function when the timer event was set up. /// /// Returns TIMERR_NOERROR if successful or MMSYSERR_INVALPARAM if the specified timer event does not exist. [DllImport("Winmm.dll")] - private static extern int timeKillEvent(uint uTimerID); + private static extern int timeKillEvent(uint uTimerId); private void CallbackInternal( uint uTimerId, @@ -76,12 +76,12 @@ public sealed class MultimediaTimer : IDisposable public void Dispose() { - _lpTimeProc = default; + lpTimeProc = default; timeKillEvent(_eventId); } private delegate void LpTimeProcDelegate( - uint uTimerID, + uint uTimerId, uint uMsg, int dwUser, int dw1, diff --git a/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs b/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs index f808d0b84..b04a06ec0 100644 --- a/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs @@ -22,7 +22,7 @@ public sealed class MusicPlayer : IMusicPlayer public float Volume { get; private set; } = 1.0f; - private readonly AdjustVolumeDelegate AdjustVolume; + private readonly AdjustVolumeDelegate _adjustVolume; private readonly VoiceClient _vc; private readonly IMusicQueue _queue; @@ -30,8 +30,8 @@ public sealed class MusicPlayer : IMusicPlayer private readonly IVoiceProxy _proxy; private readonly ISongBuffer _songBuffer; - private bool _skipped; - private int? _forceIndex; + private bool skipped; + private int? forceIndex; private readonly Thread _thread; private readonly Random _rng; @@ -48,9 +48,9 @@ public sealed class MusicPlayer : IMusicPlayer _vc = GetVoiceClient(qualityPreset); if (_vc.BitDepth == 16) - AdjustVolume = AdjustVolumeInt16; + _adjustVolume = AdjustVolumeInt16; else - AdjustVolume = AdjustVolumeFloat32; + _adjustVolume = AdjustVolumeFloat32; _songBuffer = new PoopyBufferImmortalized(_vc.InputLength); @@ -95,9 +95,9 @@ public sealed class MusicPlayer : IMusicPlayer continue; } - if (_skipped) + if (skipped) { - _skipped = false; + skipped = false; _queue.Advance(); continue; } @@ -182,9 +182,9 @@ public sealed class MusicPlayer : IMusicPlayer { // doing the skip this way instead of in the condition // ensures that a song will for sure be skipped - if (_skipped) + if (skipped) { - _skipped = false; + skipped = false; break; } @@ -268,10 +268,9 @@ public sealed class MusicPlayer : IMusicPlayer _ = OnCompleted?.Invoke(this, track); HandleQueuePostTrack(); - _skipped = false; + skipped = false; _ = _proxy.StopSpeakingAsync(); - ; await Task.Delay(100); } @@ -285,16 +284,16 @@ public sealed class MusicPlayer : IMusicPlayer // if nothing is read from the buffer, song is finished if (data.Length == 0) return null; - AdjustVolume(data, Volume); + _adjustVolume(data, Volume); return _proxy.SendPcmFrame(vc, data, length); } private void HandleQueuePostTrack() { - if (_forceIndex is { } forceIndex) + if (this.forceIndex is { } forceIndex) { _queue.SetIndex(forceIndex); - _forceIndex = null; + this.forceIndex = null; return; } @@ -419,7 +418,7 @@ public sealed class MusicPlayer : IMusicPlayer public void Clear() { _queue.Clear(); - _skipped = true; + skipped = true; } public IReadOnlyCollection GetQueuedTracks() @@ -430,7 +429,7 @@ public sealed class MusicPlayer : IMusicPlayer public void Next() { - _skipped = true; + skipped = true; IsStopped = false; IsPaused = false; } @@ -439,8 +438,8 @@ public sealed class MusicPlayer : IMusicPlayer { if (_queue.SetIndex(index)) { - _forceIndex = index; - _skipped = true; + forceIndex = index; + skipped = true; IsStopped = false; IsPaused = false; return true; @@ -463,7 +462,7 @@ public sealed class MusicPlayer : IMusicPlayer IsKilled = true; IsStopped = true; IsPaused = false; - _skipped = true; + skipped = true; } public bool TryRemoveTrackAt(int index, out IQueuedTrackInfo? trackInfo) @@ -472,7 +471,7 @@ public sealed class MusicPlayer : IMusicPlayer return false; if (isCurrent) - _skipped = true; + skipped = true; return true; } diff --git a/src/NadekoBot/Modules/Music/_Common/Impl/MusicQueue.cs b/src/NadekoBot/Modules/Music/_Common/Impl/MusicQueue.cs index 02b5a2d62..7c23386a1 100644 --- a/src/NadekoBot/Modules/Music/_Common/Impl/MusicQueue.cs +++ b/src/NadekoBot/Modules/Music/_Common/Impl/MusicQueue.cs @@ -91,7 +91,7 @@ public sealed partial class MusicQueue : IMusicQueue var currentNode = tracks.First!; int i; - for (i = 1; i <= this.index; i++) + for (i = 1; i <= index; i++) currentNode = currentNode.Next!; // can't be null because index is always in range of the count var added = new QueuedTrackInfo(trackInfo, queuer); @@ -110,7 +110,7 @@ public sealed partial class MusicQueue : IMusicQueue foreach (var track in toEnqueue) { var added = new QueuedTrackInfo(track, queuer); - this.tracks.AddLast(added); + tracks.AddLast(added); } } } @@ -156,7 +156,7 @@ public sealed partial class MusicQueue : IMusicQueue if (newIndex < 0 || newIndex >= tracks.Count) return false; - this.index = newIndex; + index = newIndex; return true; } } @@ -170,11 +170,11 @@ public sealed partial class MusicQueue : IMusicQueue trackInfo = removedNode.Value; tracks.Remove(removedNode); - if (i <= this.index) - --this.index; + if (i <= index) + --index; - if (this.index < 0) - this.index = Count; + if (index < 0) + index = Count; // if it was the last song in the queue // // wrap back to start @@ -303,7 +303,7 @@ public sealed partial class MusicQueue : IMusicQueue if (remoteAt < 0 || remoteAt >= tracks.Count) return false; - if (remoteAt == this.index) isCurrent = true; + if (remoteAt == index) isCurrent = true; RemoveAtInternal(remoteAt, out trackInfo); diff --git a/src/NadekoBot/Modules/Music/_Common/Resolvers/YtdlYoutubeResolver.cs b/src/NadekoBot/Modules/Music/_Common/Resolvers/YtdlYoutubeResolver.cs index dd18195c8..6ecdc78be 100644 --- a/src/NadekoBot/Modules/Music/_Common/Resolvers/YtdlYoutubeResolver.cs +++ b/src/NadekoBot/Modules/Music/_Common/Resolvers/YtdlYoutubeResolver.cs @@ -5,12 +5,12 @@ namespace NadekoBot.Modules.Music; public sealed class YtdlYoutubeResolver : IYoutubeResolver { - private static readonly string[] durationFormats = + private static readonly string[] _durationFormats = { "ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss" }; - private static readonly Regex expiryRegex = new(@"(?:[\?\&]expire\=(?\d+))"); + private static readonly Regex _expiryRegex = new(@"(?:[\?\&]expire\=(?\d+))"); private static readonly Regex _simplePlaylistRegex = new(@"&list=(?[\w\-]{12,})", RegexOptions.Compiled); @@ -85,7 +85,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver return default; } - if (!TimeSpan.TryParseExact(dataArray[4], durationFormats, CultureInfo.InvariantCulture, out var time)) + if (!TimeSpan.TryParseExact(dataArray[4], _durationFormats, CultureInfo.InvariantCulture, out var time)) time = TimeSpan.Zero; var thumbnail = Uri.IsWellFormedUriString(dataArray[3], UriKind.Absolute) ? dataArray[3].Trim() : string.Empty; @@ -108,7 +108,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver private static TimeSpan GetExpiry(string streamUrl) { - var match = expiryRegex.Match(streamUrl); + var match = _expiryRegex.Match(streamUrl); if (match.Success && double.TryParse(match.Groups["timestamp"].ToString(), out var timestamp)) { var realExpiry = timestamp.ToUnixTimestamp() - DateTime.UtcNow; diff --git a/src/NadekoBot/Modules/Nsfw/Nsfw.cs b/src/NadekoBot/Modules/Nsfw/Nsfw.cs index ad42b8c02..ccadc3a03 100644 --- a/src/NadekoBot/Modules/Nsfw/Nsfw.cs +++ b/src/NadekoBot/Modules/Nsfw/Nsfw.cs @@ -36,7 +36,7 @@ public partial class NSFW : NadekoModule } } - private async Task InternalButts(IMessageChannel Channel) + private async Task InternalButts(IMessageChannel channel) { try { @@ -47,7 +47,7 @@ public partial class NSFW : NadekoModule await http.GetStringAsync($"http://api.obutts.ru/butts/{new NadekoRandom().Next(0, 4335)}"))[0]; } - await Channel.SendMessageAsync($"http://media.obutts.ru/{obj["preview"]}"); + await channel.SendMessageAsync($"http://media.obutts.ru/{obj["preview"]}"); } catch (Exception ex) { diff --git a/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs b/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs index c1ca1a25d..3a527a2d7 100644 --- a/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs +++ b/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs @@ -35,7 +35,7 @@ public class SearchImagesService : ISearchImagesService, INService private readonly IHttpClientFactory _httpFactory; private readonly DbService _db; - private readonly object taglock = new(); + private readonly object _taglock = new(); public SearchImagesService( DbService db, @@ -188,7 +188,7 @@ public class SearchImagesService : ISearchImagesService, INService public ValueTask ToggleBlacklistTag(ulong guildId, string tag) { - lock (taglock) + lock (_taglock) { tag = tag.Trim().ToLowerInvariant(); var blacklistedTags = BlacklistedTags.GetOrAdd(guildId, new HashSet()); @@ -214,7 +214,7 @@ public class SearchImagesService : ISearchImagesService, INService public ValueTask GetBlacklistedTags(ulong guildId) { - lock (taglock) + lock (_taglock) { if (BlacklistedTags.TryGetValue(guildId, out var tags)) return new(tags.ToArray()); diff --git a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/ImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/ImageDownloader.cs index e6ecd3157..d3175c84a 100644 --- a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/ImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/ImageDownloader.cs @@ -10,7 +10,7 @@ public abstract class ImageDownloader : IImageDownloader public Booru Booru { get; } protected readonly HttpClient _http; - protected JsonSerializerOptions _serializerOptions = new() + protected readonly JsonSerializerOptions _serializerOptions = new() { PropertyNameCaseInsensitive = true, NumberHandling = JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString diff --git a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistService.cs b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistService.cs index f47f4ad76..3e0ba46b4 100644 --- a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistService.cs +++ b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistService.cs @@ -30,7 +30,7 @@ public sealed class BlacklistService : IEarlyBehavior private ValueTask OnReload(BlacklistEntry[] newBlacklist) { - this.blacklist = newBlacklist; + blacklist = newBlacklist; return default; } diff --git a/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs b/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs index 6bdb4e9f1..e4176a6e4 100644 --- a/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs +++ b/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs @@ -9,7 +9,7 @@ public partial class Permissions [Group] public partial class GlobalPermissionCommands : NadekoSubmodule { - private GlobalPermissionService _service; + private readonly GlobalPermissionService _service; private readonly DbService _db; public GlobalPermissionCommands(GlobalPermissionService service, DbService db) diff --git a/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs b/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs index e11dfa930..6903e8c4f 100644 --- a/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs +++ b/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs @@ -10,7 +10,7 @@ public class CryptoService : INService private readonly IHttpClientFactory _httpFactory; private readonly IBotCredentials _creds; - private readonly SemaphoreSlim getCryptoLock = new(1, 1); + private readonly SemaphoreSlim _getCryptoLock = new(1, 1); public CryptoService(IDataCache cache, IHttpClientFactory httpFactory, IBotCredentials creds) { @@ -52,7 +52,7 @@ public class CryptoService : INService public async Task> CryptoData() { - await getCryptoLock.WaitAsync(); + await _getCryptoLock.WaitAsync(); try { var fullStrData = await _cache.GetOrAddCachedDataAsync("nadeko:crypto_data", @@ -81,7 +81,7 @@ public class CryptoService : INService "", TimeSpan.FromHours(1)); - return JsonConvert.DeserializeObject(fullStrData).Data; + return JsonConvert.DeserializeObject(fullStrData)?.Data ?? new(); } catch (Exception ex) { @@ -90,7 +90,7 @@ public class CryptoService : INService } finally { - getCryptoLock.Release(); + _getCryptoLock.Release(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs b/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs index 4379ad903..2635a5de7 100644 --- a/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs +++ b/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs @@ -10,7 +10,7 @@ public partial class Searches [Group] public partial class FeedCommands : NadekoSubmodule { - private static readonly Regex YtChannelRegex = + private static readonly Regex _ytChannelRegex = new(@"youtube\.com\/(?:c\/|channel\/|user\/)?(?[a-zA-Z0-9\-]{1,})"); [Cmd] @@ -18,7 +18,7 @@ public partial class Searches [UserPerm(GuildPerm.ManageMessages)] public partial Task YtUploadNotif(string url, [Leftover] ITextChannel channel = null) { - var m = YtChannelRegex.Match(url); + var m = _ytChannelRegex.Match(url); if (!m.Success) return ReplyErrorLocalizedAsync(strs.invalid_input); var channelId = m.Groups["channelid"].Value; @@ -38,7 +38,7 @@ public partial class Searches channel ??= (ITextChannel)ctx.Channel; try { - var feeds = await FeedReader.ReadAsync(url); + await FeedReader.ReadAsync(url); } catch (Exception ex) { diff --git a/src/NadekoBot/Modules/Searches/OsuCommands.cs b/src/NadekoBot/Modules/Searches/OsuCommands.cs index 53bcc11ed..7e83bc913 100644 --- a/src/NadekoBot/Modules/Searches/OsuCommands.cs +++ b/src/NadekoBot/Modules/Searches/OsuCommands.cs @@ -115,7 +115,6 @@ public partial class Searches [Cmd] public async partial Task Osu5(string user, [Leftover] string mode = null) { - ; if (string.IsNullOrWhiteSpace(_creds.OsuApiKey)) { await SendErrorAsync("An osu! API key is required."); diff --git a/src/NadekoBot/Modules/Searches/SearchesService.cs b/src/NadekoBot/Modules/Searches/SearchesService.cs index 33606803b..998086476 100644 --- a/src/NadekoBot/Modules/Searches/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/SearchesService.cs @@ -46,7 +46,7 @@ public class SearchesService : INService private readonly NadekoRandom _rng; private readonly List _yomamaJokes; - private readonly object yomamaLock = new(); + private readonly object _yomamaLock = new(); private int yomamaJokeIndex; public SearchesService( @@ -224,9 +224,11 @@ public class SearchesService : INService using var req = new HttpRequestMessage(HttpMethod.Get, "http://api.timezonedb.com/v2.1/get-time-zone?" - + $"key={_creds.TimezoneDbApiKey}&format=json&" - + "by=position&" - + $"lat={geoData.Lat}&lng={geoData.Lon}"); + + $"key={_creds.TimezoneDbApiKey}" + + $"&format=json" + + $"&by=position" + + $"&lat={geoData.Lat}" + + $"&lng={geoData.Lon}"); using var geoRes = await http.SendAsync(req); var resString = await geoRes.Content.ReadAsStringAsync(); var timeObj = JsonConvert.DeserializeObject(resString); @@ -274,7 +276,7 @@ public class SearchesService : INService public Task GetYomamaJoke() { string joke; - lock (yomamaLock) + lock (_yomamaLock) { if (yomamaJokeIndex >= _yomamaJokes.Count) { @@ -428,8 +430,6 @@ public class SearchesService : INService public async Task GetSteamAppIdByName(string query) { - var redis = _cache.Redis; - var db = redis.GetDatabase(); const string steamGameIdsKey = "steam_names_to_appid"; // var exists = await db.KeyExistsAsync(steamGameIdsKey); diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs index dd7f34c04..c73acf2cf 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs @@ -59,7 +59,7 @@ public partial class Searches [UserPerm(GuildPerm.Administrator)] public async partial Task StreamsClear() { - var count = _service.ClearAllStreams(ctx.Guild.Id); + await _service.ClearAllStreams(ctx.Guild.Id); await ReplyConfirmLocalizedAsync(strs.streams_cleared); } diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs index bdf6c7d94..b3f34ed59 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs @@ -116,7 +116,7 @@ public sealed class StreamNotificationService : INService return; var deleteGroups = failingStreams.GroupBy(x => x.Type) - .ToDictionary(x => x.Key, x => x.Select(x => x.Name).ToList()); + .ToDictionary(x => x.Key, x => x.Select(y => y.Name).ToList()); using var uow = _db.GetDbContext(); foreach (var kvp in deleteGroups) diff --git a/src/NadekoBot/Modules/Searches/YoutubeTrack/YtTrackService.cs b/src/NadekoBot/Modules/Searches/YoutubeTrack/YtTrackService.cs index cf2092d3d..9b20fee04 100644 --- a/src/NadekoBot/Modules/Searches/YoutubeTrack/YtTrackService.cs +++ b/src/NadekoBot/Modules/Searches/YoutubeTrack/YtTrackService.cs @@ -1,5 +1,4 @@ ο»Ώ#nullable disable -namespace NadekoBot.Modules.Searches.Services; // public class YtTrackService : INService // { diff --git a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TwitchResponseHelix.cs b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TwitchResponseHelix.cs deleted file mode 100644 index fdf979882..000000000 --- a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TwitchResponseHelix.cs +++ /dev/null @@ -1,22 +0,0 @@ -#nullable disable -namespace NadekoBot.Modules.Searches.Common; - -// -// public class TwitchResponse -// { -// public List Data { get; set; } -// -// public class StreamApiData -// { -// public string Id { get; set; } -// public string UserId { get; set; } -// public string UserName { get; set; } -// public string GameId { get; set; } -// public string Type { get; set; } -// public string Title { get; set; } -// public int ViewerCount { get; set; } -// public string Language { get; set; } -// public string ThumbnailUrl { get; set; } -// public DateTime StartedAt { get; set; } -// } -// } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs index e8012ada7..2c26ae5c0 100644 --- a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs @@ -34,8 +34,6 @@ public partial class Utility [RequireContext(ContextType.Guild)] public async partial Task Alias(string trigger, [Leftover] string mapping = null) { - var channel = (ITextChannel)ctx.Channel; - if (string.IsNullOrWhiteSpace(trigger)) return; @@ -52,7 +50,6 @@ public partial class Utility await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); - var toAdd = new CommandAlias { Mapping = mapping, Trigger = trigger }; var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger); if (tr is not null) uow.Set().Remove(tr); @@ -84,9 +81,9 @@ public partial class Utility { var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); var toAdd = new CommandAlias { Mapping = mapping, Trigger = trigger }; - var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger); + var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger).ToArray(); if (toRemove.Any()) - uow.RemoveRange(toRemove.ToArray()); + uow.RemoveRange(toRemove); config.CommandAliases.Add(toAdd); uow.SaveChanges(); } @@ -103,7 +100,6 @@ public partial class Utility [RequireContext(ContextType.Guild)] public async partial Task AliasList(int page = 1) { - var channel = (ITextChannel)ctx.Channel; page -= 1; if (page < 0) diff --git a/src/NadekoBot/Modules/Utility/ConfigCommands.cs b/src/NadekoBot/Modules/Utility/ConfigCommands.cs index eaf4734a6..98045b598 100644 --- a/src/NadekoBot/Modules/Utility/ConfigCommands.cs +++ b/src/NadekoBot/Modules/Utility/ConfigCommands.cs @@ -107,7 +107,7 @@ public partial class Utility if (string.IsNullOrWhiteSpace(value)) value = "-"; - if (prop != "currency.sign") value = Format.Code(Format.Sanitize(value?.TrimTo(1000)), "json"); + if (prop != "currency.sign") value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json"); var embed = _eb.Create() .WithOkColor() @@ -134,7 +134,7 @@ public partial class Utility await ctx.OkAsync(); } - private string GetPropsAndValuesString(IConfigService config, IEnumerable names) + private string GetPropsAndValuesString(IConfigService config, IReadOnlyCollection names) { var propValues = names.Select(pr => { @@ -142,7 +142,7 @@ public partial class Utility if (pr != "currency.sign") val = val?.TrimTo(28); return val?.Replace("\n", "") ?? "-"; - }); + }).ToList(); var strings = names.Zip(propValues, (name, value) => $"{name,-25} = {value}\n"); diff --git a/src/NadekoBot/Modules/Utility/Patreon/PatreonRewardsService.cs b/src/NadekoBot/Modules/Utility/Patreon/PatreonRewardsService.cs index 72e8e89bd..769244efa 100644 --- a/src/NadekoBot/Modules/Utility/Patreon/PatreonRewardsService.cs +++ b/src/NadekoBot/Modules/Utility/Patreon/PatreonRewardsService.cs @@ -150,7 +150,7 @@ public class PatreonRewardsService : INService + "?fields%5Bmember%5D=full_name,currently_entitled_amount_cents" + "&fields%5Buser%5D=social_connections" + "&include=user"; - PatreonResponse data = null; + PatreonResponse data; do { var res = await http.GetStringAsync(page); diff --git a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs index 2eab53b1f..798e30e6c 100644 --- a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs @@ -62,12 +62,16 @@ public partial class Utility } if (quotes.Any()) + { await SendConfirmAsync(GetText(strs.quotes_page(page + 1)), string.Join("\n", quotes.Select(q => $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}"))); + } else + { await ReplyErrorLocalizedAsync(strs.quotes_page_none); + } } [Cmd] diff --git a/src/NadekoBot/Modules/Utility/Repeater/RunningRepeater.cs b/src/NadekoBot/Modules/Utility/Repeater/RunningRepeater.cs index f7d469a31..8a737db95 100644 --- a/src/NadekoBot/Modules/Utility/Repeater/RunningRepeater.cs +++ b/src/NadekoBot/Modules/Utility/Repeater/RunningRepeater.cs @@ -55,7 +55,6 @@ public sealed class RunningRepeater /// /// Calculate when is the proper time to run the repeater again based on initial time repeater ran. /// - /// /// Initial time repeater ran at (or should run at). private DateTime CalculateInitialInterval(DateTime initialDateTime) { diff --git a/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs b/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs index f01144c17..634b24e0c 100644 --- a/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs +++ b/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs @@ -23,7 +23,7 @@ public class ConverterService : INService _httpFactory = factory; if (client.ShardId == 0) - _currencyUpdater = new(async shouldLoad => await UpdateCurrency((bool)shouldLoad), + _currencyUpdater = new(async shouldLoad => await UpdateCurrency((bool)shouldLoad!), client.ShardId == 0, TimeSpan.Zero, _updateInterval); @@ -55,7 +55,9 @@ public class ConverterService : INService .ToArray(); var fileData = JsonConvert.DeserializeObject(File.ReadAllText("data/units.json")) - .Where(x => x.UnitType != "currency"); + ?.Where(x => x.UnitType != "currency"); + if (fileData is null) + return; var data = JsonConvert.SerializeObject(range.Append(baseType).Concat(fileData).ToList()); _cache.Redis.GetDatabase().StringSet("converter_units", data); diff --git a/src/NadekoBot/Modules/Utility/VerboseErrors/VerboseErrorsService.cs b/src/NadekoBot/Modules/Utility/VerboseErrors/VerboseErrorsService.cs index 5f986e1e2..bf53dbf5c 100644 --- a/src/NadekoBot/Modules/Utility/VerboseErrors/VerboseErrorsService.cs +++ b/src/NadekoBot/Modules/Utility/VerboseErrors/VerboseErrorsService.cs @@ -6,7 +6,7 @@ namespace NadekoBot.Modules.Utility.Services; public class VerboseErrorsService : INService { - private readonly ConcurrentHashSet guildsEnabled; + private readonly ConcurrentHashSet _guildsEnabled; private readonly DbService _db; private readonly CommandHandler _ch; private readonly HelpService _hs; @@ -23,12 +23,12 @@ public class VerboseErrorsService : INService _ch.CommandErrored += LogVerboseError; - guildsEnabled = new(bot.AllGuildConfigs.Where(x => x.VerboseErrors).Select(x => x.GuildId)); + _guildsEnabled = new(bot.AllGuildConfigs.Where(x => x.VerboseErrors).Select(x => x.GuildId)); } private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason) { - if (channel is null || !guildsEnabled.Contains(channel.GuildId)) + if (channel is null || !_guildsEnabled.Contains(channel.GuildId)) return; try @@ -60,9 +60,9 @@ public class VerboseErrorsService : INService } if ((bool)enabled) // This doesn't need to be duplicated inside the using block - guildsEnabled.Add(guildId); + _guildsEnabled.Add(guildId); else - guildsEnabled.TryRemove(guildId); + _guildsEnabled.TryRemove(guildId); return (bool)enabled; } diff --git a/src/NadekoBot/Modules/Xp/Club/ClubService.cs b/src/NadekoBot/Modules/Xp/Club/ClubService.cs index 95f813852..d67acca33 100644 --- a/src/NadekoBot/Modules/Xp/Club/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Club/ClubService.cs @@ -9,10 +9,10 @@ public class ClubService : INService private readonly DbService _db; private readonly IHttpClientFactory _httpFactory; - public ClubService(DbService db, IHttpClientFactory _httpFactory) + public ClubService(DbService db, IHttpClientFactory httpFactory) { _db = db; - this._httpFactory = _httpFactory; + _httpFactory = httpFactory; } public bool CreateClub(IUser user, string clubName, out ClubInfo club) diff --git a/src/NadekoBot/Modules/Xp/XpConfigService.cs b/src/NadekoBot/Modules/Xp/XpConfigService.cs index 9ac52160e..3702bb70a 100644 --- a/src/NadekoBot/Modules/Xp/XpConfigService.cs +++ b/src/NadekoBot/Modules/Xp/XpConfigService.cs @@ -5,12 +5,13 @@ namespace NadekoBot.Modules.Xp.Services; public sealed class XpConfigService : ConfigServiceBase { - private const string FilePath = "data/xp.yml"; - private static readonly TypedKey changeKey = new("config.xp.updated"); - public override string Name { get; } = "xp"; + private const string FILE_PATH = "data/xp.yml"; + private static readonly TypedKey _changeKey = new("config.xp.updated"); + public override string Name + => "xp"; public XpConfigService(IConfigSeria serializer, IPubSub pubSub) - : base(FilePath, serializer, pubSub, changeKey) + : base(FILE_PATH, serializer, pubSub, _changeKey) { AddParsedProp("txt.cooldown", conf => conf.MessageXpCooldown, diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index bfd069859..dbe8c3068 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -42,7 +42,7 @@ public class XpService : INService private readonly ConcurrentHashSet _excludedServers; private readonly ConcurrentQueue _addMessageXp = new(); - private XpTemplate _template; + private XpTemplate template; private readonly DiscordSocketClient _client; private readonly TypedKey _xpTemplateReloadKey; @@ -266,15 +266,15 @@ public class XpService : INService { ContractResolver = new RequireObjectPropertiesContractResolver() }; - _template = JsonConvert.DeserializeObject(File.ReadAllText("./data/xp_template.json"), + template = JsonConvert.DeserializeObject(File.ReadAllText("./data/xp_template.json"), settings); } catch (Exception ex) { Log.Error(ex, "Xp template is invalid. Loaded default values"); - _template = new(); + template = new(); File.WriteAllText("./data/xp_template_backup.json", - JsonConvert.SerializeObject(_template, Formatting.Indented)); + JsonConvert.SerializeObject(template, Formatting.Indented)); } } @@ -583,7 +583,7 @@ public class XpService : INService public async Task GetUserStatsAsync(IGuildUser user) { DiscordUser du; - UserXpStats stats = null; + UserXpStats stats; int totalXp; int globalRank; int guildRank; @@ -691,58 +691,58 @@ public class XpService : INService }.WithFallbackFonts(_fonts.FallBackFonts); using var img = Image.Load(_images.XpBackground, out var imageFormat); - if (_template.User.Name.Show) + if (template.User.Name.Show) { - var fontSize = (int)(_template.User.Name.FontSize * 0.9); + var fontSize = (int)(template.User.Name.FontSize * 0.9); var username = stats.User.ToString(); var usernameFont = _fonts.NotoSans.CreateFont(fontSize, FontStyle.Bold); var size = TextMeasurer.Measure($"@{username}", new(usernameFont)); var scale = 400f / size.Width; if (scale < 1) - usernameFont = _fonts.NotoSans.CreateFont(_template.User.Name.FontSize * scale, FontStyle.Bold); + usernameFont = _fonts.NotoSans.CreateFont(template.User.Name.FontSize * scale, FontStyle.Bold); img.Mutate(x => { x.DrawText(usernameTextOptions, "@" + username, usernameFont, - _template.User.Name.Color, - new(_template.User.Name.Pos.X, _template.User.Name.Pos.Y + 8)); + template.User.Name.Color, + new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8)); }); } //club name - if (_template.Club.Name.Show) + if (template.Club.Name.Show) { var clubName = stats.User.Club?.ToString() ?? "-"; - var clubFont = _fonts.NotoSans.CreateFont(_template.Club.Name.FontSize, FontStyle.Regular); + var clubFont = _fonts.NotoSans.CreateFont(template.Club.Name.FontSize, FontStyle.Regular); img.Mutate(x => x.DrawText(clubTextOptions, clubName, clubFont, - _template.Club.Name.Color, - new(_template.Club.Name.Pos.X + 50, _template.Club.Name.Pos.Y - 8))); + template.Club.Name.Color, + new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8))); } - if (_template.User.GlobalLevel.Show) + if (template.User.GlobalLevel.Show) img.Mutate(x => { x.DrawText(stats.Global.Level.ToString(), - _fonts.NotoSans.CreateFont(_template.User.GlobalLevel.FontSize, FontStyle.Bold), - _template.User.GlobalLevel.Color, - new(_template.User.GlobalLevel.Pos.X, _template.User.GlobalLevel.Pos.Y)); //level + _fonts.NotoSans.CreateFont(template.User.GlobalLevel.FontSize, FontStyle.Bold), + template.User.GlobalLevel.Color, + new(template.User.GlobalLevel.Pos.X, template.User.GlobalLevel.Pos.Y)); //level }); - if (_template.User.GuildLevel.Show) + if (template.User.GuildLevel.Show) img.Mutate(x => { x.DrawText(stats.Guild.Level.ToString(), - _fonts.NotoSans.CreateFont(_template.User.GuildLevel.FontSize, FontStyle.Bold), - _template.User.GuildLevel.Color, - new(_template.User.GuildLevel.Pos.X, _template.User.GuildLevel.Pos.Y)); + _fonts.NotoSans.CreateFont(template.User.GuildLevel.FontSize, FontStyle.Bold), + template.User.GuildLevel.Color, + new(template.User.GuildLevel.Pos.X, template.User.GuildLevel.Pos.Y)); }); @@ -752,53 +752,53 @@ public class XpService : INService var guild = stats.Guild; //xp bar - if (_template.User.Xp.Bar.Show) + if (template.User.Xp.Bar.Show) { var xpPercent = global.LevelXp / (float)global.RequiredXp; - DrawXpBar(xpPercent, _template.User.Xp.Bar.Global, img); + DrawXpBar(xpPercent, template.User.Xp.Bar.Global, img); xpPercent = guild.LevelXp / (float)guild.RequiredXp; - DrawXpBar(xpPercent, _template.User.Xp.Bar.Guild, img); + DrawXpBar(xpPercent, template.User.Xp.Bar.Guild, img); } - if (_template.User.Xp.Global.Show) + if (template.User.Xp.Global.Show) img.Mutate(x => x.DrawText($"{global.LevelXp}/{global.RequiredXp}", - _fonts.NotoSans.CreateFont(_template.User.Xp.Global.FontSize, FontStyle.Bold), - Brushes.Solid(_template.User.Xp.Global.Color), + _fonts.NotoSans.CreateFont(template.User.Xp.Global.FontSize, FontStyle.Bold), + Brushes.Solid(template.User.Xp.Global.Color), pen, - new(_template.User.Xp.Global.Pos.X, _template.User.Xp.Global.Pos.Y))); + new(template.User.Xp.Global.Pos.X, template.User.Xp.Global.Pos.Y))); - if (_template.User.Xp.Guild.Show) + if (template.User.Xp.Guild.Show) img.Mutate(x => x.DrawText($"{guild.LevelXp}/{guild.RequiredXp}", - _fonts.NotoSans.CreateFont(_template.User.Xp.Guild.FontSize, FontStyle.Bold), - Brushes.Solid(_template.User.Xp.Guild.Color), + _fonts.NotoSans.CreateFont(template.User.Xp.Guild.FontSize, FontStyle.Bold), + Brushes.Solid(template.User.Xp.Guild.Color), pen, - new(_template.User.Xp.Guild.Pos.X, _template.User.Xp.Guild.Pos.Y))); + new(template.User.Xp.Guild.Pos.X, template.User.Xp.Guild.Pos.Y))); - if (stats.FullGuildStats.AwardedXp != 0 && _template.User.Xp.Awarded.Show) + if (stats.FullGuildStats.AwardedXp != 0 && template.User.Xp.Awarded.Show) { var sign = stats.FullGuildStats.AwardedXp > 0 ? "+ " : ""; - var awX = _template.User.Xp.Awarded.Pos.X + var awX = template.User.Xp.Awarded.Pos.X - (Math.Max(0, stats.FullGuildStats.AwardedXp.ToString().Length - 2) * 5); - var awY = _template.User.Xp.Awarded.Pos.Y; + var awY = template.User.Xp.Awarded.Pos.Y; img.Mutate(x => x.DrawText($"({sign}{stats.FullGuildStats.AwardedXp})", - _fonts.NotoSans.CreateFont(_template.User.Xp.Awarded.FontSize, FontStyle.Bold), - Brushes.Solid(_template.User.Xp.Awarded.Color), + _fonts.NotoSans.CreateFont(template.User.Xp.Awarded.FontSize, FontStyle.Bold), + Brushes.Solid(template.User.Xp.Awarded.Color), pen, new(awX, awY))); } //ranking - if (_template.User.GlobalRank.Show) + if (template.User.GlobalRank.Show) img.Mutate(x => x.DrawText(stats.GlobalRanking.ToString(), - _fonts.UniSans.CreateFont(_template.User.GlobalRank.FontSize, FontStyle.Bold), - _template.User.GlobalRank.Color, - new(_template.User.GlobalRank.Pos.X, _template.User.GlobalRank.Pos.Y))); + _fonts.UniSans.CreateFont(template.User.GlobalRank.FontSize, FontStyle.Bold), + template.User.GlobalRank.Color, + new(template.User.GlobalRank.Pos.X, template.User.GlobalRank.Pos.Y))); - if (_template.User.GuildRank.Show) + if (template.User.GuildRank.Show) img.Mutate(x => x.DrawText(stats.GuildRanking.ToString(), - _fonts.UniSans.CreateFont(_template.User.GuildRank.FontSize, FontStyle.Bold), - _template.User.GuildRank.Color, - new(_template.User.GuildRank.Pos.X, _template.User.GuildRank.Pos.Y))); + _fonts.UniSans.CreateFont(template.User.GuildRank.FontSize, FontStyle.Bold), + template.User.GuildRank.Color, + new(template.User.GuildRank.Pos.X, template.User.GuildRank.Pos.Y))); //time on this level @@ -808,21 +808,21 @@ public class XpService : INService return string.Format(format, offset.Days, offset.Hours, offset.Minutes); } - if (_template.User.TimeOnLevel.Global.Show) - img.Mutate(x => x.DrawText(GetTimeSpent(stats.User.LastLevelUp, _template.User.TimeOnLevel.Format), - _fonts.NotoSans.CreateFont(_template.User.TimeOnLevel.Global.FontSize, FontStyle.Bold), - _template.User.TimeOnLevel.Global.Color, - new(_template.User.TimeOnLevel.Global.Pos.X, _template.User.TimeOnLevel.Global.Pos.Y))); + if (template.User.TimeOnLevel.Global.Show) + img.Mutate(x => x.DrawText(GetTimeSpent(stats.User.LastLevelUp, template.User.TimeOnLevel.Format), + _fonts.NotoSans.CreateFont(template.User.TimeOnLevel.Global.FontSize, FontStyle.Bold), + template.User.TimeOnLevel.Global.Color, + new(template.User.TimeOnLevel.Global.Pos.X, template.User.TimeOnLevel.Global.Pos.Y))); - if (_template.User.TimeOnLevel.Guild.Show) + if (template.User.TimeOnLevel.Guild.Show) img.Mutate(x - => x.DrawText(GetTimeSpent(stats.FullGuildStats.LastLevelUp, _template.User.TimeOnLevel.Format), - _fonts.NotoSans.CreateFont(_template.User.TimeOnLevel.Guild.FontSize, FontStyle.Bold), - _template.User.TimeOnLevel.Guild.Color, - new(_template.User.TimeOnLevel.Guild.Pos.X, _template.User.TimeOnLevel.Guild.Pos.Y))); + => x.DrawText(GetTimeSpent(stats.FullGuildStats.LastLevelUp, template.User.TimeOnLevel.Format), + _fonts.NotoSans.CreateFont(template.User.TimeOnLevel.Guild.FontSize, FontStyle.Bold), + template.User.TimeOnLevel.Guild.Color, + new(template.User.TimeOnLevel.Guild.Pos.X, template.User.TimeOnLevel.Guild.Pos.Y))); //avatar - if (stats.User.AvatarId is not null && _template.User.Icon.Show) + if (stats.User.AvatarId is not null && template.User.Icon.Show) try { var avatarUrl = stats.User.RealAvatarUrl(); @@ -836,10 +836,10 @@ public class XpService : INService using (var tempDraw = Image.Load(avatarData)) { tempDraw.Mutate(x => x - .Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y) - .ApplyRoundedCorners(Math.Max(_template.User.Icon.Size.X, - _template.User.Icon.Size.Y) - / 2)); + .Resize(template.User.Icon.Size.X, template.User.Icon.Size.Y) + .ApplyRoundedCorners(Math.Max(template.User.Icon.Size.X, + template.User.Icon.Size.Y) + / 2.0f)); await using (var stream = tempDraw.ToStream()) { data = stream.ToArray(); @@ -851,11 +851,11 @@ public class XpService : INService } using var toDraw = Image.Load(data); - if (toDraw.Size() != new Size(_template.User.Icon.Size.X, _template.User.Icon.Size.Y)) - toDraw.Mutate(x => x.Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y)); + if (toDraw.Size() != new Size(template.User.Icon.Size.X, template.User.Icon.Size.Y)) + toDraw.Mutate(x => x.Resize(template.User.Icon.Size.X, template.User.Icon.Size.Y)); img.Mutate(x => x.DrawImage(toDraw, - new Point(_template.User.Icon.Pos.X, _template.User.Icon.Pos.Y), + new Point(template.User.Icon.Pos.X, template.User.Icon.Pos.Y), 1)); } catch (Exception ex) @@ -864,9 +864,9 @@ public class XpService : INService } //club image - if (_template.Club.Icon.Show) await DrawClubImage(img, stats); + if (template.Club.Icon.Show) await DrawClubImage(img, stats); - img.Mutate(x => x.Resize(_template.OutputSize.X, _template.OutputSize.Y)); + img.Mutate(x => x.Resize(template.OutputSize.X, template.OutputSize.Y)); return ((Stream)img.ToStream(imageFormat), imageFormat); }); @@ -880,7 +880,7 @@ public class XpService : INService var length = info.Length * percent; - float x3 = 0, x4 = 0, y3 = 0, y4 = 0; + float x3, x4, y3, y4; if (info.Direction == XpTemplateDirection.Down) { @@ -936,11 +936,10 @@ public class XpService : INService using (var tempDraw = Image.Load(imgData)) { tempDraw.Mutate(x => x - .Resize(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y) - .ApplyRoundedCorners(Math.Max(_template.Club.Icon.Size.X, - _template.Club.Icon.Size.Y) + .Resize(template.Club.Icon.Size.X, template.Club.Icon.Size.Y) + .ApplyRoundedCorners(Math.Max(template.Club.Icon.Size.X, + template.Club.Icon.Size.Y) / 2.0f)); - ; await using (var tds = tempDraw.ToStream()) { data = tds.ToArray(); @@ -952,12 +951,12 @@ public class XpService : INService } using var toDraw = Image.Load(data); - if (toDraw.Size() != new Size(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y)) - toDraw.Mutate(x => x.Resize(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y)); + if (toDraw.Size() != new Size(template.Club.Icon.Size.X, template.Club.Icon.Size.Y)) + toDraw.Mutate(x => x.Resize(template.Club.Icon.Size.X, template.Club.Icon.Size.Y)); img.Mutate(x => x.DrawImage( toDraw, - new Point(_template.Club.Icon.Pos.X, _template.Club.Icon.Pos.Y), + new Point(template.Club.Icon.Pos.X, template.Club.Icon.Pos.Y), 1)); } catch (Exception ex) diff --git a/src/NadekoBot/Modules/Xp/_Common/XpTemplate.cs b/src/NadekoBot/Modules/Xp/_Common/XpTemplate.cs index 6487a897b..0a827f9e4 100644 --- a/src/NadekoBot/Modules/Xp/_Common/XpTemplate.cs +++ b/src/NadekoBot/Modules/Xp/_Common/XpTemplate.cs @@ -82,7 +82,7 @@ public class XpTemplateUser public XpTemplateText GlobalRank { get; set; } public XpTemplateText GuildRank { get; set; } public XpTemplateTimeOnLevel TimeOnLevel { get; set; } - public XpTemplateXP Xp { get; set; } + public XpTemplateXp Xp { get; set; } } public class XpTemplateTimeOnLevel @@ -108,7 +108,7 @@ public class XpTemplateText public XpTemplatePos Pos { get; set; } } -public class XpTemplateXP +public class XpTemplateXp { public XpTemplateXpBar Bar { get; set; } public XpTemplateText Global { get; set; } diff --git a/src/NadekoBot/Services/DbService.cs b/src/NadekoBot/Services/DbService.cs index 74f5e6663..b8ea8ef0f 100644 --- a/src/NadekoBot/Services/DbService.cs +++ b/src/NadekoBot/Services/DbService.cs @@ -8,8 +8,8 @@ namespace NadekoBot.Services; public class DbService { - private readonly DbContextOptions options; - private readonly DbContextOptions migrateOptions; + private readonly DbContextOptions _options; + private readonly DbContextOptions _migrateOptions; public DbService(IBotCredentials creds) { @@ -20,19 +20,19 @@ public class DbService var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseSqlite(builder.ToString()); - options = optionsBuilder.Options; + _options = optionsBuilder.Options; optionsBuilder = new(); optionsBuilder.UseSqlite(builder.ToString()); - migrateOptions = optionsBuilder.Options; + _migrateOptions = optionsBuilder.Options; } public void Setup() { - using var context = new NadekoContext(options); + using var context = new NadekoContext(_options); if (context.Database.GetPendingMigrations().Any()) { - var mContext = new NadekoContext(migrateOptions); + var mContext = new NadekoContext(_migrateOptions); mContext.Database.Migrate(); mContext.SaveChanges(); mContext.Dispose(); @@ -44,7 +44,7 @@ public class DbService private NadekoContext GetDbContextInternal() { - var context = new NadekoContext(options); + var context = new NadekoContext(_options); context.Database.SetCommandTimeout(60); var conn = context.Database.GetDbConnection(); conn.Open(); diff --git a/src/NadekoBot/Services/IGoogleApiService.cs b/src/NadekoBot/Services/IGoogleApiService.cs index 55bae18a7..da9823be8 100644 --- a/src/NadekoBot/Services/IGoogleApiService.cs +++ b/src/NadekoBot/Services/IGoogleApiService.cs @@ -3,7 +3,7 @@ using Google.Apis.Customsearch.v1.Data; namespace NadekoBot.Services; -public interface IGoogleApiService : INService +public interface IGoogleApiService { IReadOnlyDictionary Languages { get; }