Per docs/plugin-audit-report.md (plugins normalized to Trigger(handlers) → Service(services) → Model(repository/models) + utils): - Split monolithic __init__.py into handlers/services/utils across dailywife, deer_pipe, dice, galgame_card, helldivers_tools, huoziyinshua, learning_chat, makeaquote, mc_server_status, ncm_saying, picfinder_take, picstatus, random_jm_code, regif, steam_info, video_analysis, group_tools - Move static assets under res/: deer_pipe font/img, makeaquote font, helldivers img/templates, huoziyinshua HuoZiYinShua - Add config.py + register_config_items to ncm_saying, random_jm_code, group_tools; learning_chat unified config bridge - Remove deprecated: voice_trans plugin, bf_bot/test.py, dead code in dailywife/deer_pipe, empty dirs, debug scripts under helldivers temp - Disable brash_general_supercredits_tools (stub comment only) - bot.py: optional stdout/stderr redirect to log file for Web log viewer, force ANSI colorize on non-TTY sinks - Move runtime data (jm_code.json) out of plugin dir into hexi/data - Docs: plugin-audit-report.md; README reflects removed plugins Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
"""搜图 —— 运行态(Service 层:每日限流 + 批量搜索会话)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from ..config import DAILY_LIMIT, SEARCH_TIMEOUT
|
|
|
|
|
|
class DailyNumberLimiter:
|
|
"""每日次数限制器(按年积日计数)"""
|
|
|
|
def __init__(self, max_num):
|
|
self.max = max_num
|
|
self.today = -1
|
|
self.count = {}
|
|
|
|
def check(self, key) -> bool:
|
|
day = datetime.now().timetuple().tm_yday
|
|
if day != self.today:
|
|
self.today = day
|
|
self.count.clear()
|
|
return self.count.get(key, 0) < self.max
|
|
|
|
def get_num(self, key):
|
|
return self.count.get(key, 0)
|
|
|
|
def increase(self, key, num=1):
|
|
self.count[key] = self.count.get(key, 0) + num
|
|
|
|
|
|
class PicListener:
|
|
def __init__(self):
|
|
self.on = {}
|
|
self.count = {}
|
|
self.limit = {}
|
|
self.timeout = {}
|
|
|
|
def get_on_off_status(self, gid):
|
|
return self.on[gid] if self.on.get(gid) is not None else False
|
|
|
|
def turn_on(self, gid, uid):
|
|
self.on[gid] = uid
|
|
self.timeout[gid] = datetime.now() + timedelta(seconds=SEARCH_TIMEOUT)
|
|
self.count[gid] = 0
|
|
self.limit[gid] = DAILY_LIMIT - lmtd.get_num(uid)
|
|
|
|
def turn_off(self, gid):
|
|
self.on.pop(gid)
|
|
self.count.pop(gid)
|
|
self.timeout.pop(gid)
|
|
self.limit.pop(gid)
|
|
|
|
def count_plus(self, gid):
|
|
self.count[gid] += 1
|
|
|
|
|
|
lmtd = DailyNumberLimiter(DAILY_LIMIT)
|
|
pls = PicListener()
|