Added achievement validation triggers #340 #1.1.0.rc3
This commit is contained in:
parent
aa2c80ec12
commit
4cea31fce5
@ -10,6 +10,9 @@ from modules.achievements.achievement_attribute_resolver import AchievementAttri
|
|||||||
from modules.achievements.achievement_service import AchievementService
|
from modules.achievements.achievement_service import AchievementService
|
||||||
from modules.achievements.commands.achievements_group import AchievementGroup
|
from modules.achievements.commands.achievements_group import AchievementGroup
|
||||||
from modules.achievements.events.achievement_on_message_event import AchievementOnMessageEvent
|
from modules.achievements.events.achievement_on_message_event import AchievementOnMessageEvent
|
||||||
|
from modules.achievements.events.achievement_on_reaction_add_event import AchievementOnReactionAddEvent
|
||||||
|
from modules.achievements.events.achievement_on_reaction_remove_event import AchievementOnReactionRemoveEvent
|
||||||
|
from modules.achievements.events.achievement_on_voice_state_update_event import AchievementOnVoiceStateUpdateEvent
|
||||||
|
|
||||||
|
|
||||||
class AchievementsModule(ModuleABC):
|
class AchievementsModule(ModuleABC):
|
||||||
@ -26,3 +29,6 @@ class AchievementsModule(ModuleABC):
|
|||||||
self._dc.add_command(AchievementGroup)
|
self._dc.add_command(AchievementGroup)
|
||||||
|
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_message.value, AchievementOnMessageEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_message.value, AchievementOnMessageEvent)
|
||||||
|
self._dc.add_event(DiscordEventTypesEnum.on_reaction_add.value, AchievementOnReactionAddEvent)
|
||||||
|
self._dc.add_event(DiscordEventTypesEnum.on_reaction_remove.value, AchievementOnReactionRemoveEvent)
|
||||||
|
self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, AchievementOnVoiceStateUpdateEvent)
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
from typing import Union
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
|
from cpl_discord.events import OnReactionAddABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
|
from bot_data.model.server_config import ServerConfig
|
||||||
|
from modules.achievements.achievement_service import AchievementService
|
||||||
|
|
||||||
|
|
||||||
|
class AchievementOnReactionAddEvent(OnReactionAddABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
logger: LoggerABC,
|
||||||
|
bot: DiscordBotServiceABC,
|
||||||
|
achievements: AchievementService,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
users: UserRepositoryABC,
|
||||||
|
):
|
||||||
|
OnReactionAddABC.__init__(self)
|
||||||
|
|
||||||
|
self._config = config
|
||||||
|
self._logger = logger
|
||||||
|
self._bot = bot
|
||||||
|
self._achievements = achievements
|
||||||
|
self._db = db
|
||||||
|
self._servers = servers
|
||||||
|
self._users = users
|
||||||
|
|
||||||
|
async def on_reaction_add(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]):
|
||||||
|
if not isinstance(user, discord.Member):
|
||||||
|
return
|
||||||
|
|
||||||
|
if user.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if user.bot:
|
||||||
|
return
|
||||||
|
|
||||||
|
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||||
|
server_config.feature_flags, FeatureFlagsEnum.achievements_module
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
server = self._servers.get_server_by_discord_id(user.guild.id)
|
||||||
|
user = self._users.get_user_by_discord_id_and_server_id(user.author.id, server.id)
|
||||||
|
|
||||||
|
user.reaction_count += 1
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
|
await self._achievements.validate_achievements_for_user(user)
|
@ -0,0 +1,61 @@
|
|||||||
|
from typing import Union
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
|
from cpl_discord.events import OnReactionRemoveABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
|
from bot_data.model.server_config import ServerConfig
|
||||||
|
from modules.achievements.achievement_service import AchievementService
|
||||||
|
|
||||||
|
|
||||||
|
class AchievementOnReactionRemoveEvent(OnReactionRemoveABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
logger: LoggerABC,
|
||||||
|
bot: DiscordBotServiceABC,
|
||||||
|
achievements: AchievementService,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
users: UserRepositoryABC,
|
||||||
|
):
|
||||||
|
OnReactionRemoveABC.__init__(self)
|
||||||
|
|
||||||
|
self._config = config
|
||||||
|
self._logger = logger
|
||||||
|
self._bot = bot
|
||||||
|
self._achievements = achievements
|
||||||
|
self._db = db
|
||||||
|
self._servers = servers
|
||||||
|
self._users = users
|
||||||
|
|
||||||
|
async def on_reaction_remove(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]):
|
||||||
|
if not isinstance(user, discord.Member):
|
||||||
|
return
|
||||||
|
|
||||||
|
if user.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if user.bot:
|
||||||
|
return
|
||||||
|
|
||||||
|
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||||
|
server_config.feature_flags, FeatureFlagsEnum.achievements_module
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
server = self._servers.get_server_by_discord_id(user.guild.id)
|
||||||
|
user = self._users.get_user_by_discord_id_and_server_id(user.author.id, server.id)
|
||||||
|
|
||||||
|
user.reaction_count -= 1
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
|
await self._achievements.validate_achievements_for_user(user)
|
@ -0,0 +1,55 @@
|
|||||||
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
|
from cpl_discord.events import OnVoiceStateUpdateABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
|
from bot_data.model.server_config import ServerConfig
|
||||||
|
from modules.achievements.achievement_service import AchievementService
|
||||||
|
|
||||||
|
|
||||||
|
class AchievementOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
logger: LoggerABC,
|
||||||
|
bot: DiscordBotServiceABC,
|
||||||
|
achievements: AchievementService,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
users: UserRepositoryABC,
|
||||||
|
):
|
||||||
|
OnVoiceStateUpdateABC.__init__(self)
|
||||||
|
|
||||||
|
self._config = config
|
||||||
|
self._logger = logger
|
||||||
|
self._bot = bot
|
||||||
|
self._achievements = achievements
|
||||||
|
self._db = db
|
||||||
|
self._servers = servers
|
||||||
|
self._users = users
|
||||||
|
|
||||||
|
async def on_voice_state_update(
|
||||||
|
self, member: discord.member.Member, before: discord.member.VoiceState, after: discord.member.VoiceState
|
||||||
|
):
|
||||||
|
if member.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if member.author.bot:
|
||||||
|
return
|
||||||
|
|
||||||
|
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||||
|
server_config.feature_flags, FeatureFlagsEnum.achievements_module
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||||
|
user = self._users.get_user_by_discord_id_and_server_id(member.author.id, server.id)
|
||||||
|
|
||||||
|
await self._achievements.validate_achievements_for_user(user)
|
Loading…
Reference in New Issue
Block a user