from cheru import aiorequests from cheru.utils import helper import nonebot from nonebot import MatcherGroup from nonebot.log import logger from nonebot.permission import MESSAGE from nonebot.adapters.cqhttp import Bot, Event, MessageSegment from nonebot_plugin_rauthman import isInService from urllib.parse import quote # from pixivpy3 import AppPixivAPI from pixivpy3 import ByPassSniApi from .config import * import random import datetime sv = MatcherGroup(type='message', rule=isInService('pixiv', 1)) # aapi = AppPixivAPI() aapi = ByPassSniApi() aapi.require_appapi_hosts(hostname="public-api.secure.pixiv.net") aapi.set_accept_language('jp') sv_search = sv.on_startswith(msg='/pixiv', permission=MESSAGE, block=True) @sv_search.handle() async def pixiv_handle(bot: Bot, event: Event, state: dict): msg = str(event.message).strip() msg = msg.replace('/pixiv', '') if not msg: logger.info('pixiv_handle | no keyword') await sv_search.finish() state['keyword'] = msg
absPath = os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".") config_file = f'{absPath}/config.json' # data = { # 'calendar_days': 7, # 日程表返回包括今天在内多长时间的日程,默认是7天 # 'Refresh_date': '', # 上次爬取日程表的日期 # 'schedule_data': '' # 从官方日历爬取下来的数据 # } # day_key里保存的是每天的信息分类,"qdhd"是多倍掉落庆典,"tdz"是公会战, # "tbhd"是公会之家家具上架,"jqhd"是活动地图,"jssr"是角色生日 # 你可以自定义这个列表,删掉不想看到的活动 day_key = ["qdhd", "tdz", "tbhd", "jqhd"] sv = MatcherGroup(type='message', rule=isInService('schedule', 1)) sv_query = sv.on_command(cmd='schedule', aliases={ '国服日程表', '日程表'}, permission=MESSAGE, block=True) @sv_query.handle() async def Schedule(bot: Bot, ev: Event, state: dict): # 调用的时候比对上次爬取日程表时间,不是今天就重新爬取日程表,是今天就直接返回 p = config_file await checkFolder(p) data = await readJson(p) if data == FAILURE: data = { 'calendar_days': 7, 'Refresh_date': '', 'schedule_data': ''
import re from itertools import zip_longest from nonebot.adapters.cqhttp import escape, Bot, Event, MessageSegment from nonebot.permission import MESSAGE from nonebot import MatcherGroup from nonebot_plugin_rauthman import isInService sv = MatcherGroup(type='message', rule=isInService('cherugo', 1)) CHERU_SET = '切卟叮咧哔唎啪啰啵嘭噜噼巴拉蹦铃' CHERU_DIC = {c: i for i, c in enumerate(CHERU_SET)} ENCODING = 'gb18030' rex_split = re.compile(r'\b', re.U) rex_word = re.compile(r'^\w+$', re.U) rex_cheru_word: re.Pattern = re.compile(rf'切[{CHERU_SET}]+', re.U) def grouper(iterable, n, fillvalue=None): args = [iter(iterable)] * n return zip_longest(*args, fillvalue=fillvalue) def word2cheru(w: str) -> str: c = ['切'] for b in w.encode(ENCODING): c.append(CHERU_SET[b & 0xf]) c.append(CHERU_SET[(b >> 4) & 0xf]) return ''.join(c) def cheru2word(c: str) -> str:
from nonebot import MatcherGroup from nonebot.adapters.cqhttp import Bot, Event from nonebot_plugin_rauthman import isInService from nonebot.permission import MESSAGE from nonebot.log import logger from nonebot.plugin import on_message from cheru.utils import res, helper from cheru import config from typing import (Any, Callable, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, Union) from .argparse import ArgParser from .exception import * sv = MatcherGroup(type='message', rule=isInService('clanbattle')) SORRY = 'ごめんなさい!嘤嘤嘤(〒︿〒)' _registry: Dict[str, Tuple[Callable, ArgParser]] = {} async def _clanbattle_bus(bot: Bot, event: Event, state: dict): # check prefix start = '' for m in event.message: if m.type == 'text': start = m.data.get('text', '').lstrip() break # if not start or start[0] not in '!!': # return # find cmd
# sv.logger.info(f'episode={index[episode]}') # 下载图片并保存 await download_img(os.path.join(save_dir, get_pic_name(episode)), link) # 保存官漫目录信息 with open(os.path.join(save_dir, 'index.json'), 'w', encoding='utf8') as f: json.dump(index, f, ensure_ascii=False) return id_ sv_search = sv.on_command(cmd='comic_search', aliases={'官漫'}, permission=MESSAGE, block=True, rule=isInService('官漫', 1)) @sv_search.handle() async def comic_handle(bot: Bot, event: Event, state: dict): episode = event.plain_text.strip() if not re.fullmatch(r'\d{0,3}', episode): await sv_search.finish() episode = episode.lstrip('0') if not episode: await sv_search.finish('请输入漫画集数 如:官漫123') state['episode'] = episode @sv_search.got('episode') async def comic_got(bot: Bot, event: Event, state: dict):
from . import sv from nonebot.log import logger from nonebot.adapters.cqhttp import Bot, Event, MessageSegment from nonebot.permission import MESSAGE, SUPERUSER from nonebot.exception import FinishedException, NetworkError from nonebot_plugin_rauthman import isInService from cheru.utils import helper, res, chara import re sv_whois = sv.on_regex(r'^((谁是|誰是)(.*)|(.*)(是谁|是誰))', permission=MESSAGE, block=True, rule=isInService('whois', 1)) lmt = helper.FreqLimiter(5) @sv_whois.handle() async def whois(bot: Bot, event: Event, state: dict): uid = event.user_id if not lmt.check(uid): msg = f'{MessageSegment.at(uid)}兰德索尔花名册冷却中(剩余 {int(lmt.left_time(uid)) + 1}秒)' await sv_whois.finish(msg) lmt.start_cd(uid) name = event.plain_text.strip() name_ = name.replace('谁是', '').replace('誰是', '').replace('是谁', '').replace('是誰', '') if not name_: await sv_whois.finish() id_ = chara.name2id(name_) confi = 100
return logger.info(f'检索到{len(news)}条{TAG}新闻更新!') await helper.broadcast(bot, spider.format_items(news), TAG, interval_time=0.5) async def send_news(bot: Bot, ev: Event, spider: BaseSpider, sv: Matcher, max_num=5): if not spider.item_cache: await spider.get_update() news = spider.item_cache news = news[:min(max_num, len(news))] msg = spider.format_items(news) await sv.finish(msg) sv_news = sv.on_command(cmd='blnews', aliases={ 'B服新闻', 'b服新闻', 'B服日程', 'b服日程'}, permission=MESSAGE, block=True, rule=isInService('B服新闻', 1)) @sv_news.handle() async def blnews(bot: Bot, event: Event, state: dict): await send_news(bot, event, SonetSpider, sv_news) scheduler = require("nonebot_plugin_apscheduler").scheduler @scheduler.scheduled_job('cron', minute='*/5') async def news_scheduler(): if nonebot.get_bots(): bot = list(nonebot.get_bots().values())[0] else:
from collections import defaultdict import re from nonebot import MatcherGroup from nonebot.matcher import Matcher from nonebot.adapters.cqhttp import Bot, Event, MessageSegment from nonebot.permission import MESSAGE from nonebot.log import logger from nonebot_plugin_rauthman import isInService from cheru.utils import helper, chara, priv from .gacha import Gacha try: import ujson as json except: import json sv = MatcherGroup(type='message', rule=isInService('gacha', 1)) from .update import * jewel_limit = helper.DailyNumberLimiter(15000) tenjo_limit = helper.DailyNumberLimiter(5) JEWEL_EXCEED_NOTICE = f'您今天已经抽过{jewel_limit.max}钻了,欢迎明早5点后再来!' TENJO_EXCEED_NOTICE = f'您今天已经抽过{tenjo_limit.max}张天井券了,欢迎明早5点后再来!' POOL = ('MIX', 'JP', 'TW', 'BL') DEFAULT_POOL = POOL[0] _pool_config_file = os.path.expanduser('~/.cheru/group_pool_config.json') _group_pool = {} try: with open(_pool_config_file, encoding='utf8') as f: