Compare commits
	
		
			2 Commits
		
	
	
		
			ba5d897662
			...
			6949db10f8
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6949db10f8 | |||
| 844a818aa0 | 
@@ -5,6 +5,7 @@ from cpl_core.environment import ApplicationEnvironmentABC
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from bot_data.abc.migration_abc import MigrationABC
 | 
					from bot_data.abc.migration_abc import MigrationABC
 | 
				
			||||||
from bot_data.migration.api_migration import ApiMigration
 | 
					from bot_data.migration.api_migration import ApiMigration
 | 
				
			||||||
 | 
					from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
 | 
				
			||||||
from bot_data.migration.auto_role_migration import AutoRoleMigration
 | 
					from bot_data.migration.auto_role_migration import AutoRoleMigration
 | 
				
			||||||
from bot_data.migration.initial_migration import InitialMigration
 | 
					from bot_data.migration.initial_migration import InitialMigration
 | 
				
			||||||
from bot_data.migration.level_migration import LevelMigration
 | 
					from bot_data.migration.level_migration import LevelMigration
 | 
				
			||||||
@@ -27,3 +28,4 @@ class StartupMigrationExtension(StartupExtensionABC):
 | 
				
			|||||||
        services.add_transient(MigrationABC, ApiMigration)  # 15.10.2022 #70 - 0.3.0
 | 
					        services.add_transient(MigrationABC, ApiMigration)  # 15.10.2022 #70 - 0.3.0
 | 
				
			||||||
        services.add_transient(MigrationABC, LevelMigration)  # 06.11.2022 #25 - 0.3.0
 | 
					        services.add_transient(MigrationABC, LevelMigration)  # 06.11.2022 #25 - 0.3.0
 | 
				
			||||||
        services.add_transient(MigrationABC, StatsMigration)  # 09.11.2022 #46 - 0.3.0
 | 
					        services.add_transient(MigrationABC, StatsMigration)  # 09.11.2022 #46 - 0.3.0
 | 
				
			||||||
 | 
					        services.add_transient(MigrationABC, AutoRoleFix1Migration)  # 30.12.2022 #151 - 0.3.0
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										29
									
								
								kdb-bot/src/bot_data/migration/auto_role_fix1_migration.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								kdb-bot/src/bot_data/migration/auto_role_fix1_migration.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					from bot_core.logging.database_logger import DatabaseLogger
 | 
				
			||||||
 | 
					from bot_data.abc.migration_abc import MigrationABC
 | 
				
			||||||
 | 
					from bot_data.db_context import DBContext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AutoRoleFix1Migration(MigrationABC):
 | 
				
			||||||
 | 
					    name = '0.3.0_AutoRoleMigration'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self, logger: DatabaseLogger, db: DBContext):
 | 
				
			||||||
 | 
					        MigrationABC.__init__(self)
 | 
				
			||||||
 | 
					        self._logger = logger
 | 
				
			||||||
 | 
					        self._db = db
 | 
				
			||||||
 | 
					        self._cursor = db.cursor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def upgrade(self):
 | 
				
			||||||
 | 
					        self._logger.debug(__name__, 'Running upgrade')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self._cursor.execute(
 | 
				
			||||||
 | 
					            str(f"""
 | 
				
			||||||
 | 
					            ALTER TABLE AutoRoles ADD DiscordChannelId BIGINT NOT NULL AFTER ServerId;
 | 
				
			||||||
 | 
					            """)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def downgrade(self):
 | 
				
			||||||
 | 
					        self._cursor.execute(
 | 
				
			||||||
 | 
					            str(f"""
 | 
				
			||||||
 | 
					            ALTER TABLE AutoRoles DROP COLUMN DiscordChannelId;
 | 
				
			||||||
 | 
					            """)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
@@ -6,9 +6,10 @@ from cpl_core.database import TableABC
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class AutoRole(TableABC):
 | 
					class AutoRole(TableABC):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, server_id: int, dc_message_id: int, created_at: datetime=None, modified_at: datetime=None, id=0):
 | 
					    def __init__(self, server_id: int, dc_channel_id: int, dc_message_id: int, created_at: datetime=None, modified_at: datetime=None, id=0):
 | 
				
			||||||
        self._auto_role_id = id
 | 
					        self._auto_role_id = id
 | 
				
			||||||
        self._server_id = server_id
 | 
					        self._server_id = server_id
 | 
				
			||||||
 | 
					        self._discord_channel_id = dc_channel_id
 | 
				
			||||||
        self._discord_message_id = dc_message_id
 | 
					        self._discord_message_id = dc_message_id
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        TableABC.__init__(self)
 | 
					        TableABC.__init__(self)
 | 
				
			||||||
@@ -23,6 +24,10 @@ class AutoRole(TableABC):
 | 
				
			|||||||
    def server_id(self) -> int:
 | 
					    def server_id(self) -> int:
 | 
				
			||||||
        return self._server_id
 | 
					        return self._server_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def discord_channel_id(self) -> int:
 | 
				
			||||||
 | 
					        return self._discord_channel_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def discord_message_id(self) -> int:
 | 
					    def discord_message_id(self) -> int:
 | 
				
			||||||
        return self._discord_message_id
 | 
					        return self._discord_message_id
 | 
				
			||||||
@@ -58,9 +63,10 @@ class AutoRole(TableABC):
 | 
				
			|||||||
    def insert_string(self) -> str:
 | 
					    def insert_string(self) -> str:
 | 
				
			||||||
        return str(f"""
 | 
					        return str(f"""
 | 
				
			||||||
            INSERT INTO `AutoRoles` (
 | 
					            INSERT INTO `AutoRoles` (
 | 
				
			||||||
                `ServerId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
 | 
					                `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
 | 
				
			||||||
            ) VALUES (
 | 
					            ) VALUES (
 | 
				
			||||||
                {self._server_id},
 | 
					                {self._server_id},
 | 
				
			||||||
 | 
					                {self._discord_channel_id},
 | 
				
			||||||
                {self._discord_message_id},
 | 
					                {self._discord_message_id},
 | 
				
			||||||
                '{self._created_at}',
 | 
					                '{self._created_at}',
 | 
				
			||||||
                '{self._modified_at}'
 | 
					                '{self._modified_at}'
 | 
				
			||||||
@@ -72,6 +78,7 @@ class AutoRole(TableABC):
 | 
				
			|||||||
        return str(f"""
 | 
					        return str(f"""
 | 
				
			||||||
            UPDATE `AutoRoles`
 | 
					            UPDATE `AutoRoles`
 | 
				
			||||||
            SET `ServerId` = {self._server_id},
 | 
					            SET `ServerId` = {self._server_id},
 | 
				
			||||||
 | 
					            `DiscordChannelId` = {self._discord_channel_id},
 | 
				
			||||||
            `DiscordMessageId` = {self._discord_message_id},
 | 
					            `DiscordMessageId` = {self._discord_message_id},
 | 
				
			||||||
            `LastModifiedAt` = '{self._modified_at}'
 | 
					            `LastModifiedAt` = '{self._modified_at}'
 | 
				
			||||||
            WHERE `AutoRoleId` = {self._auto_role_id};
 | 
					            WHERE `AutoRoleId` = {self._auto_role_id};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
                result[2],
 | 
					                result[2],
 | 
				
			||||||
                result[3],
 | 
					                result[3],
 | 
				
			||||||
                result[4],
 | 
					                result[4],
 | 
				
			||||||
 | 
					                result[5],
 | 
				
			||||||
                id=result[0]
 | 
					                id=result[0]
 | 
				
			||||||
            ))
 | 
					            ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,6 +41,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
            result[2],
 | 
					            result[2],
 | 
				
			||||||
            result[3],
 | 
					            result[3],
 | 
				
			||||||
            result[4],
 | 
					            result[4],
 | 
				
			||||||
 | 
					            result[5],
 | 
				
			||||||
            id=result[0]
 | 
					            id=result[0]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,6 +58,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
            result[2],
 | 
					            result[2],
 | 
				
			||||||
            result[3],
 | 
					            result[3],
 | 
				
			||||||
            result[4],
 | 
					            result[4],
 | 
				
			||||||
 | 
					            result[5],
 | 
				
			||||||
            id=result[0]
 | 
					            id=result[0]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -69,6 +72,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
                result[2],
 | 
					                result[2],
 | 
				
			||||||
                result[3],
 | 
					                result[3],
 | 
				
			||||||
                result[4],
 | 
					                result[4],
 | 
				
			||||||
 | 
					                result[5],
 | 
				
			||||||
                id=result[0]
 | 
					                id=result[0]
 | 
				
			||||||
            ))
 | 
					            ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -82,6 +86,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
            result[2],
 | 
					            result[2],
 | 
				
			||||||
            result[3],
 | 
					            result[3],
 | 
				
			||||||
            result[4],
 | 
					            result[4],
 | 
				
			||||||
 | 
					            result[5],
 | 
				
			||||||
            id=result[0]
 | 
					            id=result[0]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,6 +103,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
 | 
				
			|||||||
            result[2],
 | 
					            result[2],
 | 
				
			||||||
            result[3],
 | 
					            result[3],
 | 
				
			||||||
            result[4],
 | 
					            result[4],
 | 
				
			||||||
 | 
					            result[5],
 | 
				
			||||||
            id=result[0]
 | 
					            id=result[0]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -114,7 +114,7 @@ class AutoRoleGroup(DiscordCommandABC):
 | 
				
			|||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        server_id = self._servers.get_server_by_discord_id(ctx.guild.id).server_id
 | 
					        server_id = self._servers.get_server_by_discord_id(ctx.guild.id).server_id
 | 
				
			||||||
        self._auto_roles.add_auto_role(AutoRole(server_id, int(message_id)))
 | 
					        self._auto_roles.add_auto_role(AutoRole(server_id, int(channel.id), int(message_id)))
 | 
				
			||||||
        self._db_context.save_changes()
 | 
					        self._db_context.save_changes()
 | 
				
			||||||
        self._logger.info(__name__, f'Saved auto-role for message {message_id} at server {server_id}')
 | 
					        self._logger.info(__name__, f'Saved auto-role for message {message_id} at server {server_id}')
 | 
				
			||||||
        await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.success').format(message_id))
 | 
					        await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.success').format(message_id))
 | 
				
			||||||
@@ -239,8 +239,9 @@ class AutoRoleGroup(DiscordCommandABC):
 | 
				
			|||||||
        self._db_context.save_changes()
 | 
					        self._db_context.save_changes()
 | 
				
			||||||
        rule = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).single()
 | 
					        rule = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).single()
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            message = await ctx.fetch_message(auto_role_from_db.discord_message_id)
 | 
					 | 
				
			||||||
            guild: Guild = self._bot.guilds.where(lambda g: g == ctx.guild).single()
 | 
					            guild: Guild = self._bot.guilds.where(lambda g: g == ctx.guild).single()
 | 
				
			||||||
 | 
					            channel = guild.get_channel(auto_role_from_db.discord_channel_id)
 | 
				
			||||||
 | 
					            message = await channel.fetch_message(auto_role_from_db.discord_message_id)
 | 
				
			||||||
            emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
 | 
					            emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if emoji is None:
 | 
					            if emoji is None:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,6 +36,9 @@ class BaseReactionHandler:
 | 
				
			|||||||
            self._logger.warn(__name__, f'User {payload.user_id} in {guild.name} not found - skipping')
 | 
					            self._logger.warn(__name__, f'User {payload.user_id} in {guild.name} not found - skipping')
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if member.bot:
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        server = self._servers.get_server_by_discord_id(guild.id)
 | 
					        server = self._servers.get_server_by_discord_id(guild.id)
 | 
				
			||||||
        user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
 | 
					        user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
 | 
				
			||||||
        settings: BaseServerSettings = self._base_helper.get_config(guild.id)
 | 
					        settings: BaseServerSettings = self._base_helper.get_config(guild.id)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user