新增myb全部重做超管命令,加大米游币自动获取时间延迟(请尝试更换自动获取时间来增加成功率)

This commit is contained in:
CMHopeSunshine 2022-10-07 11:23:13 +08:00
parent cedd7366ef
commit 0c2dcacaac
3 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,7 @@
from typing import Union
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.permission import SUPERUSER
from nonebot.adapters.onebot.v11 import GroupMessageEvent, PrivateMessageEvent
from nonebot.plugin import PluginMetadata
@ -8,7 +9,7 @@ from nonebot.plugin import PluginMetadata
from LittlePaimon.database.models import MihoyoBBSSub, PrivateCookie
from LittlePaimon.utils import logger
from LittlePaimon.utils.message import CommandUID, CommandSwitch
from .coin_handle import mhy_bbs_coin
from .coin_handle import mhy_bbs_coin, bbs_auto_coin
from .sign_handle import mhy_bbs_sign, bbs_auto_sign
from .draw import draw_result
@ -35,7 +36,7 @@ sign = on_command('mys签到', aliases={'米游社签到', 'mys自动签到', '
'pm_usage': '米游社签到(uid)[on|off]',
'pm_priority': 1
})
all_sign = on_command('全部重签', priority=8, block=True, permission=SUPERUSER, state={
all_sign = on_command('全部重签', priority=8, block=True, permission=SUPERUSER, rule=to_me(), state={
'pm_name': '米游社全部重签',
'pm_description': '重签全部米游社签到任务,需超级用户权限',
'pm_usage': '@Bot 全部重签',
@ -49,6 +50,13 @@ get_coin = on_command('myb获取', aliases={'米游币获取', 'myb自动获取'
'pm_priority': 2
})
all_coin = on_command('myb全部重做', priority=8, block=True, permission=SUPERUSER, rule=to_me(), state={
'pm_name': '米游币获取全部重做',
'pm_description': '重做全部米游币获取任务,需超级用户权限',
'pm_usage': '@Bot myb全部重做',
'pm_priority': 4
})
signing_list = []
coin_getting_list = []
@ -134,3 +142,9 @@ async def _(event: Union[GroupMessageEvent, PrivateMessageEvent], uid=CommandUID
await sign.finish(f'UID{uid}关闭米游币自动获取成功', at_sender=True)
else:
await sign.finish(f'UID{uid}尚未开启米游币自动获取,无需关闭!', at_sender=True)
@all_coin.handle()
async def _(event: Union[GroupMessageEvent, PrivateMessageEvent]):
await all_coin.send('开始执行myb全部重做需要一定时间...')
await bbs_auto_coin()

View File

@ -207,7 +207,7 @@ class MihoyoBBSCoin:
10001] else f"出错了:{data['retcode']} {data['message']}"
logger.info('米游币自动获取', f'➤➤<r>{self.state}</r>')
return self.state
await asyncio.sleep(random.randint(3, 6))
await asyncio.sleep(random.randint(5, 10))
logger.info('米游币自动获取', '➤➤讨论区签到<g>完成</g>')
return '讨论区签到:完成!'
@ -223,7 +223,7 @@ class MihoyoBBSCoin:
data = req.json()
if data['message'] == 'OK':
num_ok += 1
await asyncio.sleep(random.randint(3, 6))
await asyncio.sleep(random.randint(5, 10))
logger.info('米游币自动获取', '➤➤看帖任务<g>完成</g>')
return f'浏览帖子:完成{str(num_ok)}个!'
@ -246,7 +246,7 @@ class MihoyoBBSCoin:
if data['message'] == 'OK':
num_ok += 1
# 取消点赞
await asyncio.sleep(random.randint(2, 4))
await asyncio.sleep(random.randint(3, 6))
req = await aiorequests.post(url=bbs_Likeurl,
headers=self.headers,
json={
@ -257,7 +257,7 @@ class MihoyoBBSCoin:
if data['message'] == 'OK':
num_cancel += 1
logger.info('米游币自动获取', '➤➤点赞任务<g>完成</g>')
await asyncio.sleep(random.randint(3, 6))
await asyncio.sleep(random.randint(5, 10))
return f'点赞帖子:完成{str(num_ok)}个!'
async def share_post(self):
@ -274,9 +274,9 @@ class MihoyoBBSCoin:
if data['message'] == 'OK':
return '分享帖子:完成!'
else:
await asyncio.sleep(random.randint(4, 7))
await asyncio.sleep(random.randint(5, 10))
logger.info('米游币自动获取', '➤➤分享任务<g>完成</g>')
await asyncio.sleep(random.randint(3, 6))
await asyncio.sleep(random.randint(5, 10))
return '分享帖子:完成!'
@ -301,6 +301,10 @@ async def mhy_bbs_coin(user_id: str, uid: str) -> str:
@scheduler.scheduled_job('cron', hour=pm.config.auto_myb_hour, minute=pm.config.auto_myb_minute, misfire_grace_time=10)
async def _():
await bbs_auto_coin()
async def bbs_auto_coin():
"""
指定时间执行所有米游币获取订阅任务 并将结果分群绘图发送
@ -311,7 +315,7 @@ async def bbs_auto_coin():
subs = await MihoyoBBSSub.filter(sub_event='米游币自动获取').all()
if not subs:
return
logger.info('米游币自动获取', f'开始执行米游币自动获取,共<m>{len(subs)}</m>个任务,预计花费<m>{round(75 * len(subs) / 60, 2)}</m>分钟')
logger.info('米游币自动获取', f'开始执行米游币自动获取,共<m>{len(subs)}</m>个任务,预计花费<m>{round(100 * len(subs) / 60, 2)}</m>分钟')
coin_result_group = defaultdict(list)
coin_result_private = defaultdict(list)
for sub in subs:
@ -328,7 +332,7 @@ async def bbs_auto_coin():
'result': '出错' not in result and 'Cookie' not in result,
'msg': result
})
await asyncio.sleep(random.randint(3, 6))
await asyncio.sleep(random.randint(15, 25))
for group_id, result_list in coin_result_group.items():
result_num = len(result_list)

View File

@ -124,7 +124,7 @@ async def bbs_auto_sign():
if not subs:
# 如果没有米游社原神签到订阅,则不执行签到任务
return
logger.info('米游社原神签到', f'开始执行米游社自动签到,共<m>{len(subs)}</m>个任务,预计花费<m>{round(100 * len(subs) / 60, 2)}</m>分钟')
logger.info('米游社原神签到', f'开始执行米游社自动签到,共<m>{len(subs)}</m>个任务,预计花费<m>{len(subs) * 2}</m>分钟')
sign_result_group = defaultdict(list)
sign_result_private = defaultdict(list)
for sub in subs: