async def call(context): if context.get("group_id"): if not cache.get(context.get("group_id")): cache.set(context.get("group_id"), type(str(context.get("group_id")), (Cache, ), {})()) if not list(cache.get(context.get("group_id")).values()): return "现在没人联机了, 自己发起吧." shouldBe = True tick = 0 while shouldBe and tick < 8: result = random.choice( list(cache.get(context.get("group_id")).values())) if result['user_id'] != context['user_id']: shouldBe = False tick += 1 if tick >= 8 and shouldBe: return "错误: 等待列表中可能只有你一个人吧= =" return "".join([ str(MessageSegment.at(result['user_id'])), ", ", str(MessageSegment.at(context['user_id'])), " 找你联机!" ]) else: return "本指令不支持私人聊天."
async def ro(session: CommandSession): userid = session.ctx['user_id'] result = "" if session.get('readable') == 1: array, result = calculate(session.get('expression')) result = MessageSegment.at(userid) + '投掷为' + str(array) + "合计为" + str(result) elif session.get('readable') == 2: skill = session.get('skill') ability = session.get('ability') _, result = roll(1, 100) success = issuccess(result, ability) result = MessageSegment.at(userid) + '投掷的' + skill + '为' + str(result) + ',' + success elif session.get('readable') == 3: skill = session.get('skill') ability = session.get('ability') _, tmp1 = roll(1, 100) _, tmp2 = roll(1, 100) if tmp1 == 100: tmp1 = 0 if tmp2 == 100: tmp2 = 0 result1 = max(tmp1 / 10, tmp2 / 10) result2 = min(tmp1 % 10, tmp2 % 10) result = int(result1) * 10 + result2 success = issuccess(result, ability) result = MessageSegment.at(userid) + '投掷的' + skill + '为[' + \ str(tmp1) + ', ' + str(tmp2) + "]计算惩罚骰结果为" + str(result) + success elif session.get('readable') == 4: skill = session.get('skill') ability = session.get('ability') _, tmp1 = roll(1, 100) _, tmp2 = roll(1, 100) if tmp1 == 100: tmp1 = 0 if tmp2 == 100: tmp2 = 0 result1 = min(tmp1 / 10, tmp2 / 10) result2 = max(tmp1 % 10, tmp2 % 10) result = int(result1) * 10 + result2 success = issuccess(result, ability) result = MessageSegment.at(userid) + '投掷的' + skill + '为[' + \ str(tmp1) + ', ' + str(tmp2) + "]计算奖励骰结果为" + str(result) + "," + success else: result = "骰娘无法读懂您的参数呢QAQ" with open("command_log.txt", "a") as f: f.write(str(result)) await session.send(result)
async def handle_message(bot: NoneBot, ctx: Dict[str, Any]) -> None: _log_message(ctx) if ctx['message_type'] != 'private': # group or discuss ctx['to_me'] = False first_message_seg = ctx['message'][0] if first_message_seg == MessageSegment.at(ctx['self_id']): ctx['to_me'] = True del ctx['message'][0] if not ctx['message']: ctx['message'].append(MessageSegment.text('')) else: ctx['to_me'] = True while True: try: handled = await handle_command(bot, ctx) break except SwitchException as e: # we are sure that there is no session existing now ctx['message'] = e.new_ctx_message ctx['to_me'] = True if handled: logger.info(f'Message {ctx["message_id"]} is handled as a command') return handled = await handle_natural_language(bot, ctx) if handled: logger.info(f'Message {ctx["message_id"]} is handled ' f'as natural language') return
def _check_at_me(bot: NoneBot, event: CQEvent) -> None: if event.detail_type == 'private': event['to_me'] = True else: # group or discuss event['to_me'] = False at_me_seg = MessageSegment.at(event.self_id) # check the first segment first_msg_seg = event.message[0] if first_msg_seg == at_me_seg: event['to_me'] = True del event.message[0] if not event['to_me']: # check the last segment i = -1 last_msg_seg = event.message[i] if last_msg_seg.type == 'text' and \ not last_msg_seg.data['text'].strip() and \ len(event.message) >= 2: i -= 1 last_msg_seg = event.message[i] if last_msg_seg == at_me_seg: event['to_me'] = True del event.message[i:] if not event.message: event.message.append(MessageSegment.text(''))
async def get_result(num: int, max: int, userid) -> str: result = 0 result_string = "" if num > 20: return "个数太多骰娘数不过来啦QAQ" for i in range(num): result_string += "," + str(random.randint(1, max)) result_string = MessageSegment.at(userid) + "投掷结果为" + result_string return result_string
async def cherulize(bot, ev: CQEvent): s = ev.message.extract_plain_text() at = MessageSegment.at(ev.user_id) if len(s) > 500: await bot.send(ev, f'{at} 切、切噜太长切不动勒切噜噜...') return msg = ['切噜~♪' + str2cheru(s)] await bot.send(ev, f'{at}说: ' + '\n'.join(msg)) await util.delete_msg(ev, ev.message_id)
def has_at_bot(self, event: Event, message: str): """ 是否有人 at 机器人 """ has_at = False msg = Message(message) for seg in msg: if seg == MessageSegment.at(event.self_id): has_at = True return has_at
async def coc(session: CommandSession): userid = session.ctx["user_id"] attribute = ['力量', '体质', '体型', '敏捷', '外貌', '智力', '意志', '教育', '幸运'] result = "COC7版投掷结果\n" for i in range(6): tmp = get_coc() for j in range(9): result = result + attribute[j] + ":" + str(tmp[j]) result = result + '\n' await session.send(MessageSegment.at(userid) + result)
async def _(event): msg = Message(event.message) numpad = False for seg in msg: if seg == MessageSegment.at(event.self_id): numpad = True if numpad: seg = Message(seg).extract_plain_text().strip() data = reply(seg) await send(event, data) numpad = False
async def farm_bc(bot, ev): if not priv.check_priv(ev, priv.ADMIN): await bot.send(ev, '只有群管理才可以召回成员~', at_sender=True) return d_farm_object = {} with f_farm.open('r') as f: d_farm_object = json.load(f) gid = str(ev['group_id']) if gid not in d_farm_object: await bot.send(ev, '农场里没有人诶') return else: l_uid = d_farm_object[gid] msg = [str(MessageSegment.at(user_id=uid)) for uid in l_uid] await bot.send(ev, f'{"".join(msg)} 是时候从农场回来啦!\n使用【回公会:IDxxxxx】将信息登记到BOT, 可以方便管理员统一邀请哦')
async def coc(session: CommandSession): userid = session.ctx["user_id"] result = "DND5E投掷结果" for i in range(6): result += "\n" + str(get_dnd()) await session.send(MessageSegment.at(userid) + result)
def at_current(event: Event) -> 'MessageSegment': return MessageSegment.at(event.user_id)
def at_all() -> 'MessageSegment': return MessageSegment.at('all')