Added client filter #162
This commit is contained in:
parent
3f7cfc47af
commit
36fd3c73b9
47
kdb-bot/src/bot_graphql/filter/client_filter.py
Normal file
47
kdb-bot/src/bot_graphql/filter/client_filter.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from cpl_query.extension import List
|
||||||
|
|
||||||
|
from bot_data.model.client import Client
|
||||||
|
from bot_graphql.abc.filter_abc import FilterABC
|
||||||
|
|
||||||
|
|
||||||
|
class ClientFilter(FilterABC):
|
||||||
|
def __init__(self):
|
||||||
|
FilterABC.__init__(self)
|
||||||
|
|
||||||
|
self._id = None
|
||||||
|
self._discord_id = None
|
||||||
|
self._name = None
|
||||||
|
self._server = None
|
||||||
|
|
||||||
|
def from_dict(self, values: dict):
|
||||||
|
if "id" in values:
|
||||||
|
self._id = int(values["id"])
|
||||||
|
|
||||||
|
if "discord_id" in values:
|
||||||
|
self._id = int(values["discord_id"])
|
||||||
|
|
||||||
|
if "name" in values:
|
||||||
|
self._name = values["name"]
|
||||||
|
|
||||||
|
if "server" in values:
|
||||||
|
from bot_graphql.filter.server_filter import ServerFilter
|
||||||
|
|
||||||
|
server = ServerFilter()
|
||||||
|
server.from_dict(values["server"])
|
||||||
|
self._server = server
|
||||||
|
|
||||||
|
def filter(self, query: List[Client]) -> List[Client]:
|
||||||
|
if self._id is not None:
|
||||||
|
query = query.where(lambda x: x.client_id == self._id)
|
||||||
|
|
||||||
|
if self._discord_id is not None:
|
||||||
|
query = query.where(lambda x: x.client_id == self._discord_id)
|
||||||
|
|
||||||
|
if self._name is not None:
|
||||||
|
query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower())
|
||||||
|
|
||||||
|
if self._server is not None:
|
||||||
|
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||||
|
query = query.where(lambda x: x.server.server_id in servers)
|
||||||
|
|
||||||
|
return query
|
@ -18,10 +18,5 @@ input ClientFilter {
|
|||||||
id: ID
|
id: ID
|
||||||
discord_id: String
|
discord_id: String
|
||||||
name: String
|
name: String
|
||||||
sent_message_count: Int
|
|
||||||
received_message_count: Int
|
|
||||||
deleted_message_count: Int
|
|
||||||
received_command_count: Int
|
|
||||||
moved_users_count: Int
|
|
||||||
server: ServerFilter
|
server: ServerFilter
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ type Server implements TableQuery {
|
|||||||
auto_roles: [AutoRole]
|
auto_roles: [AutoRole]
|
||||||
auto_role_count: Int
|
auto_role_count: Int
|
||||||
|
|
||||||
clients: [Client]
|
clients(filter: ClientFilter, page: Page, sort: Sort): [Client]
|
||||||
client_count: Int
|
client_count: Int
|
||||||
|
|
||||||
users(filter: UserFilter): [User]
|
users(filter: UserFilter): [User]
|
||||||
|
Loading…
Reference in New Issue
Block a user