async def group_change_chat(bot: Bot, event: CQEvent): if not event.get_plaintext(): await trans_auth.finish('请发送“转移授权 旧群群号*新群群号”来进行转移') origin = event.get_plaintext().strip() pattern = re.compile(r'^(\d{5,15})\*(\d{5,15})$') m = pattern.match(origin) if m is None: await trans_auth.finish( '格式或群号错误\n请发送“转移授权 旧群群号*新群群号”来转移群授权时长\n如果新群已经授权,则会增加对应时长') old_gid = int(m.group(1)) new_gid = int(m.group(2)) if event.user_id not in salmon.configs.SUPERUSERS: util.log(f'{event.user_id}尝试转移授权{old_gid}到{new_gid}, 已拒绝') trans_auth.finish('权限不足') gtime_old = util.check_group(old_gid) if gtime_old == 0: await trans_auth.finish('旧群无授权, 不可进行转移') if old_gid == new_gid: await trans_auth.finish('宁搁这儿原地TP呢?') await util.transfer_group(old_gid, new_gid) gtime_new = util.check_group(new_gid) msg = await util.process_group_msg(new_gid, expiration=gtime_new, title=f'旧群{old_gid}授权已清空, 新群授权状态:\n') await notify_group(group_id=old_gid, txt=f'已转移本群授权时长至其他群。') await trans_auth.finish(msg)
async def _(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, MessageEvent): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') available = [ 'zh', 'en', 'fr', 'es', 'it', 'de', 'tr', 'ru', 'pt', 'vi', 'id', 'ms', 'th', 'jp', 'kr' ] state['available'] = ' | '.join(available) state['valid'] = deepcopy(available) if event.get_plaintext(): for language in available: if event.get_plaintext().startswith(language): state['source'] = language break if 'source' in state: input = event.get_plaintext().split(' ', 2) if state['source'] == 'zh': available.remove('zh') elif state['source'] == 'en': for i in ['jp', 'kr']: available.remove(i) available.remove(state['source']) elif state['source'] in [ 'fr', 'es', 'it', 'de', 'tr', 'ru', 'pt' ]: for i in ['vi', 'id', 'ms', 'th', 'jp', 'kr']: available.remove(i) available.remove(state['source']) elif state['source'] in ['vi', 'id', 'ms', 'th']: available = ['zh', 'en'] else: available = ['zh'] if len(available) == 1: state['target'] = 'zh' salmon.logger.info(input) if len(input) == 3: state['text'] = input[2] else: state['text'] = input[1] elif len(input) == 3: state['target'] = input[1] state['text'] = input[2] elif len(input) == 2: for language in available: if input[0] in available: state['target'] = input[1] else: state['text'] = input[1] else: state['text'] = event.get_plaintext() if isinstance(event, GroupMessageEvent): message = f'>{nickname}\n请选择输入语种,可选值如下~\n{state["available"]}' elif isinstance(event, PrivateMessageEvent): message = f'请选择输入语种,可选值如下~\n{state["available"]}' state['prompt'] = message else: salmon.logger.warning('Not supported: translator') return
async def jyu_rec(bot: Bot, event: CQEvent, state: T_State): SUPER_LUCKY_LINE = 170 await check_jewel_num(bot, event) uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') jewel_limit.increase(uid, 1500) if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) result, hiishi = gacha.gacha_ten() res1 = chara.gen_team_pic(result[:5], star_slot_verbose=False) res2 = chara.gen_team_pic(result[5:], star_slot_verbose=False) res = concat_pic([res1, res2]) res = pic2b64(res) res = MessageSegment.image(res) result = [f'{c.name}{"★"*c.star}' for c in result] res1 = ' '.join(result[0:5]) res2 = ' '.join(result[5:]) res = f'{res}\n{res1}\n{res2}' if hiishi >= SUPER_LUCKY_LINE: await bot.send(event, '恭喜海豹!おめでとうございます!') await gacha_10.finish(Message(f'>{nickname}\n素敵な仲間が増えますよ!\n{res}')) elif isinstance(event, PrivateMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def add_time_all_rec(bot: Bot, event: CQEvent, state: T_State): if event.user_id not in salmon.configs.SUPERUSERS: util.log(f'{event.user_id}尝试批量授权, 已拒绝') await all_add.finish('权限不足') days = event.get_plaintext().strip() if days: state['days'] = days
async def look_pool(bot: Bot, event: CQEvent): if isinstance(event, GroupMessageEvent): gid = str(event.group_id) gacha = Gacha(_group_pool[gid]) elif isinstance(event, PrivateMessageEvent): name = util.normalize_str(event.get_plaintext().strip()) if not name: await gacha_pool.finish('请后接区服简称\n※例:"查看卡池jp"') elif name in ('国', '国服', 'cn'): await gacha_pool.finish('请选择详细区服\n※例:"查看卡池b服"或"查看卡池台服"') elif name in ('b', 'b服', 'bl', 'bilibili', '陆', '陆服'): name = 'BL' elif name in ('台', '台服', 'tw', 'sonet'): name = 'TW' elif name in ('日', '日服', 'jp', 'cy', 'cygames'): name = 'JP' elif name in ('混', '混合', 'mix'): name = 'MIX' else: await gacha_pool.finish('未知区服,请接区服简称\n※例:"查看卡池jp"') gacha = Gacha(name) up_chara = gacha.up up_chara = map(lambda x: str(chara.fromname(x, star=3).icon.cqcode) + x, up_chara) up_chara = '\n'.join(up_chara) await gacha_pool.finish( Message( f"本期卡池主打的角色:\n{up_chara}\nUP概率合计={(gacha.up_prob/10):.1f}%\n3★出率={(gacha.s3_prob)/10:.1f}%" ))
async def remove_auth_rec(bot: Bot, event: CQEvent, state: T_State): ''' 完全移除一个群的授权,当然群聊发送也是需要确认群号的 ''' gid = event.get_plaintext().strip() if gid: state['gid'] = gid
async def whois(bot: Bot, event: CQEvent, state: T_State): name = event.get_plaintext().strip() if not name: return id_ = chara.name2id(name) confi = 100 guess = False if id_ == chara.UNKNOWN: id_, guess_name, confi = chara.guess_id(name) guess = True c = chara.fromid(id_) if confi < 60: return 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 bot.send(event, f'>{nickname}\n兰德索尔花名册冷却中(剩余 {int(lmt.left_time(uid)) + 1}秒)') return elif isinstance(event, PrivateMessageEvent): await bot.send(event, f'兰德索尔花名册冷却中(剩余 {int(lmt.left_time(uid)) + 1}秒)') return lmt.start_cd(uid, 120 if guess else 0) if guess: if isinstance(event, GroupMessageEvent): msg = f'>{nickname}\n您有{confi}%的可能在找{guess_name} {c.icon.cqcode} {c.name}' elif isinstance(event, PrivateMessageEvent): msg = f'您有{confi}%的可能在找{guess_name} {c.icon.cqcode} {c.name}' await bot.send(event, Message(msg))
async def no_auth_check_rec(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, GroupMessageEvent): gid = event.group_id state['gid'] = gid elif isinstance(event, PrivateMessageEvent): gid = event.get_plaintext().strip() if gid: state['gid'] = gid
async def quit_rec(bot: Bot, event: CQEvent, state: T_State): if event.user_id not in configs.SUPERUSERS: await leave.finish('Insufficient authority.') if isinstance(event, GroupMessageEvent): state['gids'] = [event.group_id] elif isinstance(event, PrivateMessageEvent): gid = event.get_plaintext().split() if gid: state['gids'] = gid
async def group_list_chat(bot: Bot, event: CQEvent): ''' 此指令获得的是, 所有已经获得授权的群, 其中一些群可能Bot并没有加入 分页显示, 请在authMS.py中配置 ''' if event.user_id not in salmon.configs.SUPERUSERS: util.log(f'{event.user_id}尝试查看授权列表, 已拒绝') await auth_list.finish('只有主人才能查看授权列表哦') if isinstance(event, GroupMessageEvent): # 群聊查看授权列表你也是个小天才 await auth_list.finish('不支持群聊查看') elif isinstance(event, PrivateMessageEvent): if not event.get_plaintext().split(): # 无其他参数默认第一页 page = 1 else: page = int(event.get_plaintext().strip()) msg = '======授权列表======\n' authed_group_list = await util.get_authed_group_list() length = len(authed_group_list) groups_in_page = config.GROUPS_IN_PAGE pages_all = ceil(length / groups_in_page) # 向上取整 if page > pages_all: await auth_list.finish(f'页码错误, 当前共有授权信息{length}条, 共{pages_all}页') if page <= 0: await auth_list.finish('请输入正确的页码') i = 0 for item in authed_group_list: i = i + 1 if i < (page - 1) * groups_in_page + 1 or i > page * groups_in_page: continue gid = int(item['gid']) g_time = util.check_group(gid) msg_new = await util.process_group_msg( gid, g_time, title=f'第{i}条信息\n', end='\n\n', group_name_sp=item['groupName']) msg += msg_new msg += f'第{page}页, 共{pages_all}页\n发送授权列表+页码以查询其他页' await auth_list.finish(msg)
async def rank_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请发送需要查询rank表的区服' elif isinstance(event, PrivateMessageEvent): state['prompt'] = '请发送需要查询rank表的区服' args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def group_set(bot: Bot, event: CQEvent): if isinstance(event, GroupMessageEvent): gid = event.group_id is_su = priv.check_priv(event, priv.SUPERUSER) args = util.normalize_str(event.get_plaintext()).split() msg = '' if not is_su: msg = '权限不足' elif len(args) == 0: msg = '请后接参数(空格隔开)\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' elif args[0] == 'set' and len(args) >= 3: if len(args) >= 4 and args[3].isdigit(): gid = int(args[3]) elif args[1] == 'r18': key = 'lolicon_r18' elif args[1] == 'withdraw': key = 'withdraw' else: key = None if args[2] == 'on' or args[2] == '启用': value = True elif args[2] == 'off' or args[2] == '禁用': value = False elif args[2].isdigit(): value = int(args[2]) else: value = None if key and (not value is None): set_group_config(gid, key, value) msg = '设置成功!当前设置值如下:\n' msg += f'群/{gid} : 设置项/{key} = 值/{value}' else: msg = '无效参数\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' elif args[0] == 'status': if len(args) >= 2 and args[1].isdigit(): gid = int(args[1]) withdraw_status = "Off" if get_group_config( gid, "withdraw") == 0 else f'{get_group_config(gid, "withdraw")}s' lolicon_status = "R18" if get_group_config(gid, "lolicon_r18") else "Normal" msg = f'Group: {gid} :' msg += f'\nWithdraw: {withdraw_status}' msg += f'\nSetu: {lolicon_status}' elif args[0] == 'fetch': await bot.send(event, '开始缓存图片') await lolicon_fetch_process() msg = '缓存进程结束' elif args[0] == 'warehouse': msg = 'Warehouse:' state = check_path() for k, v in state.items(): msg += f'\n{k} : {v}' else: msg = '无效参数\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' await bot.send(event, msg)
async def no_number_check_rec(bot: Bot, event: CQEvent, state: T_State): ''' 不检查一个群的人数是否超过人数限制, 在群聊中发送则为不检查本群 ''' if isinstance(event, GroupMessageEvent): gid = event.group_id state['gid'] = gid elif isinstance(event, PrivateMessageEvent): gid = event.get_plaintext().strip() if gid: state['gid'] = gid
async def switch_recg(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, PrivateMessageEvent): await gacha_switch.finish('请在群聊内切换卡池') elif isinstance(event, GroupMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args message = f'>{nickname}\n请发送需要切换的卡池的区服' state['prompt'] = message
async def auth_query_chat(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, GroupMessageEvent): if not priv.check_priv(event, priv.ADMIN): await query_time.finish('查询授权需要管理及以上的权限') gid = event.group_id state['gids'] = [event.group_id] elif isinstance(event, PrivateMessageEvent): if event.user_id not in salmon.configs.SUPERUSERS: await query_time.finish('权限不足') gid = event.get_plaintext().split() if gid: state['gids'] = gid
async def download(bot: Bot, event: CQEvent): if event.user_id not in salmon.configs.SUPERUSERS: await bot.send(event, 'Insufficient authority.') raise FinishedException try: id_ = roster.get_id(event.get_plaintext().strip()) assert id_ != UNKNOWN, '未知角色名' download_chara_icon(id_, 6) download_chara_icon(id_, 3) download_chara_icon(id_, 1) await bot.send(event, 'OK.') except Exception as e: salmon.logger.exception(e) await bot.send(event, f'Error: {type(e)}') raise FinishedException
async def ichi_rec(bot: Bot, event: CQEvent, state: T_State): await check_jewel_num(bot, event) uid = event.user_id jewel_limit.increase(uid, 150) user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) chara, _ = gacha.gacha_one(gacha.up_prob, gacha.s3_prob, gacha.s2_prob) res = f'{chara.icon.cqcode} {chara.name} {"★"*chara.star}' await gacha_1.finish(Message(f'>{nickname}\n素敵な仲間が増えますよ!\n{res}')) elif isinstance(event, PrivateMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def add_time_chat(bot: Bot, event: CQEvent): origin = event.get_plaintext().strip() pattern = re.compile(r'^(\d{5,15})([+-]\d{1,5})$') m = pattern.match(origin) if m is None: await change_auth.finish('请发送“授权 群号±时长”来进行指定群的授权') gid = int(m.group(1)) days = int(m.group(2)) if event.user_id not in salmon.configs.SUPERUSERS: util.log(f'{event.user_id}尝试为群{gid}增加{days}天授权, 已拒绝') await change_auth.finish('权限不足') result = await util.change_authed_time(gid, days) msg = await util.process_group_msg(gid, result, title='变更成功, 变更后的群授权信息:\n') await notify_group(group_id=gid, txt=f'已为本群增加{days}天授权时长。\n可在群内发送【查询授权】来查看授权时间。') await change_auth.finish(msg)
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): msg = get_bundle_manual(name, bundles[name], event.group_id) elif isinstance(event, PrivateMessageEvent): msg = get_private_manual(name, bundles[name]) await send_help.finish(msg) elif name in svs: msg = get_service_help(name, info[name]) await send_help.finish(msg)
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 if isinstance(event, GroupMessageEvent): message = f'>{nickname}\n请发送您要反馈的内容~' elif isinstance(event, PrivateMessageEvent): message = '请发送您要反馈的内容~' state['prompt'] = message
async def whois(bot: Bot, event: CQEvent): name = event.get_plaintext().strip() if not name: return id_ = chara.name2id(name) confi = 100 guess = False if id_ == chara.UNKNOWN: id_, guess_name, confi = chara.guess_id(name) guess = True c = chara.fromid(id_) if confi < 60: return uid = event.user_id if not lmt.check(uid): await who_is.finish(f'兰德索尔花名册冷却中(剩余 {int(lmt.left_time(uid)) + 1}秒)', call_header=True) lmt.start_cd(uid, 120 if guess else 0) if guess: msg = f'兰德索尔似乎没有叫"{name}"的人...\n角色别称补全计划: github.com/Ice-Cirno/HoshinoBot/issues/5\n您有{confi}%的可能在找{guess_name} {c.icon.cqcode} {c.name}' await who_is.send(Message(msg), call_header=True) else: msg = f'{c.icon.cqcode} {c.name}' await who_is.finish(Message(msg), call_header=True)
async def bc_rec(bot: Bot, event: CQEvent, state: T_State): if event.user_id not in salmon.configs.SUPERUSERS: await broadcast.finish('Insufficient authority.') msg = event.get_message() if msg: state['msg'] = msg
async def nibyaku_rec(bot: Bot, event: CQEvent, state: T_State): await check_tenjo_num(bot, event) uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') tenjo_limit.increase(uid) if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) result = gacha.gacha_tenjou() up = len(result['up']) s3 = len(result['s3']) s2 = len(result['s2']) s1 = len(result['s1']) res = [*(result['up']), *(result['s3'])] random.shuffle(res) lenth = len(res) if lenth <= 0: res = "竟...竟然没有3★?!" else: step = 4 pics = [] for i in range(0, lenth, step): j = min(lenth, i + step) pics.append( chara.gen_team_pic(res[i:j], star_slot_verbose=False)) res = concat_pic(pics) res = pic2b64(res) res = MessageSegment.image(res) msg = [ f">{nickname}\n" f"素敵な仲間が増えますよ! {res}", f"★★★×{up+s3} ★★×{s2} ★×{s1}", f"获得记忆碎片×{100*up}与女神秘石×{50*(up+s3) + 10*s2 + s1}!\n第{result['first_up_pos']}抽首次获得up角色" if up else f"获得女神秘石{50*(up+s3) + 10*s2 + s1}个!" ] if up == 0 and s3 == 0: msg.append("太惨了,咱们还是退款删游吧...") elif up == 0 and s3 > 5: msg.append("up呢?我的up呢?") elif up == 0 and s3 <= 2: msg.append("这位酋长,梦幻包考虑一下?") elif up == 0: msg.append("据说天井的概率只有12.16%") elif up <= 2: if result['first_up_pos'] < 50: msg.append("你的喜悦我收到了,滚去喂鲨鱼吧!") elif result['first_up_pos'] < 100: msg.append("已经可以了,您已经很欧了") elif result['first_up_pos'] > 190: msg.append("标 准 结 局") elif result['first_up_pos'] > 150: msg.append("补井还是不补井,这是一个问题...") else: msg.append("期望之内,亚洲水平") elif up == 3: msg.append("抽井母五一气呵成!多出30等专武~") elif up >= 4: msg.append("记忆碎片一大堆!您是托吧?") msg = Message('\n'.join(msg)) await gacha_200.finish(msg) elif isinstance(event, PrivateMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def remove_allowlist_rec(bot: Bot, event: CQEvent, state: T_State): gid = event.get_plaintext().strip() if gid: state['gid'] = gid
async def get_spec_setu(bot: Bot, event: CQEvent, state: T_State): args = event.get_plaintext().split() if args: state['pid'] = args message = await add_header(bot, event, msg='请发送需要提取的图片的pid') state['prompt'] = message
async def ls_s(bot: Bot, event: CQEvent, state: T_State): if event.user_id not in configs.SUPERUSERS: await lss.finish('Insufficient authority.') args = event.get_plaintext().split() if args: state['service'] = args