1.0.0 #253
@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
@ -18,6 +19,10 @@ class UserJoinedServerRepositoryABC(ABC):
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]:
|
||||
pass
|
||||
|
@ -1,10 +1,8 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class UserJoinedServer(TableABC):
|
||||
@ -69,6 +67,15 @@ class UserJoinedServer(TableABC):
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
|
@ -57,6 +57,21 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedServer.get(id)}",
|
||||
)
|
||||
result = self._context.select(UserJoinedServer.get_select_by_id_string(id))[0]
|
||||
return UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> List[UserJoinedServer]:
|
||||
joins = List(UserJoinedServer)
|
||||
self._logger.trace(
|
||||
|
@ -34,7 +34,7 @@ class QueryABC(ObjectType):
|
||||
return self._resolve_collection(get_collection(*args), *args, **kwargs)
|
||||
|
||||
self.set_field(f"{name}s", wrapper)
|
||||
self.set_field(f"{name}_count", lambda *args: get_collection(*args).count())
|
||||
self.set_field(f"{name}Count", lambda *args: get_collection(*args).count())
|
||||
|
||||
# @FilterABC.resolve_filter_annotation
|
||||
def _resolve_collection(self, collection: List, *_, filter: FilterABC = None, page: Page = None, sort: Sort = None):
|
||||
|
@ -24,14 +24,14 @@ class AutoRoleFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "channel_id" in values:
|
||||
self._channel_id = int(values["channel_id"])
|
||||
if "channelId" in values:
|
||||
self._channel_id = int(values["channelId"])
|
||||
|
||||
if "channel_name" in values:
|
||||
self._channel_name = values["channel_name"]
|
||||
if "channelName" in values:
|
||||
self._channel_name = values["channelName"]
|
||||
|
||||
if "message_id" in values:
|
||||
self._message_id = int(values["message_id"])
|
||||
if "messageId" in values:
|
||||
self._message_id = int(values["messageId"])
|
||||
|
||||
if "server" in values:
|
||||
from bot_graphql.filter.server_filter import ServerFilter
|
||||
|
@ -22,16 +22,16 @@ class AutoRoleRuleFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "emoji_name" in values:
|
||||
self._emoji_name = values["emoji_name"]
|
||||
if "emojiName" in values:
|
||||
self._emoji_name = values["emojiName"]
|
||||
|
||||
if "role_id" in values:
|
||||
self._role_id = int(values["role_id"])
|
||||
if "roleId" in values:
|
||||
self._role_id = int(values["roleId"])
|
||||
|
||||
if "role_name" in values:
|
||||
self._role_name = values["role_name"]
|
||||
if "roleName" in values:
|
||||
self._role_name = values["roleName"]
|
||||
|
||||
if "auto_role" in values:
|
||||
if "autoRole" in values:
|
||||
from bot_graphql.filter.auto_role_filter import AutoRoleFilter
|
||||
|
||||
self._auto_role: AutoRoleFilter = self._services.get_service(AutoRoleFilter)
|
||||
|
@ -17,8 +17,8 @@ class ClientFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "discord_id" in values:
|
||||
self._id = int(values["discord_id"])
|
||||
if "discordId" in values:
|
||||
self._id = int(values["discordId"])
|
||||
|
||||
if "name" in values:
|
||||
self._name = values["name"]
|
||||
|
@ -10,11 +10,11 @@ class Page(FilterABC):
|
||||
self._page_size = None
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
if "page_index" in values:
|
||||
self._page_index = int(values["page_index"])
|
||||
if "pageIndex" in values:
|
||||
self._page_index = int(values["pageIndex"])
|
||||
|
||||
if "page_size" in values:
|
||||
self._page_size = int(values["page_size"])
|
||||
if "pageSize" in values:
|
||||
self._page_size = int(values["pageSize"])
|
||||
|
||||
def filter(self, query: List, *args) -> List:
|
||||
if self._page_size is not None and self._page_index is not None:
|
||||
|
@ -19,8 +19,8 @@ class ServerFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "discord_id" in values:
|
||||
self._discord_id = int(values["discord_id"])
|
||||
if "discordId" in values:
|
||||
self._discord_id = int(values["discordId"])
|
||||
|
||||
if "name" in values:
|
||||
self._name = values["name"]
|
||||
|
@ -10,11 +10,11 @@ class Sort(FilterABC):
|
||||
self._sort_column = None
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
if "sort_direction" in values:
|
||||
self._sort_direction = values["sort_direction"]
|
||||
if "sortDirection" in values:
|
||||
self._sort_direction = values["sortDirection"]
|
||||
|
||||
if "sort_column" in values:
|
||||
self._sort_column = values["sort_column"]
|
||||
if "sortColumn" in values:
|
||||
self._sort_column = values["sortColumn"]
|
||||
|
||||
def filter(self, query: List, *args) -> List:
|
||||
return query
|
||||
|
@ -37,8 +37,8 @@ class UserFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "discord_id" in values:
|
||||
self._discord_id = int(values["discord_id"])
|
||||
if "discordId" in values:
|
||||
self._discord_id = int(values["discordId"])
|
||||
|
||||
if "name" in values:
|
||||
self._name = values["name"]
|
||||
|
@ -32,11 +32,11 @@ class UserJoinedServerFilter(FilterABC):
|
||||
self._user: UserFilter = self._services.get_service(UserFilter)
|
||||
self._user.from_dict(values["user"])
|
||||
|
||||
if "joined_on" in values:
|
||||
self._joined_on = values["joined_on"]
|
||||
if "joinedOn" in values:
|
||||
self._joined_on = values["joinedOn"]
|
||||
|
||||
if "leaved_on" in values:
|
||||
self._leaved_on = values["leaved_on"]
|
||||
if "leavedOn" in values:
|
||||
self._leaved_on = values["leavedOn"]
|
||||
|
||||
def filter(self, query: List[UserJoinedServer]) -> List[UserJoinedServer]:
|
||||
if self._id is not None:
|
||||
|
@ -28,11 +28,11 @@ class UserJoinedVoiceChannelFilter(FilterABC):
|
||||
if "id" in values:
|
||||
self._id = int(values["id"])
|
||||
|
||||
if "channel_id" in values:
|
||||
self._channel_id = int(values["channel_id"])
|
||||
if "channelId" in values:
|
||||
self._channel_id = int(values["channelId"])
|
||||
|
||||
if "channel_name" in values:
|
||||
self._channel_name = values["channel_name"]
|
||||
if "channelName" in values:
|
||||
self._channel_name = values["channelName"]
|
||||
|
||||
if "user" in values:
|
||||
from bot_graphql.filter.user_filter import UserFilter
|
||||
@ -40,11 +40,11 @@ class UserJoinedVoiceChannelFilter(FilterABC):
|
||||
self._user: UserFilter = self._services.get_service(UserFilter)
|
||||
self._user.from_dict(values["user"])
|
||||
|
||||
if "joined_on" in values:
|
||||
self._joined_on = values["joined_on"]
|
||||
if "joinedOn" in values:
|
||||
self._joined_on = values["joinedOn"]
|
||||
|
||||
if "leaved_on" in values:
|
||||
self._leaved_on = values["leaved_on"]
|
||||
if "leavedOn" in values:
|
||||
self._leaved_on = values["leavedOn"]
|
||||
|
||||
def filter(self, query: List[UserJoinedVoiceChannel]) -> List[UserJoinedVoiceChannel]:
|
||||
if self._id is not None:
|
||||
|
@ -47,6 +47,8 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_singleton(GraphQLService)
|
||||
services.add_singleton(Query)
|
||||
services.add_singleton(Mutation)
|
||||
|
||||
# queries
|
||||
services.add_transient(QueryABC, AutoRoleQuery)
|
||||
services.add_transient(QueryABC, AutoRoleRuleQuery)
|
||||
services.add_transient(QueryABC, ClientQuery)
|
||||
@ -57,6 +59,7 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_transient(QueryABC, UserJoinedServerQuery)
|
||||
services.add_transient(QueryABC, UserJoinedVoiceChannelQuery)
|
||||
|
||||
# filters
|
||||
services.add_singleton(FilterABC, AutoRoleFilter)
|
||||
services.add_singleton(FilterABC, AutoRoleRuleFilter)
|
||||
services.add_singleton(FilterABC, ClientFilter)
|
||||
@ -66,6 +69,7 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_singleton(FilterABC, UserJoinedServerFilter)
|
||||
services.add_singleton(FilterABC, UserJoinedVoiceChannelFilter)
|
||||
|
||||
# mutations
|
||||
services.add_transient(QueryABC, AutoRoleMutation)
|
||||
services.add_transient(QueryABC, AutoRoleRuleMutation)
|
||||
services.add_transient(QueryABC, LevelMutation)
|
||||
|
35
kdb-bot/src/bot_graphql/model/autoRole.gql
Normal file
35
kdb-bot/src/bot_graphql/model/autoRole.gql
Normal file
@ -0,0 +1,35 @@
|
||||
type AutoRole implements TableQuery {
|
||||
id: ID
|
||||
channelId: String
|
||||
channelName: String
|
||||
messageId: String
|
||||
|
||||
server: Server
|
||||
|
||||
autoRoleRuleCount: Int
|
||||
autoRoleRules(filter: AutoRoleRuleFilter, page: Page, sort: Sort): [AutoRoleRule]
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input AutoRoleFilter {
|
||||
id: ID
|
||||
channelId: String
|
||||
channelName: String
|
||||
messageId: String
|
||||
server: ServerFilter
|
||||
}
|
||||
|
||||
type AutoRoleMutation {
|
||||
createAutoRole(input: AutoRoleInput!): AutoRole
|
||||
updateAutoRole(input: AutoRoleInput!): AutoRole
|
||||
deleteAutoRole(id: ID): AutoRole
|
||||
}
|
||||
|
||||
input AutoRoleInput {
|
||||
id: ID!
|
||||
channelId: String!
|
||||
messageId: String!
|
||||
serverId: ID!
|
||||
}
|
32
kdb-bot/src/bot_graphql/model/autoRoleRule.gql
Normal file
32
kdb-bot/src/bot_graphql/model/autoRoleRule.gql
Normal file
@ -0,0 +1,32 @@
|
||||
type AutoRoleRule implements TableQuery {
|
||||
id: ID
|
||||
emojiName: String
|
||||
roleId: String
|
||||
roleName: String
|
||||
|
||||
autoRole: AutoRole
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input AutoRoleRuleFilter {
|
||||
id: ID
|
||||
emojiName: String
|
||||
roleId: String
|
||||
roleName: String
|
||||
autoRole: AutoRoleFilter
|
||||
}
|
||||
|
||||
type AutoRoleRuleMutation {
|
||||
createAutoRoleRule(input: AutoRoleRuleInput!): AutoRoleRule
|
||||
updateAutoRoleRule(input: AutoRoleRuleInput!): AutoRoleRule
|
||||
deleteAutoRoleRule(id: ID): AutoRoleRule
|
||||
}
|
||||
|
||||
input AutoRoleRuleInput {
|
||||
id: ID!
|
||||
emojiName: String!
|
||||
roleId: String!
|
||||
autoRoleId: ID!
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
type AutoRole implements TableQuery {
|
||||
id: ID
|
||||
channel_id: String
|
||||
channel_name: String
|
||||
message_id: String
|
||||
|
||||
server: Server
|
||||
|
||||
auto_role_rule_count: Int
|
||||
auto_role_rules(filter: AutoRoleRuleFilter, page: Page, sort: Sort): [AutoRoleRule]
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
}
|
||||
|
||||
input AutoRoleFilter {
|
||||
id: ID
|
||||
channel_id: String
|
||||
channel_name: String
|
||||
message_id: String
|
||||
server: ServerFilter
|
||||
}
|
||||
|
||||
type AutoRoleMutation {
|
||||
create_auto_role(input: AutoRoleInput!): AutoRole
|
||||
update_auto_role(input: AutoRoleInput!): AutoRole
|
||||
delete_auto_role(id: ID): AutoRole
|
||||
}
|
||||
|
||||
input AutoRoleInput {
|
||||
id: ID!
|
||||
channel_id: String!
|
||||
message_id: String!
|
||||
server_id: ID!
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
type AutoRoleRule implements TableQuery {
|
||||
id: ID
|
||||
emoji_name: String
|
||||
role_id: String
|
||||
role_name: String
|
||||
|
||||
auto_role: AutoRole
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
}
|
||||
|
||||
input AutoRoleRuleFilter {
|
||||
id: ID
|
||||
emoji_name: String
|
||||
role_id: String
|
||||
role_name: String
|
||||
auto_role: AutoRoleFilter
|
||||
}
|
||||
|
||||
type AutoRoleRuleMutation {
|
||||
create_auto_role_rule(input: AutoRoleRuleInput!): AutoRoleRule
|
||||
update_auto_role_rule(input: AutoRoleRuleInput!): AutoRoleRule
|
||||
delete_auto_role_rule(id: ID): AutoRoleRule
|
||||
}
|
||||
|
||||
input AutoRoleRuleInput {
|
||||
id: ID!
|
||||
emoji_name: String!
|
||||
role_id: String!
|
||||
auto_role_id: ID!
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
interface TableQuery {
|
||||
created_at: String
|
||||
modified_at: String
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input Page {
|
||||
page_index: Int
|
||||
page_size: Int
|
||||
pageIndex: Int
|
||||
pageSize: Int
|
||||
}
|
||||
|
||||
input Sort {
|
||||
sort_direction: String
|
||||
sort_column: String
|
||||
sortDirection: String
|
||||
sortColumn: String
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
type Client implements TableQuery {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
sent_message_count: Int
|
||||
received_message_count: Int
|
||||
deleted_message_count: Int
|
||||
received_command_count: Int
|
||||
moved_users_count: Int
|
||||
sentMessageCount: Int
|
||||
receivedMessageCount: Int
|
||||
deletedMessageCount: Int
|
||||
receivedCommandCount: Int
|
||||
movedUsersCount: Int
|
||||
|
||||
server: Server
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input ClientFilter {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
server: ServerFilter
|
||||
}
|
7
kdb-bot/src/bot_graphql/model/knownUser.gql
Normal file
7
kdb-bot/src/bot_graphql/model/knownUser.gql
Normal file
@ -0,0 +1,7 @@
|
||||
type KnownUser implements TableQuery {
|
||||
id: ID
|
||||
discordId: String
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
type KnownUser implements TableQuery {
|
||||
id: ID
|
||||
discord_id: String
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
}
|
@ -2,13 +2,13 @@ type Level implements TableQuery {
|
||||
id: ID
|
||||
name: String
|
||||
color: String
|
||||
min_xp: Int
|
||||
minXp: Int
|
||||
permissions: String
|
||||
|
||||
server: Server
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input LevelFilter {
|
||||
@ -18,16 +18,16 @@ input LevelFilter {
|
||||
}
|
||||
|
||||
type LevelMutation {
|
||||
create_level(input: LevelInput!): Level
|
||||
update_level(input: LevelInput!): Level
|
||||
delete_level(id: ID): Level
|
||||
createLevel(input: LevelInput!): Level
|
||||
updateLevel(input: LevelInput!): Level
|
||||
deleteLevel(id: ID): Level
|
||||
}
|
||||
|
||||
input LevelInput {
|
||||
id: ID
|
||||
name: String!
|
||||
color: String!
|
||||
min_xp: Int!
|
||||
minXp: Int!
|
||||
permissions: String!
|
||||
server_id: ID!
|
||||
serverId: ID!
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
type Mutation {
|
||||
auto_role: AutoRoleMutation
|
||||
auto_role_rule: AutoRoleRuleMutation
|
||||
autoRole: AutoRoleMutation
|
||||
autoRoleRule: AutoRoleRuleMutation
|
||||
level: LevelMutation
|
||||
user: UserMutation
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
type Query {
|
||||
auto_roles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
||||
auto_role_count: Int
|
||||
autoRoles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
||||
autoRole_count: Int
|
||||
|
||||
auto_role_rules(filter: AutoRoleRuleFilter, page: Page, sort: Sort): [AutoRoleRule]
|
||||
auto_role_rule_count: Int
|
||||
autoRoleRules(filter: AutoRoleRuleFilter, page: Page, sort: Sort): [AutoRoleRule]
|
||||
autoRoleRuleCount: Int
|
||||
|
||||
clients(filter: ClientFilter, page: Page, sort: Sort): [Client]
|
||||
client_count: Int
|
||||
clientCount: Int
|
||||
|
||||
known_users: [KnownUser]
|
||||
known_user_count: Int
|
||||
knownUsers: [KnownUser]
|
||||
knownUserCount: Int
|
||||
|
||||
levels(filter: LevelFilter, page: Page, sort: Sort): [Level]
|
||||
level_count: Int
|
||||
levelCount: Int
|
||||
|
||||
servers(filter: ServerFilter, page: Page, sort: Sort): [Server]
|
||||
server_count: Int
|
||||
serverCount: Int
|
||||
|
||||
user_joined_servers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [User]
|
||||
user_joined_server_count: Int
|
||||
userJoinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [User]
|
||||
userJoinedServerCount: Int
|
||||
|
||||
user_joined_voice_channels(filter: UserJoinedVoiceChannelFilter, page: Page, sort: Sort): [User]
|
||||
user_joined_voice_channel_count: Int
|
||||
userJoinedVoiceChannels(filter: UserJoinedVoiceChannelFilter, page: Page, sort: Sort): [User]
|
||||
userJoinedVoiceChannelCount: Int
|
||||
|
||||
users(filter: UserFilter, page: Page, sort: Sort): [User]
|
||||
user_count: Int
|
||||
userCount: Int
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
type Server implements TableQuery {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
|
||||
auto_roles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
||||
auto_role_count: Int
|
||||
autoRoles(filter: AutoRoleFilter, page: Page, sort: Sort): [AutoRole]
|
||||
autoRoleCount: Int
|
||||
|
||||
clients(filter: ClientFilter, page: Page, sort: Sort): [Client]
|
||||
client_count: Int
|
||||
|
||||
users(filter: UserFilter, page: Page, sort: Sort): [User]
|
||||
user_count: Int
|
||||
clientCount: Int
|
||||
|
||||
levels(filter: LevelFilter, page: Page, sort: Sort): [Level]
|
||||
level_count: Int
|
||||
levelCount: Int
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
users(filter: UserFilter, page: Page, sort: Sort): [User]
|
||||
userCount: Int
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input ServerFilter {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
type User implements TableQuery {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
xp: Int
|
||||
ontime: Float
|
||||
level: Level
|
||||
|
||||
joined_servers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer]
|
||||
joined_server_count: Int
|
||||
joinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer]
|
||||
joinedServerCount: Int
|
||||
|
||||
joined_voice_channels(filter: UserJoinedVoiceChannelFilter, page: Page, sort: Sort): [UserJoinedVoiceChannel]
|
||||
joined_voice_channel_count: Int
|
||||
joinedVoiceChannels(filter: UserJoinedVoiceChannelFilter, page: Page, sort: Sort): [UserJoinedVoiceChannel]
|
||||
joinedVoiceChannelCount: Int
|
||||
|
||||
server: Server
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input UserFilter {
|
||||
id: ID
|
||||
discord_id: String
|
||||
discordId: String
|
||||
name: String
|
||||
xp: Int
|
||||
ontime: Float
|
||||
@ -29,7 +29,7 @@ input UserFilter {
|
||||
}
|
||||
|
||||
type UserMutation {
|
||||
update_user(input: UserInput!): User
|
||||
updateUser(input: UserInput!): User
|
||||
}
|
||||
|
||||
input UserInput {
|
||||
|
@ -1,16 +1,16 @@
|
||||
type UserJoinedServer implements TableQuery {
|
||||
id: ID
|
||||
user: User
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input UserJoinedServerFilter {
|
||||
id: ID
|
||||
user: UserFilter
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
}
|
20
kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql
Normal file
20
kdb-bot/src/bot_graphql/model/userJoinedVoiceChannel.gql
Normal file
@ -0,0 +1,20 @@
|
||||
type UserJoinedVoiceChannel implements TableQuery {
|
||||
id: ID
|
||||
channelId: String
|
||||
channelName: String
|
||||
user: User
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
}
|
||||
|
||||
input UserJoinedVoiceChannelFilter {
|
||||
id: ID
|
||||
channelId: String
|
||||
channelName: String
|
||||
user: UserFilter
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
type UserJoinedVoiceChannel implements TableQuery {
|
||||
id: ID
|
||||
channel_id: String
|
||||
channel_name: String
|
||||
user: User
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
|
||||
created_at: String
|
||||
modified_at: String
|
||||
}
|
||||
|
||||
input UserJoinedVoiceChannelFilter {
|
||||
id: ID
|
||||
channel_id: String
|
||||
channel_name: String
|
||||
user: UserFilter
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
}
|
@ -1,14 +1,39 @@
|
||||
from ariadne import MutationType
|
||||
|
||||
from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
|
||||
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
|
||||
from bot_graphql.mutations.level_mutation import LevelMutation
|
||||
from bot_graphql.mutations.user_mutation import UserMutation
|
||||
|
||||
|
||||
class Mutation(MutationType):
|
||||
def __init__(self, level_mutation: LevelMutation):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role_mutation: AutoRoleMutation,
|
||||
auto_role_rule_mutation: AutoRoleRuleMutation,
|
||||
level_mutation: LevelMutation,
|
||||
user_mutation: UserMutation,
|
||||
):
|
||||
MutationType.__init__(self)
|
||||
|
||||
self._auto_role_mutation = auto_role_mutation
|
||||
self._auto_role_rule_mutation = auto_role_rule_mutation
|
||||
self._level_mutation = level_mutation
|
||||
self._user_mutation = user_mutation
|
||||
|
||||
self.set_field("autoRole", self.resolve_auto_role)
|
||||
self.set_field("autoRoleRule", self.resolve_auto_role_rule)
|
||||
self.set_field("level", self.resolve_level)
|
||||
self.set_field("user", self.resolve_user)
|
||||
|
||||
def resolve_auto_role(self, *_):
|
||||
return self._auto_role_mutation
|
||||
|
||||
def resolve_auto_role_rule(self, *_):
|
||||
return self._auto_role_rule_mutation
|
||||
|
||||
def resolve_level(self, *_):
|
||||
return self._level_mutation
|
||||
|
||||
def resolve_user(self, *_):
|
||||
return self._user_mutation
|
||||
|
@ -19,30 +19,28 @@ class AutoRoleMutation(QueryABC):
|
||||
self._auto_roles = auto_roles
|
||||
self._db = db
|
||||
|
||||
self.set_field("create_auto_role", self.resolve_create_auto_role)
|
||||
self.set_field("update_auto_role", self.resolve_update_auto_role)
|
||||
self.set_field("delete_auto_role", self.resolve_delete_auto_role)
|
||||
self.set_field("createAutoRole", self.resolve_create_auto_role)
|
||||
self.set_field("updateAutoRole", self.resolve_update_auto_role)
|
||||
self.set_field("deleteAutoRole", self.resolve_delete_auto_role)
|
||||
|
||||
def resolve_create_auto_role(self, *_, input: dict):
|
||||
auto_role = AutoRole(
|
||||
self._servers.get_server_by_id(input["server_id"]), input["channel_id"], input["message_id"]
|
||||
)
|
||||
auto_role = AutoRole(self._servers.get_server_by_id(input["serverId"]), input["channelId"], input["messageId"])
|
||||
self._auto_roles.add_auto_role(auto_role)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_new(x: AutoRole):
|
||||
return (
|
||||
x.server.server_id == input["server_id"]
|
||||
and x.discord_channel_id == input["channel_id"]
|
||||
and x.discord_message_id == input["message_id"]
|
||||
x.server.server_id == input["serverId"]
|
||||
and x.discord_channel_id == input["channelId"]
|
||||
and x.discord_message_id == input["messageId"]
|
||||
)
|
||||
|
||||
return self._auto_roles.get_auto_roles_by_server_id(auto_role.server.server_id).where(get_new)
|
||||
|
||||
def resolve_update_auto_role(self, *_, input: dict):
|
||||
auto_role = self._auto_roles.get_auto_role_by_id(input["id"])
|
||||
auto_role.discord_channel_id = input["channel_id"] if "channel_id" in input else auto_role.discord_channel_id
|
||||
auto_role.discord_message_id = input["message_id"] if "message_id" in input else auto_role.discord_message_id
|
||||
auto_role.discord_channel_id = input["channelId"] if "channelId" in input else auto_role.discord_channel_id
|
||||
auto_role.discord_message_id = input["messageId"] if "messageId" in input else auto_role.discord_message_id
|
||||
|
||||
self._auto_roles.update_auto_role(auto_role)
|
||||
self._db.save_changes()
|
||||
|
@ -19,22 +19,22 @@ class AutoRoleRuleMutation(QueryABC):
|
||||
self._auto_roles = auto_roles
|
||||
self._db = db
|
||||
|
||||
self.set_field("create_auto_role_rule", self.resolve_create_auto_role_rule)
|
||||
self.set_field("update_auto_role_rule", self.resolve_update_auto_role_rule)
|
||||
self.set_field("delete_auto_role_rule", self.resolve_delete_auto_role_rule)
|
||||
self.set_field("createAutoRoleRule", self.resolve_create_auto_role_rule)
|
||||
self.set_field("updateAutoRoleRule", self.resolve_update_auto_role_rule)
|
||||
self.set_field("deleteAutoRoleRule", self.resolve_delete_auto_role_rule)
|
||||
|
||||
def resolve_create_auto_role_rule(self, *_, input: dict):
|
||||
auto_role_rule = AutoRoleRule(
|
||||
self._auto_roles.get_auto_role_by_id(input["auto_role_id"]), input["emoji_name"], input["role_id"]
|
||||
self._auto_roles.get_auto_role_by_id(input["autoRoleId"]), input["emojiName"], input["roleId"]
|
||||
)
|
||||
self._auto_roles.add_auto_role_rule(auto_role_rule)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_new(x: AutoRoleRule):
|
||||
return (
|
||||
x.auto_role.auto_role_id == input["auto_role_id"]
|
||||
and x.emoji_name == input["emoji_name"]
|
||||
and x.role_id == input["role_id"]
|
||||
x.auto_role.auto_role_id == input["autoRoleId"]
|
||||
and x.emoji_name == input["emojiName"]
|
||||
and x.role_id == input["roleId"]
|
||||
)
|
||||
|
||||
return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.auto_role_id).where(
|
||||
@ -43,8 +43,8 @@ class AutoRoleRuleMutation(QueryABC):
|
||||
|
||||
def resolve_update_auto_role_rule(self, *_, input: dict):
|
||||
auto_role_rule = self._auto_roles.get_auto_role_rule_by_id(input["id"])
|
||||
auto_role_rule.emoji_name = input["emoji_name"] if "emoji_name" in input else auto_role_rule.emoji_name
|
||||
auto_role_rule.role_id = input["role_id"] if "role_id" in input else auto_role_rule.role_id
|
||||
auto_role_rule.emoji_name = input["emojiName"] if "emojiName" in input else auto_role_rule.emoji_name
|
||||
auto_role_rule.role_id = input["roleId"] if "roleId" in input else auto_role_rule.role_id
|
||||
|
||||
self._auto_roles.update_auto_role_rule(auto_role_rule)
|
||||
self._db.save_changes()
|
||||
|
@ -19,17 +19,17 @@ class LevelMutation(QueryABC):
|
||||
self._levels = levels
|
||||
self._db = db
|
||||
|
||||
self.set_field("create_level", self.resolve_create_level)
|
||||
self.set_field("update_level", self.resolve_update_level)
|
||||
self.set_field("delete_level", self.resolve_delete_level)
|
||||
self.set_field("createLevel", self.resolve_create_level)
|
||||
self.set_field("updateLevel", self.resolve_update_level)
|
||||
self.set_field("deleteLevel", self.resolve_delete_level)
|
||||
|
||||
def resolve_create_level(self, *_, input: dict):
|
||||
level = Level(
|
||||
input["name"],
|
||||
input["color"],
|
||||
int(input["min_xp"]),
|
||||
int(input["minXp"]),
|
||||
int(input["permissions"]),
|
||||
self._servers.get_server_by_id(input["server_id"]),
|
||||
self._servers.get_server_by_id(input["serverId"]),
|
||||
)
|
||||
self._levels.add_level(level)
|
||||
self._db.save_changes()
|
||||
@ -48,7 +48,7 @@ class LevelMutation(QueryABC):
|
||||
level = self._levels.get_level_by_id(input["id"])
|
||||
level.name = input["name"] if "name" in input else level.name
|
||||
level.color = input["color"] if "color" in input else level.color
|
||||
level.min_xp = input["min_xp"] if "min_xp" in input else level.min_xp
|
||||
level.min_xp = input["minXp"] if "minXp" in input else level.min_xp
|
||||
level.permissions = input["permissions"] if "permissions" in input else level.permissions
|
||||
|
||||
self._levels.update_level(level)
|
||||
|
@ -18,7 +18,7 @@ class UserMutation(QueryABC):
|
||||
self._users = users
|
||||
self._db = db
|
||||
|
||||
self.set_field("update_user", self.resolve_update_user)
|
||||
self.set_field("updateUser", self.resolve_update_user)
|
||||
|
||||
def resolve_update_user(self, *_, input: dict):
|
||||
user = self._users.get_user_by_id(input["id"])
|
||||
|
@ -21,12 +21,12 @@ class AutoRoleQuery(DataQueryABC):
|
||||
self._servers = servers
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("channel_id", self.resolve_channel_id)
|
||||
self.set_field("channel_name", self.resolve_channel_name)
|
||||
self.set_field("message_id", self.resolve_message_id)
|
||||
self.set_field("channelId", self.resolve_channel_id)
|
||||
self.set_field("channelName", self.resolve_channel_name)
|
||||
self.set_field("messageId", self.resolve_message_id)
|
||||
self.set_field("server", self.resolve_server)
|
||||
self.add_collection(
|
||||
"auto_role_rule", lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.auto_role_id)
|
||||
"autoRoleRule", lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.auto_role_id)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
@ -17,10 +17,10 @@ class AutoRoleRuleQuery(DataQueryABC):
|
||||
self._auto_roles = auto_roles
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("emoji_name", self.resolve_emoji_name)
|
||||
self.set_field("role_id", self.resolve_role_id)
|
||||
self.set_field("role_name", self.resolve_role_name)
|
||||
self.set_field("auto_role", self.resolve_auto_role)
|
||||
self.set_field("emojiName", self.resolve_emoji_name)
|
||||
self.set_field("roleId", self.resolve_role_id)
|
||||
self.set_field("roleName", self.resolve_role_name)
|
||||
self.set_field("autoRole", self.resolve_auto_role)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: AutoRoleRule, *_):
|
||||
|
@ -14,13 +14,13 @@ class ClientQuery(DataQueryABC):
|
||||
self._bot = bot
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("discord_id", self.resolve_discord_id)
|
||||
self.set_field("discordId", self.resolve_discord_id)
|
||||
self.set_field("name", self.resolve_name)
|
||||
self.set_field("sent_message_count", self.resolve_sent_message_count)
|
||||
self.set_field("received_message_count", self.resolve_received_message_count)
|
||||
self.set_field("deleted_message_count", self.resolve_deleted_message_count)
|
||||
self.set_field("received_command_count", self.resolve_received_command_count)
|
||||
self.set_field("moved_users_count", self.resolve_moved_users_count)
|
||||
self.set_field("sentMessageCount", self.resolve_sent_message_count)
|
||||
self.set_field("receivedMessageCount", self.resolve_received_message_count)
|
||||
self.set_field("deletedMessageCount", self.resolve_deleted_message_count)
|
||||
self.set_field("receivedCommandCount", self.resolve_received_command_count)
|
||||
self.set_field("movedUsersCount", self.resolve_moved_users_count)
|
||||
self.set_field("server", self.resolve_server)
|
||||
|
||||
@staticmethod
|
||||
|
@ -7,7 +7,7 @@ class KnownUserQuery(DataQueryABC):
|
||||
DataQueryABC.__init__(self, "KnownUser")
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("discord_id", self.resolve_discord_id)
|
||||
self.set_field("discordId", self.resolve_discord_id)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: KnownUser, *_):
|
||||
|
@ -9,7 +9,7 @@ class LevelQuery(DataQueryABC):
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("name", self.resolve_name)
|
||||
self.set_field("color", self.resolve_color)
|
||||
self.set_field("min_xp", self.resolve_min_xp)
|
||||
self.set_field("minXp", self.resolve_min_xp)
|
||||
self.set_field("permissions", self.resolve_permissions)
|
||||
self.set_field("server", self.resolve_server)
|
||||
|
||||
|
@ -3,6 +3,8 @@ from cpl_discord.service import DiscordBotServiceABC
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.server import Server
|
||||
from bot_graphql.abc.data_query_abc import DataQueryABC
|
||||
@ -15,28 +17,31 @@ class ServerQuery(DataQueryABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
auto_roles: AutoRoleRepositoryABC,
|
||||
clients: ClientRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
levels: LevelRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
ujs: UserJoinedServerRepositoryABC,
|
||||
ujvs: UserJoinedVoiceChannelRepositoryABC,
|
||||
):
|
||||
DataQueryABC.__init__(self, "Server")
|
||||
|
||||
self._bot = bot
|
||||
self._auto_roles = auto_roles
|
||||
self._users = users
|
||||
self._clients = clients
|
||||
self._users = users
|
||||
self._levels = levels
|
||||
self._users = users
|
||||
self._ujs = ujs
|
||||
self._ujvs = ujvs
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("discord_id", self.resolve_discord_id)
|
||||
self.set_field("discordId", self.resolve_discord_id)
|
||||
self.set_field("name", self.resolve_name)
|
||||
|
||||
self.add_collection(
|
||||
"auto_role", lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.server_id)
|
||||
)
|
||||
self.add_collection("client", lambda server, *_: self._clients.get_clients_by_server_id(server.server_id))
|
||||
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.server_id), UserFilter)
|
||||
self.add_collection("level", lambda server, *_: self._levels.get_levels_by_server_id(server.server_id))
|
||||
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.server_id), UserFilter)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, *_):
|
||||
|
@ -8,8 +8,8 @@ class UserJoinedServerQuery(DataQueryABC):
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("user", self.resolve_user)
|
||||
self.set_field("joined_on", self.resolve_joined_on)
|
||||
self.set_field("leaved_on", self.resolve_leaved_on)
|
||||
self.set_field("joinedOn", self.resolve_joined_on)
|
||||
self.set_field("leavedOn", self.resolve_leaved_on)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedServer, *_):
|
||||
|
@ -11,11 +11,11 @@ class UserJoinedVoiceChannelQuery(DataQueryABC):
|
||||
self._bot = bot
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("channel_id", self.resolve_channel_id)
|
||||
self.set_field("channel_name", self.resolve_channel_name)
|
||||
self.set_field("channelId", self.resolve_channel_id)
|
||||
self.set_field("channelName", self.resolve_channel_name)
|
||||
self.set_field("user", self.resolve_user)
|
||||
self.set_field("joined_on", self.resolve_joined_on)
|
||||
self.set_field("leaved_on", self.resolve_leaved_on)
|
||||
self.set_field("joinedOn", self.resolve_joined_on)
|
||||
self.set_field("leavedOn", self.resolve_leaved_on)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedVoiceChannel, *_):
|
||||
|
@ -26,16 +26,14 @@ class UserQuery(DataQueryABC):
|
||||
self._ujvs = ujvs
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
self.set_field("discord_id", self.resolve_discord_id)
|
||||
self.set_field("discordId", self.resolve_discord_id)
|
||||
self.set_field("name", self.resolve_name)
|
||||
self.set_field("xp", self.resolve_xp)
|
||||
self.set_field("ontime", self.resolve_ontime)
|
||||
self.set_field("level", self.resolve_level)
|
||||
self.add_collection("joinedServer", lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.user_id))
|
||||
self.add_collection(
|
||||
"joined_server", lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.user_id)
|
||||
)
|
||||
self.add_collection(
|
||||
"joined_voice_channel", lambda user, *_: self._ujvs.get_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
"joinedVoiceChannel", lambda user, *_: self._ujvs.get_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
)
|
||||
self.set_field("server", self.resolve_server)
|
||||
|
||||
|
@ -36,14 +36,14 @@ class Query(QueryABC):
|
||||
self._user_joined_voice_channels = user_joined_voice_channel
|
||||
self._users = users
|
||||
|
||||
self.add_collection("auto_role", lambda *_: self._auto_roles.get_auto_roles(), AutoRoleFilter)
|
||||
self.add_collection("auto_role_rule", lambda *_: self._auto_roles.get_auto_role_rules(), AutoRoleRuleFilter)
|
||||
self.add_collection("autoRole", lambda *_: self._auto_roles.get_auto_roles(), AutoRoleFilter)
|
||||
self.add_collection("autoRoleRule", lambda *_: self._auto_roles.get_auto_role_rules(), AutoRoleRuleFilter)
|
||||
self.add_collection("client", lambda *_: self._clients.get_clients())
|
||||
self.add_collection("known_user", lambda *_: self._known_users.get_users())
|
||||
self.add_collection("knowUser", lambda *_: self._known_users.get_users())
|
||||
self.add_collection("level", lambda *_: self._levels.get_levels(), LevelFilter)
|
||||
self.add_collection("server", lambda *_: self._servers.get_servers(), ServerFilter)
|
||||
self.add_collection("user_joined_server", lambda *_: self._user_joined_servers.get_user_joined_servers())
|
||||
self.add_collection("userJoinedServer", lambda *_: self._user_joined_servers.get_user_joined_servers())
|
||||
self.add_collection(
|
||||
"user_joined_voice_channel", lambda *_: self._user_joined_voice_channels.get_user_joined_voice_channels()
|
||||
"userJoinedVoiceChannel", lambda *_: self._user_joined_voice_channels.get_user_joined_voice_channels()
|
||||
)
|
||||
self.add_collection("user", lambda *_: self._users.get_users(), UserFilter)
|
||||
|
Loading…
Reference in New Issue
Block a user