二次元、原神图片增加自动撤回

This commit is contained in:
CMHopeSunshine 2022-05-06 15:05:19 +08:00
parent f3ab0d0c19
commit 398f3fe52b
3 changed files with 59 additions and 24 deletions

View File

@ -6,7 +6,7 @@ from nonebot.params import CommandArg, RegexGroup
from nonebot.message import event_preprocessor
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, MessageEvent, MessageSegment, FriendRequestEvent, \
GroupRequestEvent
from ..utils.util import FreqLimiter
from ..utils.util import FreqLimiter, auto_withdraw
from ..utils.config import config
from asyncio import sleep
import random
@ -62,7 +62,8 @@ async def cat_pic_handler(event: Union[GroupMessageEvent, MessageEvent]):
@ecy_pic.handle()
async def ecy_pic_handler(event: Union[GroupMessageEvent, MessageEvent], regexGroup=RegexGroup()):
@auto_withdraw(15)
async def ecy_pic_handler(bot: Bot, event: Union[GroupMessageEvent, MessageEvent], regexGroup=RegexGroup()):
urls = [
'https://www.dmoe.cc/random.php',
'https://acg.toubiec.cn/random.php',
@ -89,10 +90,11 @@ async def ecy_pic_handler(event: Union[GroupMessageEvent, MessageEvent], regexGr
elif url:
await cat_pic.send('派蒙努力找图ing..请稍候...')
ecy_lmt.start_cd(event.group_id or event.user_id, config.paimon_ecy_cd)
await cat_pic.finish(MessageSegment.image(file=url))
return await cat_pic.send(MessageSegment.image(file=url))
@ys_pic.handle()
@auto_withdraw(30)
async def ys_pic_handler(event: Union[GroupMessageEvent, MessageEvent]):
urls = [
'https://api.r10086.com/img-api.php?type=%E5%8E%9F%E7%A5%9E%E6%A8%AA%E5%B1%8F%E7%B3%BB%E5%88%971',

View File

@ -4,20 +4,34 @@ from typing import List
class PluginConfig(BaseModel):
# 群组模拟抽卡冷却(秒)
paimon_gacha_cd_group: int = 30
# 个人模拟抽卡冷却(秒)
paimon_gacha_cd_user: int = 60
# 树脂提醒停止检查时间(小时)
paimon_remind_start: int = 0
paimon_remind_end: int = 8
# 树脂提醒检查间隔(分钟)
paimon_check_interval: int = 16
# 树脂提醒每日提醒次数上限
paimon_remind_limit: int = 3
# 自动签到开始时间(小时)
paimon_sign_hour: int = 0
# 自动签到开始时间(分钟)
paimon_sign_minute: int = 0
# 对联冷却(秒)
paimon_duilian_cd: int = 6
# 猫图冷却(秒)
paimon_cat_cd: int = 12
# 二次元图冷却(秒)
paimon_ecy_cd: int = 6
# 原神壁纸图冷却(秒)
paimon_ysp_cd: int = 10
# 是否自动通过好友请求
paimon_add_friend: bool = False
# 是否自动通过群组请求
paimon_add_group: bool = False
# 派蒙聊天开启群组
paimon_chat_group: List[int] = []

View File

@ -10,6 +10,7 @@ import string
import functools
import inspect
import json
import asyncio
from json import JSONDecodeError
from aiohttp import ClientSession
from nonebot import get_bot
@ -23,6 +24,24 @@ from .db_util import get_cookie_cache, update_cookie_cache, delete_cookie_cache
from .db_util import get_last_query, update_last_query
def auto_withdraw(seconds: int = -1):
def wrapper(func):
@functools.wraps(func)
async def wrapped(**kwargs):
try:
message_id = await func(**kwargs)
if message_id and seconds >= 1:
await asyncio.sleep(seconds)
await get_bot().delete_msg(message_id=message_id['message_id'])
except Exception as e:
raise e
return wrapped
return wrapper
# 缓存装饰器 ttl为过期时间 参数use_cache决定是否使用缓存默认为True
def cache(ttl=datetime.timedelta(hours=1), **kwargs):
def wrap(func):
@ -149,7 +168,7 @@ async def get_use_cookie(user_id, uid='', mys_id='', action=''):
return cache_cookie
use_cookie = random.choice(cookies)
logger.info(f'---派蒙调用用户{use_cookie[0]}的uid{use_cookie[2]}私人cookie执行{action}操作---')
return {'type': 'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2],
return {'type': 'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2],
'mys_id': use_cookie[3]}
@ -258,14 +277,14 @@ def get_ds(q="", b=None) -> str:
# 米游社爬虫headers
def get_headers(cookie, q='', b=None):
headers = {
'DS': get_ds(q, b),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': cookie,
'DS': get_ds(q, b),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': cookie,
'x-rpc-app_version': "2.11.1",
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS '
'X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS '
'X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1',
'x-rpc-client_type': '5',
'Referer': 'https://webstatic.mihoyo.com/'
'Referer': 'https://webstatic.mihoyo.com/'
}
return headers
@ -280,17 +299,17 @@ def get_old_version_ds() -> str:
def get_sign_headers(cookie):
headers = {
'User_Agent': 'Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 ('
'KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.101 Mobile Safari/537.36 '
'miHoYoBBS/2.3.0',
'Cookie': cookie,
'x-rpc-device_id': random_hex(32),
'Origin': 'https://webstatic.mihoyo.com',
'X_Requested_With': 'com.mihoyo.hyperion',
'DS': get_old_version_ds(),
'User_Agent': 'Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 ('
'KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.101 Mobile Safari/537.36 '
'miHoYoBBS/2.3.0',
'Cookie': cookie,
'x-rpc-device_id': random_hex(32),
'Origin': 'https://webstatic.mihoyo.com',
'X_Requested_With': 'com.mihoyo.hyperion',
'DS': get_old_version_ds(),
'x-rpc-client_type': '5',
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id'
'=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon',
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id'
'=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon',
'x-rpc-app_version': '2.3.0'
}
return headers
@ -300,12 +319,12 @@ def get_sign_headers(cookie):
async def check_cookie(cookie):
url = 'https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo?gids=2'
headers = {
'DS': get_ds(),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': cookie,
'DS': get_ds(),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': cookie,
'x-rpc-app_version': "2.11.1",
'x-rpc-client_type': '5',
'Referer': 'https://webstatic.mihoyo.com/'
'Referer': 'https://webstatic.mihoyo.com/'
}
async with ClientSession() as session:
res = await session.get(url=url, headers=headers)