From 81406cb46acae461a027bc1c03d36a722c1cf876 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 19 Jun 2021 07:21:10 +0200 Subject: [PATCH] Cleanup, Added string and repeat limit fixes from 1.9 branch --- .../Db/Extensions/WaifuExtensions.cs | 11 -- .../Games/Services/GamesConfigService.cs | 150 ------------------ .../Utility/Services/RepeaterService.cs | 2 +- src/NadekoBot/NadekoBot.csproj | 2 +- .../strings/responses/responses.en-US.json | 1 + 5 files changed, 3 insertions(+), 163 deletions(-) diff --git a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs index d38f22e44..6728f77a1 100644 --- a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs +++ b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs @@ -77,17 +77,6 @@ namespace NadekoBot.Db .Sum(x => x.Price); } - public static int AffinityCount(this DbSet updates, ulong userId) - { - return updates - .FromSqlInterpolated($@"SELECT 1 -FROM WaifuUpdates -WHERE UserId = (SELECT Id from DiscordUser WHERE UserId={userId}) AND - UpdateType = 0 AND - NewId IS NOT NULL") - .Count(); - } - public static ulong GetWaifuUserId(this DbSet waifus, ulong ownerId, string name) { return waifus diff --git a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs index 971223e14..4f9575a31 100644 --- a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs +++ b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs @@ -20,154 +20,4 @@ namespace NadekoBot.Modules.Games.Services ConfigPrinters.ToString, val => val >= 0); } } - - // public sealed class GamesConfigMigrator : IConfigMigrator - // { - // // private readonly DbService _db; - // private readonly GamesConfigService _gss; - // - // public GamesConfigMigrator(DbService dbService, GamesConfigService gss) - // { - // _log = LogManager.GetCurrentClassLogger(); - // _db = dbService; - // _gss = gss; - // } - // - // public void EnsureMigrated() - // { - // using var uow = _db.GetDbContext(); - // using var conn = uow.Database.GetDbConnection(); - // MigrateRaceAnimals(conn); - // MigrateEightBall(conn); - // } - // - // private void MigrateTrivia(DbConnection conn) - // { - // using (var checkTableCommand = conn.CreateCommand()) - // { - // // make sure table still exists - // checkTableCommand.CommandText = - // "SELECT name FROM sqlite_master WHERE type='table' AND name='BotConfig';"; - // var checkReader = checkTableCommand.ExecuteReader(); - // if (!checkReader.HasRows) - // return; - // } - // - // Log.Information("Migrating trivia..."); - // - // using var com = conn.CreateCommand(); - // com.CommandText = $@"SELECT MinimumTriviaWinReq, TriviaCurrencyReward FROM BotConfig"; - // using var reader = com.ExecuteReader(); - // - // if (!reader.Read()) - // return; - // - // _gss.ModifyConfig(ModifyTriviaAction(reader)); - // - // Log.Information("Trivia config migrated to data/games.yml"); - // } - // - // private static Action ModifyTriviaAction(DbDataReader reader) - // => realConfig => - // { - // var val = (int) (long) reader["MinimumTriviaWinReq"]; - // realConfig.Trivia.MinimumWinReq = val <= 0 ? 1 : val; - // realConfig.Trivia.CurrencyReward = (long) reader["TriviaCurrencyReward"]; - // }; - // - // private void MigrateEightBall(DbConnection conn) - // { - // using (var checkTableCommand = conn.CreateCommand()) - // { - // // make sure table still exists - // checkTableCommand.CommandText = - // "SELECT name FROM sqlite_master WHERE type='table' AND name='EightBallResponses';"; - // var checkReader = checkTableCommand.ExecuteReader(); - // if (!checkReader.HasRows) - // return; - // } - // - // try - // { - // using (var com = conn.CreateCommand()) - // { - // com.CommandText = $@"SELECT Text FROM EightBallResponses"; - // using var reader = com.ExecuteReader(); - // - // if (!reader.Read()) - // return; - // - // Log.Information("Migrating eightball..."); - // _gss.ModifyConfig(Modify8ballAction(reader)); - // } - // - // Log.Information("Eightball migrated to data/games.yml"); - // MigrateTrivia(conn); - // } - // finally - // { - // - // using var deleteEightBallCommand = conn.CreateCommand(); - // deleteEightBallCommand.CommandText = "DROP TABLE IF EXISTS EightBallResponses"; - // deleteEightBallCommand.ExecuteNonQuery(); - // } - // - // } - // - // private static Action Modify8ballAction(DbDataReader reader) - // => realConfig => - // { - // realConfig.EightBallResponses.Clear(); - // do - // { - // realConfig.EightBallResponses.Add((string) reader["Text"]); - // } while (reader.Read()); - // }; - // - // private void MigrateRaceAnimals(DbConnection conn) - // { - // using (var checkTableCommand = conn.CreateCommand()) - // { - // // make sure table still exists - // checkTableCommand.CommandText = - // "SELECT name FROM sqlite_master WHERE type='table' AND name='RaceAnimals';"; - // var checkReader = checkTableCommand.ExecuteReader(); - // if (!checkReader.HasRows) - // return; - // } - // - // using (var com = conn.CreateCommand()) - // { - // com.CommandText = $@"SELECT Name, Icon FROM RaceAnimals"; - // using var reader = com.ExecuteReader(); - // - // if (!reader.Read()) - // return; - // - // Log.Information("Migrating race animals..."); - // _gss.ModifyConfig(ModifyRaceAnimalsAction(reader)); - // } - // - // Log.Information("Race animals migrated to data/games.yml"); - // - // using var deleteRaceAnimalsCommand = conn.CreateCommand(); - // deleteRaceAnimalsCommand.CommandText = "DROP TABLE IF EXISTS RaceAnimals"; - // deleteRaceAnimalsCommand.ExecuteNonQuery(); - // } - // - // private static Action ModifyRaceAnimalsAction(DbDataReader reader) - // => realConfig => - // { - // realConfig.RaceAnimals.Clear(); - // - // do - // { - // realConfig.RaceAnimals.Add(new RaceAnimal() - // { - // Icon = (string) reader["Icon"], - // Name = (string) reader["Name"] - // }); - // } while (reader.Read()); - // }; - // } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs index 59ae495c9..3cd802c38 100644 --- a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs @@ -343,7 +343,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") using var uow = _db.GetDbContext(); - if (await uow.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS) + if (await uow.Repeaters.AsNoTracking().CountAsyncEF(x => x.GuildId == guildId) < MAX_REPEATERS) uow.Repeaters.Add(rep); else return null; diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 05da25ac2..4f3079ffd 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -70,7 +70,7 @@ - 2.0.0 + 3.0.0 $(VersionPrefix).$(VersionSuffix) $(VersionPrefix) diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index 0b893b653..02c49276c 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -626,6 +626,7 @@ "messages": "Messages", "repeater_created": "Repeater Created", "repeater_removed": "Repeater #{0} Removed", + "repeater_exceed_limit": "You cannot have more than {0} repeaters per server.", "repeater_remove_fail": "Failed removing repeater on that index. Either you've specified invalid index, or repeater was in executing state at that time, in which case, try again in a few seconds.", "interval:": "Interval:", "executes_in:": "Executes in:",