mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	Cleanup, Added string and repeat limit fixes from 1.9 branch
This commit is contained in:
		@@ -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<GamesConfig> 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<GamesConfig> 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<GamesConfig> ModifyRaceAnimalsAction(DbDataReader reader)
 | 
			
		||||
    //         => realConfig =>
 | 
			
		||||
    //         {
 | 
			
		||||
    //             realConfig.RaceAnimals.Clear();
 | 
			
		||||
    //
 | 
			
		||||
    //             do
 | 
			
		||||
    //             {
 | 
			
		||||
    //                 realConfig.RaceAnimals.Add(new RaceAnimal()
 | 
			
		||||
    //                 {
 | 
			
		||||
    //                     Icon = (string) reader["Icon"],
 | 
			
		||||
    //                     Name = (string) reader["Name"]
 | 
			
		||||
    //                 });
 | 
			
		||||
    //             } while (reader.Read());
 | 
			
		||||
    //         };
 | 
			
		||||
    // }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user