Merge branch 'support' into 1.1.0 #1.1.0
# Conflicts: # kdb-bot/src/bot/config # kdb-bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py
This commit is contained in:
commit
99e75ba325
@ -2,6 +2,7 @@ from typing import Callable
|
|||||||
|
|
||||||
from ariadne import ObjectType
|
from ariadne import ObjectType
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
|
from cpl_core.type import T
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ class QueryABC(ObjectType):
|
|||||||
self.set_field(f"{name}Count", lambda *args: wrapper(*args).count())
|
self.set_field(f"{name}Count", lambda *args: wrapper(*args).count())
|
||||||
|
|
||||||
@ServiceProviderABC.inject
|
@ServiceProviderABC.inject
|
||||||
def _can_user_see_element(self, user: AuthUser, element, services: ServiceProviderABC) -> bool:
|
def _can_user_see_element(self, user: AuthUser, element: T, services: ServiceProviderABC) -> bool:
|
||||||
permissions: PermissionService = services.get_service(PermissionService)
|
permissions: PermissionService = services.get_service(PermissionService)
|
||||||
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
|
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
|
||||||
|
|
||||||
@ -82,12 +83,12 @@ class QueryABC(ObjectType):
|
|||||||
break
|
break
|
||||||
|
|
||||||
elif type(element) == AutoRoleRule:
|
elif type(element) == AutoRoleRule:
|
||||||
element: AutoRole = element
|
element: AutoRoleRule = element
|
||||||
for u in user.users:
|
for u in user.users:
|
||||||
u: User = u
|
u: User = u
|
||||||
guild = bot.get_guild(u.server.discord_id)
|
guild = bot.get_guild(u.server.discord_id)
|
||||||
member = guild.get_member(u.discord_id)
|
member = guild.get_member(u.discord_id)
|
||||||
if permissions.is_member_moderator(member) and u.server.id == element.server.id:
|
if permissions.is_member_moderator(member) and u.server.id == element.auto_role.server.id:
|
||||||
access = True
|
access = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -26,7 +26,11 @@ class BaseOnScheduledEventUpdateEvent(OnScheduledEventUpdateABC):
|
|||||||
|
|
||||||
# save started event
|
# save started event
|
||||||
if before.status != after.status and after.status == EventStatus.active:
|
if before.status != after.status and after.status == EventStatus.active:
|
||||||
self._events.add_event(ActiveEvent(after))
|
active_event = ActiveEvent(after)
|
||||||
|
self._events.add_event(active_event)
|
||||||
|
|
||||||
|
for member in after.channel.members:
|
||||||
|
self._events.give_xp_for_event_participation(member, active_event)
|
||||||
# delete stopped event
|
# delete stopped event
|
||||||
if before.status != after.status and (
|
if before.status != after.status and (
|
||||||
after.status.value == EventStatus.cancelled.value or after.status.value == EventStatus.completed.value
|
after.status.value == EventStatus.cancelled.value or after.status.value == EventStatus.completed.value
|
||||||
|
@ -7,7 +7,8 @@ from cpl_discord.events import OnVoiceStateUpdateABC
|
|||||||
from bot_core.helper.event_checks import EventChecks
|
from bot_core.helper.event_checks import EventChecks
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
from bot_data.model.server_config import ServerConfig
|
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||||
|
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||||
from modules.base.service.event_service import EventService
|
from modules.base.service.event_service import EventService
|
||||||
|
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
|||||||
self,
|
self,
|
||||||
config: ConfigurationABC,
|
config: ConfigurationABC,
|
||||||
logger: LoggerABC,
|
logger: LoggerABC,
|
||||||
|
base_helper: BaseHelperABC,
|
||||||
servers: ServerRepositoryABC,
|
servers: ServerRepositoryABC,
|
||||||
users: UserRepositoryABC,
|
users: UserRepositoryABC,
|
||||||
events: EventService,
|
events: EventService,
|
||||||
@ -24,6 +26,7 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
|||||||
OnVoiceStateUpdateABC.__init__(self)
|
OnVoiceStateUpdateABC.__init__(self)
|
||||||
self._config = config
|
self._config = config
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
|
self._base_helper = base_helper
|
||||||
self._servers = servers
|
self._servers = servers
|
||||||
self._users = users
|
self._users = users
|
||||||
self._events = events
|
self._events = events
|
||||||
@ -48,16 +51,6 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
|||||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||||
return
|
return
|
||||||
|
|
||||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
self._events.give_xp_for_event_participation(member, active_event)
|
||||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if active_event.participants.any(lambda x: x.id == user.id):
|
|
||||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
|
||||||
return
|
|
||||||
|
|
||||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
|
||||||
user.xp += settings.xp_per_event_participation
|
|
||||||
self._users.update_user(user)
|
|
||||||
self._db.save_changes()
|
|
||||||
active_event.participants.append(user)
|
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||||
|
@ -1,13 +1,35 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
|
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||||
from modules.base.model.active_event import ActiveEvent
|
from modules.base.model.active_event import ActiveEvent
|
||||||
|
from modules.base.service.base_helper_service import BaseHelperService
|
||||||
|
|
||||||
|
|
||||||
class EventService:
|
class EventService:
|
||||||
def __init__(self):
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
logger: LoggerABC,
|
||||||
|
base_helper: BaseHelperService,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
users: UserRepositoryABC,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
):
|
||||||
|
self._config = config
|
||||||
|
self._logger = logger
|
||||||
|
self._base_helper = base_helper
|
||||||
|
self._servers = servers
|
||||||
|
self._users = users
|
||||||
|
self._db = db
|
||||||
|
|
||||||
self._active_events = List(ActiveEvent)
|
self._active_events = List(ActiveEvent)
|
||||||
|
|
||||||
def add_event(self, event: ActiveEvent):
|
def add_event(self, event: ActiveEvent):
|
||||||
@ -29,3 +51,16 @@ class EventService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._active_events.remove(event)
|
self._active_events.remove(event)
|
||||||
|
|
||||||
|
def give_xp_for_event_participation(self, member: discord.Member, active_event: ActiveEvent):
|
||||||
|
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||||
|
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||||
|
if active_event.participants.any(lambda x: x.id == user.id):
|
||||||
|
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||||
|
return
|
||||||
|
|
||||||
|
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||||
|
user.xp += settings.xp_per_event_participation
|
||||||
|
self._users.update_user(user)
|
||||||
|
self._db.save_changes()
|
||||||
|
active_event.participants.append(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user