2022-04-06 14:39:27 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
@File : custom.py
|
|
|
|
@Time : 2022/04/02 10:17:03
|
|
|
|
@Author : Viperorz
|
2022-04-08 06:53:17 +00:00
|
|
|
@Version : 1.0.5
|
2022-04-06 14:39:27 +00:00
|
|
|
@License : (C)Copyright 2021-2022
|
|
|
|
@Desc : None
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-04-07 08:08:10 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
import yaml
|
2022-04-06 14:39:27 +00:00
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.types import Message
|
2022-04-08 13:58:47 +00:00
|
|
|
from tools.constants import STORE_TRACE_DATA, COMMAND_YML
|
2022-04-06 14:39:27 +00:00
|
|
|
from tools.storage import SimpleStore
|
|
|
|
|
2022-04-08 13:58:47 +00:00
|
|
|
command_data: Dict[str, Any] = yaml.full_load(open(COMMAND_YML, 'rb'))
|
2022-04-07 08:08:10 +00:00
|
|
|
|
2022-04-06 14:39:27 +00:00
|
|
|
|
2022-04-07 08:08:10 +00:00
|
|
|
def command(key: str):
|
2022-04-06 14:39:27 +00:00
|
|
|
"""匹配UserBot指令"""
|
2022-04-07 08:08:10 +00:00
|
|
|
prefixes = command_data.get('help').get('all_prefixes')
|
2022-04-08 13:58:47 +00:00
|
|
|
if type(command_data.get(key).get('cmd')) == str:
|
|
|
|
cmd = [command_data.get(key).get('cmd'), key]
|
|
|
|
return filters.me & filters.text & filters.command(cmd, prefixes)
|
|
|
|
|
2022-04-07 08:08:10 +00:00
|
|
|
cmd = command_data.get(key).get('cmd')
|
|
|
|
return filters.me & filters.text & filters.command(cmd, prefixes)
|
2022-04-06 14:39:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_traced():
|
|
|
|
"""正则匹配用户输入指令及参数"""
|
|
|
|
async def func(flt, _, msg: Message):
|
|
|
|
async with SimpleStore(auto_flush=False) as store:
|
|
|
|
trace_data = store.get_data(STORE_TRACE_DATA)
|
|
|
|
if not trace_data:
|
|
|
|
return False
|
|
|
|
elif not trace_data.get(msg.from_user.id):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
# "data" kwarg is accessed with "flt.data" above
|
|
|
|
return filters.incoming & filters.create(func)
|