mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-08 21:30:01 +08:00
feat✨: add coser
This commit is contained in:
@@ -12,34 +12,6 @@ import pytz
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
|
||||
class WithdrawManager:
|
||||
"""
|
||||
消息撤回
|
||||
"""
|
||||
|
||||
_data = {}
|
||||
|
||||
@classmethod
|
||||
def append(cls, message_id: str, second: int):
|
||||
"""添加一个撤回消息id和时间
|
||||
|
||||
参数:
|
||||
message_id: 撤回消息id
|
||||
time: 延迟时间
|
||||
"""
|
||||
cls._data[message_id] = second
|
||||
|
||||
@classmethod
|
||||
def remove(cls, message_id: str):
|
||||
"""删除一个数据
|
||||
|
||||
参数:
|
||||
message_id: 撤回消息id
|
||||
"""
|
||||
if message_id in cls._data:
|
||||
del cls._data[message_id]
|
||||
|
||||
|
||||
class ResourceDirManager:
|
||||
"""
|
||||
临时文件管理器
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import asyncio
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.discord import Bot as DiscordBot
|
||||
from nonebot.adapters.dodo import Bot as DodoBot
|
||||
from nonebot.adapters.kaiheila import Bot as KaiheilaBot
|
||||
from nonebot.adapters.onebot.v11 import Bot as v11Bot
|
||||
from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
|
||||
class WithdrawManager:
|
||||
|
||||
_data = {}
|
||||
_index = 0
|
||||
|
||||
@classmethod
|
||||
def check(cls, session: EventSession, withdraw_time: tuple[int, int]) -> bool:
|
||||
"""配置项检查
|
||||
|
||||
参数:
|
||||
session: Session
|
||||
withdraw_time: 配置项数据, (0, 1)
|
||||
|
||||
返回:
|
||||
bool: 是否允许撤回
|
||||
"""
|
||||
if withdraw_time[0] and withdraw_time[0] > 0:
|
||||
if withdraw_time[1] == 2:
|
||||
return True
|
||||
if withdraw_time[1] == 1 and (session.id2 or session.id3):
|
||||
return True
|
||||
if withdraw_time[1] == 0 and not (session.id2 or session.id3):
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def append(cls, bot: Bot, message_id: str | int, time: int):
|
||||
"""添加消息撤回
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
message_id: 消息Id
|
||||
time: 延迟时间
|
||||
"""
|
||||
cls._data[cls._index] = (
|
||||
bot,
|
||||
message_id,
|
||||
time,
|
||||
)
|
||||
cls._index += 1
|
||||
|
||||
@classmethod
|
||||
def remove(cls, index: int):
|
||||
"""移除
|
||||
|
||||
参数:
|
||||
index: index
|
||||
"""
|
||||
if index in cls._data:
|
||||
del cls._data[index]
|
||||
|
||||
@classmethod
|
||||
async def withdraw_message(
|
||||
cls, bot: Bot, message_id: str | int, time: int | None = None
|
||||
):
|
||||
"""消息撤回
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
message_id: 消息Id
|
||||
time: 延迟时间
|
||||
"""
|
||||
if time:
|
||||
logger.debug(f"将在 {time}秒 内撤回消息ID: {message_id}", "WithdrawManager")
|
||||
await asyncio.sleep(time)
|
||||
if isinstance(bot, v11Bot):
|
||||
logger.debug(f"v11Bot 撤回消息ID: {message_id}", "WithdrawManager")
|
||||
await bot.delete_msg(message_id=int(message_id))
|
||||
elif isinstance(bot, v12Bot):
|
||||
logger.debug(f"v12Bot 撤回消息ID: {message_id}", "WithdrawManager")
|
||||
await bot.delete_message(message_id=str(message_id))
|
||||
elif isinstance(bot, KaiheilaBot):
|
||||
pass
|
||||
elif isinstance(bot, DodoBot):
|
||||
pass
|
||||
elif isinstance(bot, DiscordBot):
|
||||
pass
|
||||
Reference in New Issue
Block a user