msg = [ f'{TIP}\n', str(num) if num > 1 else '', 'D', f'{min_}~' if min_ != 1 else '', str(max_), (' +-'[opr] + str(offset)) if offset else '', '=', rolls_str, (' +-'[opr] + str(offset)) if offset else '', f'={res}' if offset or num > 1 else '', ] msg = ''.join(msg) if isinstance(event, GroupMessageEvent): await bot.send(event, msg, at_sender=True) elif isinstance(event, PrivateMessageEvent): await bot.send(event, '您' + msg) dice_roll = sv.on_rex(re.compile(r'^\.r\s*((?P<num>\d{0,2})d((?P<min>\d{1,4})~)?(?P<max>\d{0,4})((?P<opr>[+-])(?P<offset>\d{0,5}))?)?\b', re.I), only_group=False) qj = sv.on_fullmatch('.qj', only_group=False) @dice_roll.handle() async def dice(bot: Bot, event: CQEvent, state: T_State): num, min_, max_, opr, offset = 1, 1, 100, 1, 0 match = state['match'] if s := match.group('num'): num = int(s) if s := match.group('min'): min_ = int(s) if s := match.group('max'): max_ = int(s) if s := match.group('opr'): opr = -1 if s == '-' else 1 if s := match.group('offset'): offset = int(s)
'彩云(东加罗林空)', '彩云(侦四)', '试制景云(舰侦型)', ] @scheduler.scheduled_job('cron', id='番剧订阅', minute='*/3', second='15') async def mikan_poller(): if not Mikan.rss_cache: await Mikan.update_cache() salmon.logger.info(f'订阅缓存为空,已加载至最新') return new_bangumi = await Mikan.update_cache() if not new_bangumi: salmon.logger.info(f'未检索到番剧更新!') else: salmon.logger.info(f'检索到{len(new_bangumi)}条番剧更新!') msg = [ f'{i[1]} 【{i[2].strftime(r"%Y-%m-%d %H:%M")}】\n▲下载 {i[0]}' for i in new_bangumi ] randomiser = lambda m: f'{random.choice(DEVICES)}监测到番剧更新!{"!"*random.randint(0,4)}\n{m}' await sv.broadcast(msg, '蜜柑番剧', 0.5, randomiser) mikan = sv.on_fullmatch('来点新番') @mikan.handle() async def see_bangumi(bot: Bot, event: CQEvent): if not Mikan.rss_cache: await Mikan.update_cache() msg = [ f'{i[1]} 【{i[2].strftime(r"%Y-%m-%d %H:%M")}】\n▲链接 {i[0]}' for i in Mikan.rss_cache[:min(5, len(Mikan.rss_cache))] ] msg = '\n'.join(msg) await bot.send(event, f'最近更新的番剧:\n{msg}')
TXT = ''' [翻译] 机器翻译 '''.strip() sv = Service('机器翻译', bundle='查询', help_=TXT) app_id = salmon.configs.translate.tencent_app_id app_key = salmon.configs.translate.tencent_app_key def loadsJson(dict: str) -> dict: return json.loads(dict) translate = sv.on_fullmatch('翻译', aliases={'机翻'}, only_group=False) async def getReqSign(params: dict) -> str: keys = [] for key in sorted(params): keys.append(f'{key}={quote_plus(params[key])}') hashed_str = f'{"&".join(keys)}&app_key={app_key}' sign = md5(hashed_str.encode()) return sign.hexdigest().upper() async def rand_string(n=8) -> str: return ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(n))
def str2cheru(s: str) -> str: c = [] for w in rex_split.split(s): if rex_word.search(w): w = word2cheru(w) c.append(w) return ''.join(c) def cheru2str(c: str) -> str: return rex_cheru_word.sub(lambda w: cheru2word(w.group()), c) cherulize = sv.on_fullmatch('切噜一下', only_group=False) decherulize = sv.on_fullmatch('切噜~♪', only_group=False) @cherulize.handle() async def cherulize_rec(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') args = event.message.extract_plain_text() if args: state['kouyougo'] = args if isinstance(event, GroupMessageEvent): message = f'>{nickname}\n请问要切噜什么切噜噜?' elif isinstance(event, PrivateMessageEvent): message = '请问要切噜什么切噜噜?' state['prompt'] = message
def dump_pool_config(): with open(_pool_config_file, 'w', encoding='utf8') as f: json.dump(_group_pool, f, ensure_ascii=False) gacha_10_aliases = ('抽十连', '十连', '十连!', '十连抽', '来个十连', '来发十连', '来次十连', '抽个十连', '抽发十连', '抽次十连', '十连扭蛋', '扭蛋十连', '10连', '10连!', '10连抽', '来个10连', '来发10连', '来次10连', '抽个10连', '抽发10连', '抽次10连', '10连扭蛋', '扭蛋10连') gacha_1_aliases = ('单抽', '单抽!', '来发单抽', '来个单抽', '来次单抽', '扭蛋单抽', '单抽扭蛋') gacha_200_aliases = ('一井', '抽一井', '来一井', '来发井', '抽发井', '天井扭蛋', '扭蛋天井') POOL_NAME_TIP = '请选择以下卡池\n> 切换卡池jp\n> 切换卡池tw\n> 切换卡池b\n> 切换卡池mix' gacha_1 = sv.on_fullmatch('gacha-1', aliases=gacha_1_aliases, only_group=False) gacha_10 = sv.on_fullmatch('gacha-10', aliases=gacha_10_aliases, only_group=False) gacha_200 = sv.on_fullmatch('gacha-300', aliases=gacha_200_aliases, only_group=False) gacha_pool = sv.on_fullmatch( 'look-up', aliases={'卡池资讯', '查看卡池', '看看卡池', '康康卡池', '看看up', '看看UP'}, only_group=False) gacha_switch = sv.on_fullmatch('gacha-switch', aliases={'切换卡池', '选择卡池'}, only_group=False) kakin = sv.on_fullmatch('kakin', aliases={'氪金', '课金'},
[查看当前/全部rank更新源] [设置rank更新源] [更新rank表缓存] [挖矿15001] 矿场余钻 [黄骑充电表] 黄骑1动规律 [谁是霸瞳] 角色别称查询 '''.strip() sv = Service('pcr-query', help_=sv_help, bundle='pcr查询') miner = sv.on_prefix('挖矿', aliases={'jjc钻石', '竞技场钻石', 'jjc钻石查询', '竞技场钻石查询'}, only_group=False) rank = sv.on_rex(r'^(\*?([日台国陆b])服?([前中后]*)卫?)?rank(表|推荐|指南)?$', only_group=False) current_source = sv.on_fullmatch('查看当前rank更新源', only_group=False) all_source = sv.on_fullmatch('查看全部rank更新源', only_group=False) set_source = sv.on_rex(r'^设置rank更新源 (.{0,5}) (.{0,10}) (.{0,20})$', only_group=False) cache_update = sv.on_fullmatch('更新rank表缓存', only_group=False) yukari = sv.on_fullmatch(('yukari-sheet', '黄骑充电', '酒鬼充电', '酒鬼充电表', '黄骑充电表'), only_group=False) who_is = sv.on_prefix('谁是', only_group=False) async def load_config(): global config global server_addr config_path = os.path.join(os.path.dirname(__file__), "rank.json") with open(config_path, "r", encoding="utf8") as fp: config = json.load(fp)
@scheduler.scheduled_job('cron', id='新闻动态', minute='*/5', jitter=20) async def pcr_news_poller(): await news_poller(SonetSpider, svtw, '台服官网') await news_poller(BiliSpider, svbl, 'B服官网') async def send_news(bot: Bot, event: CQEvent, spider: BaseSpider, max_num=5): if not spider.item_cache: await spider.get_update() news = spider.item_cache news = news[:min(max_num, len(news))] await bot.send(event, spider.format_items(news)) twnews = svtw.on_fullmatch('台服新闻', aliases={'台服动态'}, only_group=False) blnews = svbl.on_fullmatch('B服新闻', aliases={'b服新闻', 'B服动态', 'b服动态'}, only_group=False) @twnews.handle() async def tw_send(bot: Bot, event: CQEvent): await send_news(bot, event, SonetSpider) @blnews.handle() async def bl_send(bot: Bot, event: CQEvent): await send_news(bot, event, BiliSpider)
aliases = ('怎么拆', '怎么解', '怎么打', '如何拆', '如何解', '如何打', 'jjc查询') aliases_b = tuple('b' + a for a in aliases) + tuple('B' + a for a in aliases) aliases_tw = tuple('台' + a for a in aliases) aliases_jp = tuple('日' + a for a in aliases) try: thumb_up_i = R.img('priconne/gadget/thumb-up-i.png').open().resize((16, 16), Image.LANCZOS) thumb_up_a = R.img('priconne/gadget/thumb-up-a.png').open().resize((16, 16), Image.LANCZOS) thumb_down_i = R.img('priconne/gadget/thumb-down-i.png').open().resize((16, 16), Image.LANCZOS) thumb_down_a = R.img('priconne/gadget/thumb-down-a.png').open().resize((16, 16), Image.LANCZOS) except Exception as e: salmon.logger.exception(e) arena_query = sv.on_fullmatch('查竞技场', aliases=aliases, only_group=False) arena_query_b = sv.on_fullmatch('b竞技场', aliases=aliases_b, only_group=False) arena_query_tw = sv.on_fullmatch('台竞技场', aliases=aliases_tw, only_group=False) arena_query_jp = sv.on_fullmatch('日竞技场', aliases=aliases_jp, only_group=False) @arena_query.handle() @arena_query_b.handle() @arena_query_tw.handle() @arena_query_jp.handle() async def arena_rec(bot: Bot, event: CQEvent, state: T_State): args = event.message.extract_plain_text() if args: state['defen'] = args @arena_query.got('defen', prompt='请发送竞技场防守队伍') async def arena_query(bot: Bot, event: CQEvent, state: T_State):
from nonebot.rule import to_me from salmon import Bot, R, Service, priv, util from salmon.typing import CQEvent, Message, GroupMessageEvent, PrivateMessageEvent # basic function for debug, not included in Service('chat') zai = on_command('zai?', to_me(), aliases={'在?', '在?', '在吗', '在么?', '在嘛', '在嘛?'}) @zai.handle() async def say_hello(bot: Bot, event: CQEvent): await zai.send('はい!私はいつも貴方の側にいますよ!') sv = Service('chat', visible=False) sorry = sv.on_fullmatch('沙雕机器人', only_group=False) waifu = sv.on_fullmatch('老婆', to_me(), aliases={'waifu', 'laopo'}, only_group=False) laogong = sv.on_fullmatch('老公', to_me(), only_group=False) mua = sv.on_fullmatch('mua', to_me(), only_group=False) seina = sv.on_fullmatch('来点星奏', only_group=False) dd = sv.on_fullmatch('我朋友说他好了', aliases={'我有个朋友说他好了'}, only_group=False) haole = sv.on_fullmatch('我好了', only_group=False) @sorry.handle() async def say_sorry(bot: Bot, event: CQEvent): await bot.send(event, 'ごめんなさい!嘤嘤嘤(〒︿〒)') @waifu.handle() async def chat_waifu(bot: Bot, event: CQEvent): if not priv.check_priv(event, priv.SUPERUSER):
import salmon from salmon import Bot, Service, priv from salmon.typing import (CQEvent, GroupMessageEvent, Message, PrivateMessageEvent, T_State) from salmon.util import DailyNumberLimiter sv = Service('_feedback_', manage_priv=priv.SUPERUSER, help_='[反馈] 后接反馈内容 联系维护组') _max = 1 lmt = DailyNumberLimiter(_max) EXCEED_NOTICE = f'您今天已经反馈过{_max}次了,请明早5点后再来!' feed_back = sv.on_fullmatch('反馈', aliases={'来杯咖啡', '来杯红茶'}, only_group=False) @feed_back.handle() async def feed_rec(bot: Bot, event: CQEvent, state: T_State): uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') if not lmt.check(uid): if isinstance(event, GroupMessageEvent): await feed_back.finish(f'>{nickname}\n您今天已经反馈过{_max}次了,请明早5点后再来!') elif isinstance(event, PrivateMessageEvent): await feed_back.finish(EXCEED_NOTICE) lmt.increase(uid) args = event.get_message() if args: state['text'] = args
bundle="pcr娱乐", help_=""" [猜头像] 猜猜bot随机发送的头像的一小部分来自哪位角色 [猜头像排行] 显示小游戏的群排行榜(只显示前十) """.strip(), ) svd = Service("pcr-desc-guess", bundle="pcr娱乐", help_=""" [猜角色] 猜猜bot在描述哪位角色 [猜角色排行] 显示小游戏的群排行榜(只显示前十) """.strip()) avatar_rank = sva.on_fullmatch('猜头像排行', aliases={'猜头像排名', '猜头像排行榜', '猜头像群排行'}, only_group=False) desc_rank = svd.on_fullmatch('猜角色排行', aliases={'猜角色排名', '猜角色排行榜', '猜角色群排行'}, only_group=False) avatar_guess = sva.on_fullmatch('猜头像', only_group=False) desc_guess = svd.on_fullmatch('猜角色', only_group=False) class Dao: def __init__(self, db_path): self.db_path = db_path os.makedirs(os.path.dirname(db_path), exist_ok=True) self._create_table() def connect(self):
※我方羊驼算一号位 ※图片搬运自漪夢奈特''') sv_help = ''' [rank日服] rank推荐表 [rank台服] rank推荐表 [rank陆服] rank推荐表 [挖矿15001] 矿场余钻 [黄骑充电表] 黄骑1动规律 [谁是霸瞳] 角色别称查询 '''.strip() sv = Service('pcr-query', help_=sv_help, bundle='pcr查询') miner = sv.on_fullmatch('挖矿', aliases={'jjc钻石', '竞技场钻石', 'jjc钻石查询', '竞技场钻石查询'}, only_group=False) rank = sv.on_fullmatch('rank', aliases={'Rank', 'rank表', 'Rank表'}, only_group=False) yukari = sv.on_fullmatch('yukari-sheet', aliases={'黄骑充电', '酒鬼充电', '酒鬼充电表', '黄骑充电表'}, only_group=False) who_is = sv.on_prefix('谁是', only_group=False) is_who = sv.on_suffix('是谁', only_group=False) @miner.handle() async def miner_rec(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') if isinstance(event, GroupMessageEvent): state['prompt'] = f'>{nickname}\n请发送当前竞技场排名' elif isinstance(event, PrivateMessageEvent): state['prompt'] = '请发送当前竞技场排名' try: args = int(event.message.extract_plain_text())
if sv.visible: manual.append(f"|※| {sv.name}") return '\n'.join(manual) def get_service_help(name, service_info): manual = [f"➤{name}功能帮助:"] service_info = sorted(service_info, key=lambda s: s.name) for sv in service_info: if sv.visible: if sv.help: manual.append(sv.help) return "\n".join(manual) send_help = sv.on_fullmatch('help', aliases={'帮助'}, only_group=False) help_bundle = sv.on_fullmatch('help_bundle', aliases={'帮助分组'}, only_group=False) @send_help.handle() async def help_handle(bot: Bot, event: CQEvent): name = event.get_plaintext().strip() bundles = Service.get_bundles() svs = Service.get_loaded_services() info = Service.get_help() if not name: await send_help.finish(TOP_MANUAL) elif name in bundles: if isinstance(event, GroupMessageEvent):
import salmon from salmon import Bot, Service, priv, scheduler from salmon.typing import CQEvent from salmon.modules.check.check import Check sv = Service('check', use_priv=priv.SUPERUSER, manage_priv=priv.SUPERUSER, visible=False) MAX_PERFORMANCE_PERCENT = salmon.configs.check.MAX_PERFORMANCE_PERCENT PROCESS_NAME_LIST = salmon.configs.check.PROCESS_NAME_LIST check = Check(salmon.configs.check.PROCESS_NAME_LIST) check_self = sv.on_fullmatch(('自检', '自檢', '自我检查', '自我檢查'), only_group=False) @check_self.handle() async def _(bot: Bot, event: CQEvent): check_report_admin = await check.get_check_info() if check_report_admin: await bot.send(event, check_report_admin) else: salmon.logger.error("Not found Check Report") await bot.send(event, "[ERROR]Not found Check Report") @scheduler.scheduled_job('cron', id='自我检查', hour='*/3', minute='13') async def check_task(): weihu = salmon.configs.SUPERUSERS[0] result = await check.get_check_easy() for bot in salmon.get_bot_list(): await bot.send_private_msg(user_id=weihu, message=result)
'扫荡券×15', '卢币×2000', '上级精炼石×3', '宝石×100', '白金转蛋券×1', ] todo_list = [ '找伊绪老师上课', '给宫子买布丁', '和真琴一起寻找伤害优衣的人', '找小雪探讨女装', '与吉塔一起登上骑空艇', '和霞一起调查伤害优衣的人', '和佩可小姐一起吃午饭', '找小小甜心玩过家家', '帮碧寻找新朋友', '去真步真步王国', '找镜华补习数学', '陪胡桃排练话剧', '和初音一起午睡', '成为露娜的朋友', '帮铃莓打扫咲恋育幼院', '和静流小姐一起做巧克力', '去伊丽莎白农场给栞小姐送书', '观看慈乐之音的演出', '解救挂树的群友', '来一发十连', '井一发当期的限定池', '给妈妈买一束康乃馨', '购买黄金保值', '竞技场背刺', '去赛马场赛马', '用决斗为海马带来笑容', '成为魔法少女', '来几局日麻' ] login = sv.on_fullmatch('签到', aliases={'盖章', '妈', '妈?', '妈妈', '妈!', '妈!', '妈妈!'}, only_group=False) @login.handle() async def give_okodokai(bot: Bot, event: CQEvent): uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') if not lmt.check(uid): if isinstance(event, GroupMessageEvent): await login.finish(f'>{nickname}\n明日はもう一つプレゼントをご用意してお待ちしますね') elif isinstance(event, PrivateMessageEvent): await login.finish('明日はもう一つプレゼントをご用意してお待ちしますね') lmt.increase(uid) present = random.choice(login_presents)
sv = Service('pcr-comic', help_=sv_help, bundle='pcr订阅') def load_index(): with open(R.get('img/priconne/comic/index.json').path, encoding='utf8') as f: return json.load(f) def get_pic_name(id_): pre = 'episode_' end = '.png' return f'{pre}{id_}{end}' comic = sv.on_fullmatch('官漫', only_group=False) @comic.handle() async def comic_rec(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') args = event.message.extract_plain_text() if args: state['episode'] = args if isinstance(event, GroupMessageEvent): message = f'>{nickname}\n请发送漫画的集数' elif isinstance(event, PrivateMessageEvent): message = '请发送漫画的集数' state['prompt'] = message