Commit a56623e
Changed files (5)
src
src/danmu/entrypoint.py
@@ -20,7 +20,7 @@ from messages.sender import send2tg
from messages.utils import blockquote, equal_prefix, smart_split, startswith_prefix
from others.emoji import CURRENCY
from publish import publish_telegraph
-from utils import convert_html, nowdt, number
+from utils import convert_html, nowdt, number, strings_list
HELP = f"""📖**查询直播合订本**
`{PREFIX.DANMU}` 使用说明:
@@ -216,7 +216,7 @@ async def get_engine_with_dates(match_time: str, qtype: str = "弹幕") -> dict[
dict: {"server": [date-1, date-2], "r2": [date-3, date-4]}
"""
now = nowdt(TZ)
- allowed_years = [x.strip() for x in DANMU.SYNC_DANMU_YEARS.split(",") if x.strip()] if qtype == "弹幕" else [x.strip() for x in DANMU.SYNC_FAYAN_YEARS.split(",") if x.strip()]
+ allowed_years = [x.strip() for x in strings_list(DANMU.SYNC_DANMU_YEARS)] if qtype == "弹幕" else [x.strip() for x in strings_list(DANMU.SYNC_FAYAN_YEARS)]
allowed_years.append(str(now.year))
allowed_years = sorted(set(allowed_years))
if qtype == "发言":
src/history/sync.py
@@ -13,6 +13,7 @@ from database.turso import turso_exec, turso_parse_resp
from history.d1 import backup_chat_history_to_d1, query_d1, sync_history_to_d1
from history.turso import backup_chat_history_to_turso, sync_history_to_turso
from history.utils import TURSO_KWARGS
+from utils import strings_list
async def sync_chat_history(client: Client, message: Message) -> None:
@@ -62,7 +63,7 @@ async def backup_chat_history(
duration = float(os.getenv(f"HISTORY_BACKUP_CHATS_DURATION_{x['cid']}", hours * 3600)) / 3600
await backup_chat_history_to_d1(client, handle, duration, start_from=start_from)
else:
- chat_ids = [x.strip() for x in chats.split(",") if x.strip()]
+ chat_ids = [x.strip() for x in strings_list(chats)]
for cid in chat_ids:
logger.info(f"Backup chat history: {cid}")
if "TURSO" in HISTORY.ENGINE.upper():
src/history/utils.py
@@ -41,24 +41,24 @@ def check_save_history(ctype: str, cid: int | str) -> bool:
return False
if true(os.getenv(f"HISTORY_INCLUDE_{cid}")):
return True
- if cid in HISTORY.IGNORE_CHATS.split(","):
+ if cid in strings_list(HISTORY.IGNORE_CHATS):
return False
- if cid in HISTORY.INCLUDE_CHATS.split(","):
+ if cid in strings_list(HISTORY.INCLUDE_CHATS):
return True
if ctype == "PRIVATE":
- if str(HISTORY.INCLUDE_PRIVATES).lower() == "all" or cid in HISTORY.INCLUDE_PRIVATES.split(","):
+ if str(HISTORY.INCLUDE_PRIVATES).lower() == "all" or cid in strings_list(HISTORY.INCLUDE_PRIVATES):
return True
return False
if ctype == "BOT":
- if str(HISTORY.INCLUDE_BOTS).lower() == "all" or cid in HISTORY.INCLUDE_BOTS.split(","):
+ if str(HISTORY.INCLUDE_BOTS).lower() == "all" or cid in strings_list(HISTORY.INCLUDE_BOTS):
return True
return False
if ctype in ["GROUP", "SUPERGROUP"]:
- if str(HISTORY.INCLUDE_GROUPS).lower() == "all" or cid in HISTORY.INCLUDE_GROUPS.split(","):
+ if str(HISTORY.INCLUDE_GROUPS).lower() == "all" or cid in strings_list(HISTORY.INCLUDE_GROUPS):
return True
return False
if ctype == "CHANNEL":
- if str(HISTORY.INCLUDE_CHANNELS).lower() == "all" or cid in HISTORY.INCLUDE_CHANNELS.split(","):
+ if str(HISTORY.INCLUDE_CHANNELS).lower() == "all" or cid in strings_list(HISTORY.INCLUDE_CHANNELS):
return True
return False
return False
@@ -85,10 +85,8 @@ def fine_grained_check(info: dict) -> bool:
return False
if true(os.getenv(f"HISTORY_{cid}_SKIP_URL")) and (find_url(info["text"]) or info.get("entity_urls")):
return False
- if os.getenv(f"HISTORY_{cid}_SKIP_KEYWORDS"):
- keywords = [x.strip() for x in os.environ[f"HISTORY_{cid}_SKIP_KEYWORDS"].split(",") if x.strip()]
- if any(x in info["text"] for x in keywords):
- return False
+ if any(x in info["text"] for x in strings_list(os.getenv(f"HISTORY_{cid}_SKIP_KEYWORDS"))):
+ return False
return True
src/messages/utils.py
@@ -41,12 +41,12 @@ def startswith_prefix(text: str, prefix: str | list[str], ignore_prefix: str | l
prefix = [prefix]
for ignore_str in ignore_prefix:
- for pfx in [x.strip() for x in ignore_str.split(",") if x.strip()]:
+ for pfx in strings_list(ignore_str):
if pfx and norm_cmd(text).startswith(norm_cmd(pfx)):
return False
for prefix_str in prefix:
- for pfx in [x.strip() for x in prefix_str.split(",") if x.strip()]:
+ for pfx in strings_list(prefix_str):
if pfx and norm_cmd(text).startswith(norm_cmd(pfx)):
return True
return False
@@ -79,12 +79,12 @@ def equal_prefix(text: str, prefix: str | list[str], ignore_prefix: str | list[s
prefix = [prefix]
for ignore_str in ignore_prefix:
- for pfx in [x.strip() for x in ignore_str.split(",") if x.strip()]:
+ for pfx in strings_list(ignore_str):
if pfx and norm_cmd(text) == norm_cmd(pfx):
return False
for prefix_str in prefix:
- for pfx in [x.strip() for x in prefix_str.split(",") if x.strip()]:
+ for pfx in strings_list(prefix_str):
if pfx and norm_cmd(text) == norm_cmd(pfx):
return True
return False
src/permission.py
@@ -9,7 +9,7 @@ from pyrogram.types import Message
from config import ENABLE, TID, cache
from messages.modify import message_modify
-from utils import i_am_bot, slim_cid, to_int, true
+from utils import i_am_bot, slim_cid, strings_list, to_int, true
async def check_permission(client: Client, message: Message) -> dict:
@@ -47,21 +47,21 @@ async def check_category(client: Client, message: Message, ctype: str) -> dict:
TID_MUTES=111111,234567
TID_MUTE_111111=true
"""
- if not is_bot and (cid in [slim_cid(x) for x in os.getenv("TID_MUTES", "").split(",")] or true(os.getenv(f"TID_MUTE_{cid}"))):
+ if not is_bot and (cid in [slim_cid(x) for x in strings_list(os.getenv("TID_MUTES"))] or true(os.getenv(f"TID_MUTE_{cid}"))):
await message.read()
"""Skip process these chats
TID_SKIPS=111111,234567
TID_SKIP_111111=true
"""
- if cid in [slim_cid(x) for x in os.getenv("TID_SKIPS", "").split(",")] or true(os.getenv(f"TID_SKIP_{cid}")):
+ if cid in [slim_cid(x) for x in strings_list(os.getenv("TID_SKIPS"))] or true(os.getenv(f"TID_SKIP_{cid}")):
permission["disabled"] = True
"""Only process these chats
TID_ONLY_GROUPS=111111,234567,-100234567
TID_ONLY_USERS=111111,234567,-100234567
"""
- if os.getenv(f"TID_ONLY_{ctype}S") and cid not in [slim_cid(x) for x in os.getenv(f"TID_ONLY_{ctype}S", "").split(",")]:
+ if os.getenv(f"TID_ONLY_{ctype}S") and cid not in [slim_cid(x) for x in strings_list(os.getenv(f"TID_ONLY_{ctype}S"))]:
permission["disabled"] = True
"""Whitelist mode for users, if a user is not in the whitelist, skip process
@@ -71,11 +71,11 @@ async def check_category(client: Client, message: Message, ctype: str) -> dict:
"""
if ctype == "PRIVATE" and true(os.getenv("TID_WHITELIST_MODE")):
permission["disabled"] = True
- if cid in [slim_cid(x) for x in os.getenv("TID_WHITELIST_USERS", "").split(",")]:
+ if cid in [slim_cid(x) for x in strings_list(os.getenv("TID_WHITELIST_USERS"))]:
permission["disabled"] = False
# check if user is a member of these chats
with contextlib.suppress(Exception):
- for chat_id in [int(x.strip()) for x in os.getenv("TID_WHITELIST_USERS_IN_CHATS", "").split(",") if x.strip()]:
+ for chat_id in [int(x.strip()) for x in strings_list(os.getenv("TID_WHITELIST_USERS_IN_CHATS")) if x.strip()]:
chat_id = to_int(f"-100{slim_cid(chat_id)}") # noqa: PLW2901
if await client.get_chat_member(chat_id, cid):
permission["disabled"] = False