text stringlengths 1 93.6k |
|---|
async def insert_admin(self, user_id: int) -> None:
|
if await self.query_user(user_id):
|
await self.execute(
|
"""UPDATE "user_list" SET "authorized" = true WHERE "id" = $1""",
|
user_id,
|
)
|
else:
|
await self.execute(
|
"""INSERT INTO "user_list" ("id", "authorized") VALUES ($1, true)""",
|
user_id,
|
)
|
async def remove_admin(self, user_id: int) -> None:
|
await self.execute(
|
"""UPDATE "user_list" SET "authorized" = false WHERE "id" = $1""", user_id
|
)
|
async def query_all_admin(self) -> list[int]:
|
return [
|
x["id"]
|
for x in await self.query(
|
"""SELECT "id" FROM "user_list" WHERE "authorized" = true"""
|
)
|
]
|
async def query_all_bypass(self) -> list[int]:
|
return [
|
x["id"]
|
for x in await self.query(
|
"""SELECT "id" FROM "user_list" WHERE "bypass" = true"""
|
)
|
]
|
async def query_all_blacklist(self) -> list[int]:
|
return [x["id"] for x in await self.query('''SELECT "id" FROM "blacklist"''')]
|
async def query_all_special_forward(self) -> dict[str, str]:
|
return {
|
str(x["chat_id"]): str(x["target"])
|
for x in await self.query('''SELECT * FROM "special_forward"''')
|
}
|
async def query_forward_from(
|
self, chat_id: int, message_id: int
|
) -> asyncpg.Record | None:
|
return await self.query1(
|
"""SELECT "from_chat", "from_user", "forward_from"
|
FROM "msg_detail" WHERE "to_chat" = $1 AND "to_msg" = $2""",
|
chat_id,
|
message_id,
|
) # type: ignore
|
_instance = None
|
@classmethod
|
def get_instance(cls) -> CheckFile:
|
if cls._instance is None:
|
raise RuntimeError("Instance not initialized")
|
return cls._instance
|
@classmethod
|
async def init_instance(
|
cls, host: str, port: int, username: str, password: str, database: str
|
) -> CheckFile:
|
cls._instance = await cls.create(host, port, username, password, database)
|
return cls._instance
|
@classmethod
|
async def close_instance(cls) -> None:
|
await CheckFile._instance.close()
|
class RedisHelper:
|
def __init__(self, redis_conn: aioredis.Redis, prefix: str):
|
self.conn = redis_conn
|
self.prefix = prefix
|
async def _basic_s_methods(self, method: str, client_id: list[int] | int) -> int:
|
if isinstance(client_id, int):
|
client_id = [client_id]
|
return await self.conn.sadd(f"{self.prefix}for_{method}", *client_id)
|
async def add_bypass(self, client_id: list[int] | int) -> int:
|
return await self._basic_s_methods("bypass", client_id)
|
async def add_blacklist(self, client_id: list[int] | int) -> int:
|
return await self._basic_s_methods("blacklist", client_id)
|
async def add_admin(self, client_id: list[int] | int) -> int:
|
return await self._basic_s_methods("admin", client_id)
|
async def delete_blacklist(self, client_id: int) -> None:
|
await self.conn.srem(f"{self.prefix}for_blacklist", client_id)
|
return
|
async def delete_admin(self, client_id: int) -> None:
|
await self.conn.srem(f"{self.prefix}for_admin", client_id)
|
return
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.