diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 97b872b9..eb07ef1f 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration { private static ConcurrentHashSet deleteMessagesOnCommand { get; } - private new static Logger _log { get; } + private new static readonly Logger _log; static Administration() { @@ -209,7 +209,7 @@ namespace NadekoBot.Modules.Administration } try { - var rgb = args.Count() == 4; + var rgb = args.Length == 4; var arg1 = args[1].Replace("#", ""); var red = Convert.ToByte(rgb ? int.Parse(arg1) : Convert.ToInt32(arg1.Substring(0, 2), 16)); @@ -244,7 +244,10 @@ namespace NadekoBot.Modules.Administration await Task.Delay(2000).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } await Context.Guild.AddBanAsync(user, 7).ConfigureAwait(false); @@ -275,7 +278,10 @@ namespace NadekoBot.Modules.Administration await user.SendErrorAsync(GetText("sbdm", Format.Bold(Context.Guild.Name), msg)); await Task.Delay(2000).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } await Context.Guild.AddBanAsync(user, 7).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs index 1426bebd..8c6cfcd5 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs @@ -421,7 +421,7 @@ namespace NadekoBot.Modules.Gambling var embed = new EmbedBuilder() .WithOkColor() - .WithTitle("Waifu " + w.Waifu.ToString() + " - \"the " + claimInfo.Title + "\"") + .WithTitle("Waifu " + w.Waifu + " - \"the " + claimInfo.Title + "\"") .AddField(efb => efb.WithName("Price").WithValue(w.Price.ToString()).WithIsInline(true)) .AddField(efb => efb.WithName("Claimed by").WithValue(w.Claimer?.ToString() ?? "No one").WithIsInline(true)) .AddField(efb => efb.WithName("Likes").WithValue(w.Affinity?.ToString() ?? "Nobody").WithIsInline(true)) diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index e2679147..08d3976f 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -12,27 +12,25 @@ using System; using Newtonsoft.Json; using System.IO; using System.Collections.Concurrent; -using NadekoBot.Modules; -using NadekoBot.Resources; namespace NadekoBot.Modules.Pokemon { [NadekoModule("Pokemon", ">")] - public partial class Pokemon : NadekoModule + public class Pokemon : NadekoModule { - private static List PokemonTypes = new List(); - private static ConcurrentDictionary Stats = new ConcurrentDictionary(); + private static readonly List _pokemonTypes = new List(); + private static readonly ConcurrentDictionary _stats = new ConcurrentDictionary(); public const string PokemonTypesFile = "data/pokemon_types.json"; - private static new Logger _log { get; } + private new static Logger _log { get; } static Pokemon() { _log = LogManager.GetCurrentClassLogger(); if (File.Exists(PokemonTypesFile)) { - PokemonTypes = JsonConvert.DeserializeObject>(File.ReadAllText(PokemonTypesFile)); + _pokemonTypes = JsonConvert.DeserializeObject>(File.ReadAllText(PokemonTypesFile)); } else { @@ -44,21 +42,18 @@ namespace NadekoBot.Modules.Pokemon private int GetDamage(PokemonType usertype, PokemonType targetType) { var rng = new Random(); - int damage = rng.Next(40, 60); - foreach (PokemonMultiplier Multiplier in usertype.Multipliers) + var damage = rng.Next(40, 60); + foreach (var multiplierObj in usertype.Multipliers) { - if (Multiplier.Type == targetType.Name) - { - var multiplier = Multiplier.Multiplication; - damage = (int)(damage * multiplier); - } + if (multiplierObj.Type != targetType.Name) continue; + damage = (int)(damage * multiplierObj.Multiplication); } return damage; } - private PokemonType GetPokeType(ulong id) + private static PokemonType GetPokeType(ulong id) { Dictionary setTypes; @@ -71,18 +66,18 @@ namespace NadekoBot.Modules.Pokemon { return StringToPokemonType(setTypes[id]); } - int count = PokemonTypes.Count; + var count = _pokemonTypes.Count; - int remainder = Math.Abs((int)(id % (ulong)count)); + var remainder = Math.Abs((int)(id % (ulong)count)); - return PokemonTypes[remainder]; + return _pokemonTypes[remainder]; } - private PokemonType StringToPokemonType(string v) + private static PokemonType StringToPokemonType(string v) { var str = v?.ToUpperInvariant(); - var list = PokemonTypes; - foreach (PokemonType p in list) + var list = _pokemonTypes; + foreach (var p in list) { if (str == p.Name) { @@ -116,8 +111,7 @@ namespace NadekoBot.Modules.Pokemon // Checking stats first, then move //Set up the userstats - PokeStats userStats; - userStats = Stats.GetOrAdd(user.Id, new PokeStats()); + var userStats = _stats.GetOrAdd(user.Id, new PokeStats()); //Check if able to move //User not able if HP < 0, has made more than 4 attacks @@ -137,8 +131,7 @@ namespace NadekoBot.Modules.Pokemon return; } //get target stats - PokeStats targetStats; - targetStats = Stats.GetOrAdd(targetUser.Id, new PokeStats()); + var targetStats = _stats.GetOrAdd(targetUser.Id, new PokeStats()); //If target's HP is below 0, no use attacking if (targetStats.Hp <= 0) @@ -184,11 +177,11 @@ namespace NadekoBot.Modules.Pokemon if (targetStats.Hp <= 0) { - response += $"\n" + GetText("fainted", Format.Bold(targetUser.ToString())); + response += "\n" + GetText("fainted", Format.Bold(targetUser.ToString())); } else { - response += $"\n" + GetText("hp_remaining", Format.Bold(targetUser.ToString()), targetStats.Hp); + response += "\n" + GetText("hp_remaining", Format.Bold(targetUser.ToString()), targetStats.Hp); } //update other stats @@ -202,8 +195,8 @@ namespace NadekoBot.Modules.Pokemon //update dictionary //This can stay the same right? - Stats[user.Id] = userStats; - Stats[targetUser.Id] = targetStats; + _stats[user.Id] = userStats; + _stats[targetUser.Id] = targetStats; await Context.Channel.SendConfirmAsync(Context.User.Mention + " " + response).ConfigureAwait(false); } @@ -235,9 +228,9 @@ namespace NadekoBot.Modules.Pokemon return; } - if (Stats.ContainsKey(targetUser.Id)) + if (_stats.ContainsKey(targetUser.Id)) { - var targetStats = Stats[targetUser.Id]; + var targetStats = _stats[targetUser.Id]; if (targetStats.Hp == targetStats.MaxHp) { await ReplyErrorLocalized("already_full", Format.Bold(targetUser.ToString())).ConfigureAwait(false); @@ -261,7 +254,7 @@ namespace NadekoBot.Modules.Pokemon if (targetStats.Hp < 0) { //Could heal only for half HP? - Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2); + _stats[targetUser.Id].Hp = (targetStats.MaxHp / 2); if (target == "yourself") { await ReplyConfirmLocalized("revive_yourself", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); @@ -271,7 +264,6 @@ namespace NadekoBot.Modules.Pokemon await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); } await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); - return; } else { @@ -299,7 +291,7 @@ namespace NadekoBot.Modules.Pokemon var targetType = StringToPokemonType(typeTargeted); if (targetType == null) { - await Context.Channel.EmbedAsync(PokemonTypes.Aggregate(new EmbedBuilder().WithDescription("List of the available types:"), + await Context.Channel.EmbedAsync(_pokemonTypes.Aggregate(new EmbedBuilder().WithDescription("List of the available types:"), (eb, pt) => eb.AddField(efb => efb.WithName(pt.Name) .WithValue(pt.Icon) .WithIsInline(true))) @@ -324,12 +316,11 @@ namespace NadekoBot.Modules.Pokemon } //Actually changing the type here - Dictionary setTypes; using (var uow = DbHandler.UnitOfWork()) { - var pokeUsers = uow.PokeGame.GetAll(); - setTypes = pokeUsers.ToDictionary(x => x.UserId, y => y.type); + var pokeUsers = uow.PokeGame.GetAll().ToArray(); + var setTypes = pokeUsers.ToDictionary(x => x.UserId, y => y.type); var pt = new UserPokeTypes { UserId = user.Id, @@ -343,7 +334,7 @@ namespace NadekoBot.Modules.Pokemon else { //update user in db - var pokeUserCmd = pokeUsers.Where(p => p.UserId == user.Id).FirstOrDefault(); + var pokeUserCmd = pokeUsers.FirstOrDefault(p => p.UserId == user.Id); pokeUserCmd.type = targetType.Name; uow.PokeGame.Update(pokeUserCmd); }