text
stringlengths
1
93.6k
async def set(self, key: str, value: str) -> None:
await self.set(key, value)
async def mset(self, mp: dict[str, str]) -> None:
await self.conn.mset(mp)
async def clean(self, mp: dict[str, str]) -> None:
await self.conn.delete(f"{self.prefix}for_bypass")
await self.conn.delete(f"{self.prefix}for_blacklist")
await self.conn.delete(" ".join(map(str, (key for key, _ in mp.items()))))
await self.conn.delete(f"{self.prefix}for_admin")
async def _basic_s_query(self, method: str, client_id: int) -> bool:
return await self.conn.sismember(f"{self.prefix}for_{method}", client_id)
async def query_admin(self, client_id: int) -> bool:
return await self._basic_s_query("admin", client_id)
async def query_blacklist(self, client_id: int) -> bool:
return await self._basic_s_query("blacklist", client_id)
async def query_bypass(self, client_id: int) -> bool:
return await self._basic_s_query("bypass", client_id)
async def query_channel_mapping(self, client_id: int) -> int | None:
if result := await self.conn.get(f"{client_id}"):
return int(result)
return None
async def get(self, key: str) -> bytes | None:
return await self.conn.get(key)
@classmethod
async def new(cls, sql_conn: CheckFile, owner: int = 0) -> RedisHelper:
redis_ = await aioredis.from_url("redis://localhost")
prefix = "".join(random.choices(string.ascii_lowercase, k=5))
self = cls(redis_, prefix)
await self.add_admin(await sql_conn.query_all_admin())
await self.add_blacklist(await sql_conn.query_all_blacklist())
await self.add_bypass(await sql_conn.query_all_bypass())
await self.mset(await sql_conn.query_all_special_forward())
if owner != 0:
await self.add_admin(owner)
return self
async def close(self) -> None:
await self.conn.close()
class ClientRedisHelper(RedisHelper):
from pyrogram.types import Message
async def check_msg_from_blacklist(self, msg: Message) -> bool:
if await self.query_blacklist(msg.chat.id):
return True
if msg.from_user and await self.query_blacklist(msg.from_user.id):
return True
if msg.sender_chat and await self.query_blacklist(msg.sender_chat.id):
return True
if msg.forward_from and await self.query_blacklist(msg.forward_from.id):
return True
if msg.forward_from_chat and await self.query_blacklist(
msg.forward_from_chat.id
):
return True
return False
async def check_msg_from_admin(self, msg: Message) -> bool:
return await self.query_admin(msg.chat.id)
# <FILESEP>
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from urllib import request, parse
import hmac, datetime, uuid, base64
import json, os, logging
import logger
Headers = {
'Accept': 'text/json',
'Content-type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}
CommonParams = {
'Format':'json',
'SignatureMethod': 'HMAC-SHA1',
'SignatureVersion': '1.0',
'Timestamp': datetime.datetime.utcnow().isoformat(),
'Version': '2015-01-09',
}
class Aliyun():
_access_key_id = ''
_access_key_secret = ''
def __init__(self, access_key_id, access_key_secret):
global _access_key_id
global _access_key_secret