Added query #378
This commit is contained in:
parent
12f956f4c3
commit
5bfd04722c
@ -11,7 +11,7 @@ from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEn
|
|||||||
class ShortRoleName(TableABC):
|
class ShortRoleName(TableABC):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
short_name: str,
|
||||||
discord_role_id: int,
|
discord_role_id: int,
|
||||||
position: ShortRoleNamePositionEnum,
|
position: ShortRoleNamePositionEnum,
|
||||||
server: Server,
|
server: Server,
|
||||||
@ -20,7 +20,7 @@ class ShortRoleName(TableABC):
|
|||||||
id=0,
|
id=0,
|
||||||
):
|
):
|
||||||
self._id = id
|
self._id = id
|
||||||
self._name = name
|
self._short_name = short_name
|
||||||
self._discord_role_id = discord_role_id
|
self._discord_role_id = discord_role_id
|
||||||
self._position = position
|
self._position = position
|
||||||
self._server = server
|
self._server = server
|
||||||
@ -34,12 +34,12 @@ class ShortRoleName(TableABC):
|
|||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def short_name(self) -> str:
|
||||||
return self._name
|
return self._short_name
|
||||||
|
|
||||||
@name.setter
|
@short_name.setter
|
||||||
def name(self, value: str):
|
def short_name(self, value: str):
|
||||||
self._name = value
|
self._short_name = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def role_id(self) -> int:
|
def role_id(self) -> int:
|
||||||
@ -109,7 +109,7 @@ class ShortRoleName(TableABC):
|
|||||||
INSERT INTO `ShortRoleNames` (
|
INSERT INTO `ShortRoleNames` (
|
||||||
`Name`, `DiscordRoleId`, `Position`, `ServerId`
|
`Name`, `DiscordRoleId`, `Position`, `ServerId`
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'{self._name}',
|
'{self._short_name}',
|
||||||
{self._discord_role_id}
|
{self._discord_role_id}
|
||||||
'{self._position}',
|
'{self._position}',
|
||||||
{self._server.id},
|
{self._server.id},
|
||||||
@ -122,7 +122,7 @@ class ShortRoleName(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
UPDATE `ShortRoleNames`
|
UPDATE `ShortRoleNames`
|
||||||
SET `Name` = '{self._name}',
|
SET `Name` = '{self._short_name}',
|
||||||
`DiscordRoleId` = {self._discord_role_id},
|
`DiscordRoleId` = {self._discord_role_id},
|
||||||
`Position` = '{self._position}',
|
`Position` = '{self._position}',
|
||||||
`ServerId` = {self._server.id}
|
`ServerId` = {self._server.id}
|
||||||
|
@ -4,7 +4,7 @@ from cpl_discord.service import DiscordBotServiceABC
|
|||||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||||
|
|
||||||
|
|
||||||
class AutoRoleRuleHistory(HistoryTableABC):
|
class ShortRoleNameHistory(HistoryTableABC):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
|
70
kdb-bot/src/bot_graphql/filter/short_role_name_filter.py
Normal file
70
kdb-bot/src/bot_graphql/filter/short_role_name_filter.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
from cpl_query.extension import List
|
||||||
|
|
||||||
|
from bot_data.model.short_role_name import ShortRoleName
|
||||||
|
from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEnum
|
||||||
|
from bot_data.model.user import User
|
||||||
|
from bot_graphql.abc.filter_abc import FilterABC
|
||||||
|
|
||||||
|
|
||||||
|
class ShortRoleNameFilter(FilterABC):
|
||||||
|
def __init__(self, bot: DiscordBotServiceABC):
|
||||||
|
FilterABC.__init__(self)
|
||||||
|
self._bot = bot
|
||||||
|
|
||||||
|
self._id = None
|
||||||
|
self._short_name = None
|
||||||
|
self._role_id = None
|
||||||
|
self._role_name = None
|
||||||
|
self._position = None
|
||||||
|
self._server = None
|
||||||
|
|
||||||
|
def from_dict(self, values: dict):
|
||||||
|
if "id" in values:
|
||||||
|
self._id = int(values["id"])
|
||||||
|
|
||||||
|
if "shortName" in values:
|
||||||
|
self._short_name = values["shortName"]
|
||||||
|
|
||||||
|
if "roleId" in values:
|
||||||
|
self._role_id = int(values["roleId"])
|
||||||
|
|
||||||
|
if "roleName" in values:
|
||||||
|
self._role_name = values["roleName"]
|
||||||
|
|
||||||
|
if "position" in values:
|
||||||
|
self._position = ShortRoleNamePositionEnum(values["position"])
|
||||||
|
|
||||||
|
if "server" in values:
|
||||||
|
from bot_graphql.filter.server_filter import ServerFilter
|
||||||
|
|
||||||
|
self._server: ServerFilter = self._services.get_service(ServerFilter)
|
||||||
|
self._server.from_dict(values["server"])
|
||||||
|
|
||||||
|
def filter(self, query: List[User]) -> List[User]:
|
||||||
|
if self._id is not None:
|
||||||
|
query = query.where(lambda x: x.id == self._id)
|
||||||
|
|
||||||
|
if self._short_name is not None:
|
||||||
|
query = query.where(lambda x: x.short_name == self._short_name or self._short_name in x.short_name)
|
||||||
|
|
||||||
|
if self._role_id is not None:
|
||||||
|
query = query.where(lambda x: x.role_id == self._role_id)
|
||||||
|
|
||||||
|
if self._role_name is not None and self._role_id is not None:
|
||||||
|
|
||||||
|
def get_role_name(x: ShortRoleName):
|
||||||
|
guild = self._bot.get_guild(x.server.discord_id)
|
||||||
|
name = guild.get_role(x.role_id).name
|
||||||
|
return name == self._role_name or self._role_name in name
|
||||||
|
|
||||||
|
query = query.where(get_role_name)
|
||||||
|
|
||||||
|
if self._position is not None:
|
||||||
|
query = query.where(lambda x: x.position == self._position or self._position in x.position)
|
||||||
|
|
||||||
|
if self._server is not None:
|
||||||
|
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||||
|
query = query.where(lambda x: x.server.id in servers)
|
||||||
|
|
||||||
|
return query
|
@ -37,6 +37,9 @@ type Query {
|
|||||||
achievementAttributes: [AchievementAttribute]
|
achievementAttributes: [AchievementAttribute]
|
||||||
achievementOperators: [String]
|
achievementOperators: [String]
|
||||||
|
|
||||||
|
shortRoleNameCount: Int
|
||||||
|
shortRoleNames(filter: ShortRoleNameFilter, page: Page, sort: Sort): [ShortRoleName]
|
||||||
|
|
||||||
technicianConfig: TechnicianConfig
|
technicianConfig: TechnicianConfig
|
||||||
possibleFeatureFlags: [String]
|
possibleFeatureFlags: [String]
|
||||||
discord: Discord
|
discord: Discord
|
||||||
|
49
kdb-bot/src/bot_graphql/graphql/shortRoleName.gql
Normal file
49
kdb-bot/src/bot_graphql/graphql/shortRoleName.gql
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
type ShortRoleName implements TableWithHistoryQuery {
|
||||||
|
id: ID
|
||||||
|
shortName: String
|
||||||
|
roleId: String
|
||||||
|
roleName: String
|
||||||
|
position: String
|
||||||
|
|
||||||
|
server: Server
|
||||||
|
|
||||||
|
createdAt: String
|
||||||
|
modifiedAt: String
|
||||||
|
|
||||||
|
history: [ShortRoleNameHistory]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShortRoleNameHistory implements HistoryTableQuery {
|
||||||
|
id: ID
|
||||||
|
shortName: String
|
||||||
|
roleId: String
|
||||||
|
position: String
|
||||||
|
|
||||||
|
server: ID
|
||||||
|
|
||||||
|
deleted: Boolean
|
||||||
|
dateFrom: String
|
||||||
|
dateTo: String
|
||||||
|
}
|
||||||
|
|
||||||
|
input ShortRoleNameFilter {
|
||||||
|
id: ID
|
||||||
|
shortName: String
|
||||||
|
roleId: String
|
||||||
|
roleName: String
|
||||||
|
position: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShortRoleNameMutation {
|
||||||
|
createShortRoleName(input: ShortRoleNameInput!): ShortRoleName
|
||||||
|
updateShortRoleName(input: ShortRoleNameInput!): ShortRoleName
|
||||||
|
deleteShortRoleName(id: ID): ShortRoleName
|
||||||
|
}
|
||||||
|
|
||||||
|
input ShortRoleNameInput {
|
||||||
|
id: ID
|
||||||
|
shortName: String
|
||||||
|
roleId: String
|
||||||
|
roleName: String
|
||||||
|
position: String
|
||||||
|
}
|
@ -14,6 +14,7 @@ from bot_graphql.filter.auto_role_rule_filter import AutoRoleRuleFilter
|
|||||||
from bot_graphql.filter.client_filter import ClientFilter
|
from bot_graphql.filter.client_filter import ClientFilter
|
||||||
from bot_graphql.filter.level_filter import LevelFilter
|
from bot_graphql.filter.level_filter import LevelFilter
|
||||||
from bot_graphql.filter.server_filter import ServerFilter
|
from bot_graphql.filter.server_filter import ServerFilter
|
||||||
|
from bot_graphql.filter.short_role_name_filter import ShortRoleNameFilter
|
||||||
from bot_graphql.filter.user_filter import UserFilter
|
from bot_graphql.filter.user_filter import UserFilter
|
||||||
from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter
|
from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter
|
||||||
from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter
|
from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter
|
||||||
@ -51,6 +52,8 @@ from bot_graphql.queries.level_query import LevelQuery
|
|||||||
from bot_graphql.queries.server_config_query import ServerConfigQuery
|
from bot_graphql.queries.server_config_query import ServerConfigQuery
|
||||||
from bot_graphql.queries.server_history_query import ServerHistoryQuery
|
from bot_graphql.queries.server_history_query import ServerHistoryQuery
|
||||||
from bot_graphql.queries.server_query import ServerQuery
|
from bot_graphql.queries.server_query import ServerQuery
|
||||||
|
from bot_graphql.queries.short_role_name_history_query import ShortRoleNameHistoryQuery
|
||||||
|
from bot_graphql.queries.short_role_name_query import ShortRoleNameQuery
|
||||||
from bot_graphql.queries.technician_config_history_query import TechnicianConfigHistoryQuery
|
from bot_graphql.queries.technician_config_history_query import TechnicianConfigHistoryQuery
|
||||||
from bot_graphql.queries.technician_config_query import TechnicianConfigQuery
|
from bot_graphql.queries.technician_config_query import TechnicianConfigQuery
|
||||||
from bot_graphql.queries.technician_id_config_history_query import TechnicianIdConfigHistoryQuery
|
from bot_graphql.queries.technician_id_config_history_query import TechnicianIdConfigHistoryQuery
|
||||||
@ -110,6 +113,8 @@ class GraphQLModule(ModuleABC):
|
|||||||
services.add_transient(QueryABC, UserJoinedVoiceChannelQuery)
|
services.add_transient(QueryABC, UserJoinedVoiceChannelQuery)
|
||||||
services.add_transient(QueryABC, UserJoinedGameServerHistoryQuery)
|
services.add_transient(QueryABC, UserJoinedGameServerHistoryQuery)
|
||||||
services.add_transient(QueryABC, UserJoinedGameServerQuery)
|
services.add_transient(QueryABC, UserJoinedGameServerQuery)
|
||||||
|
services.add_transient(QueryABC, ShortRoleNameHistoryQuery)
|
||||||
|
services.add_transient(QueryABC, ShortRoleNameQuery)
|
||||||
|
|
||||||
services.add_transient(QueryABC, DiscordQuery)
|
services.add_transient(QueryABC, DiscordQuery)
|
||||||
services.add_transient(QueryABC, GuildQuery)
|
services.add_transient(QueryABC, GuildQuery)
|
||||||
@ -129,6 +134,7 @@ class GraphQLModule(ModuleABC):
|
|||||||
services.add_transient(FilterABC, UserJoinedServerFilter)
|
services.add_transient(FilterABC, UserJoinedServerFilter)
|
||||||
services.add_transient(FilterABC, UserJoinedVoiceChannelFilter)
|
services.add_transient(FilterABC, UserJoinedVoiceChannelFilter)
|
||||||
services.add_transient(FilterABC, UserJoinedGameServerFilter)
|
services.add_transient(FilterABC, UserJoinedGameServerFilter)
|
||||||
|
services.add_transient(FilterABC, ShortRoleNameFilter)
|
||||||
|
|
||||||
# mutations
|
# mutations
|
||||||
services.add_transient(QueryABC, AutoRoleMutation)
|
services.add_transient(QueryABC, AutoRoleMutation)
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||||
|
|
||||||
|
|
||||||
|
class ShortRoleNameHistoryQuery(HistoryQueryABC):
|
||||||
|
def __init__(self):
|
||||||
|
HistoryQueryABC.__init__(self, "ShortRoleName")
|
||||||
|
|
||||||
|
self.set_field("id", lambda x, *_: x.id)
|
||||||
|
self.set_field("shortName", lambda x, *_: x.shortName)
|
||||||
|
self.set_field("roleId", lambda x, *_: x.roleId)
|
||||||
|
self.set_field("position", lambda x, *_: x.position)
|
18
kdb-bot/src/bot_graphql/queries/short_role_name_query.py
Normal file
18
kdb-bot/src/bot_graphql/queries/short_role_name_query.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
|
||||||
|
from bot_data.model.short_role_name_history import ShortRoleNameHistory
|
||||||
|
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
||||||
|
|
||||||
|
|
||||||
|
class ShortRoleNameQuery(DataQueryWithHistoryABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
):
|
||||||
|
DataQueryWithHistoryABC.__init__(self, "ShortRoleName", "ShortRoleNamesHistory", ShortRoleNameHistory, db)
|
||||||
|
|
||||||
|
self.set_field("id", lambda x, *_: x.id)
|
||||||
|
self.set_field("shortName", lambda x, *_: x.short_name)
|
||||||
|
self.set_field("roleId", lambda x, *_: x.role_id)
|
||||||
|
self.set_field("roleName", lambda x, *_: x.role_name)
|
||||||
|
self.set_field("position", lambda x, *_: x.position)
|
@ -9,6 +9,7 @@ from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
|||||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryABC
|
||||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||||
@ -21,6 +22,7 @@ from bot_graphql.filter.auto_role_rule_filter import AutoRoleRuleFilter
|
|||||||
from bot_graphql.filter.client_filter import ClientFilter
|
from bot_graphql.filter.client_filter import ClientFilter
|
||||||
from bot_graphql.filter.level_filter import LevelFilter
|
from bot_graphql.filter.level_filter import LevelFilter
|
||||||
from bot_graphql.filter.server_filter import ServerFilter
|
from bot_graphql.filter.server_filter import ServerFilter
|
||||||
|
from bot_graphql.filter.short_role_name_filter import ShortRoleNameFilter
|
||||||
from bot_graphql.filter.user_filter import UserFilter
|
from bot_graphql.filter.user_filter import UserFilter
|
||||||
from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter
|
from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter
|
||||||
from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter
|
from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter
|
||||||
@ -44,6 +46,7 @@ class Query(QueryABC):
|
|||||||
user_joined_game_server: UserJoinedGameServerRepositoryABC,
|
user_joined_game_server: UserJoinedGameServerRepositoryABC,
|
||||||
users: UserRepositoryABC,
|
users: UserRepositoryABC,
|
||||||
achievements: AchievementRepositoryABC,
|
achievements: AchievementRepositoryABC,
|
||||||
|
short_role_names: ShortRoleNameRepositoryABC,
|
||||||
achievement_service: AchievementService,
|
achievement_service: AchievementService,
|
||||||
technician_config: TechnicianConfigRepositoryABC,
|
technician_config: TechnicianConfigRepositoryABC,
|
||||||
):
|
):
|
||||||
@ -71,6 +74,8 @@ class Query(QueryABC):
|
|||||||
)
|
)
|
||||||
self.add_collection("user", lambda *_: users.get_users(), UserFilter)
|
self.add_collection("user", lambda *_: users.get_users(), UserFilter)
|
||||||
self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter)
|
self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter)
|
||||||
|
self.add_collection("shortRoleName", lambda *_: short_role_names.get_short_role_names(), ShortRoleNameFilter)
|
||||||
|
|
||||||
self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config())
|
self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config())
|
||||||
|
|
||||||
self.set_field("achievementAttributes", lambda *_: achievement_service.get_attributes())
|
self.set_field("achievementAttributes", lambda *_: achievement_service.get_attributes())
|
||||||
|
Loading…
Reference in New Issue
Block a user