async def colorImage(session: CommandSession): # 获取城市的天气预报 # 向用户发送天气预报 msg=Message() url="http://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&word=%E8%89%B2%E5%9B%BE" imgurl='https://s2.ax1x.com/2019/03/29/A00Whn.png' # msg.append(MessageSegment.share(url,"色图","网警已介入本群",imgurl)) msg.append(MessageSegment.image('https://s2.ax1x.com/2019/11/16/MBYbmd.jpg')) msg.extend('没有色图给👴爬') await session.send(msg)
async def banVote(session: CommandSession): banQQ = None for x in session.ctx['message']: if x.type == 'at': banQQ = x.data['qq'] if banQQ is None: return groupId = session.ctx['group_id'] if banList.get(groupId) is None: banList[groupId] = {} groupBanList = banList[groupId] if groupBanList.get(banQQ) is None: groupBanList[banQQ] = [] usrId = session.ctx.get('user_id') if usrId not in groupBanList[banQQ]: groupBanList[banQQ].append(usrId) limit = banConfig.get(str(groupId)) bot = nonebot.get_bot() if limit is None: try: info = await bot.get_group_info(group_id=groupId) limit = info.get('member_count') // 3 except CQHttpError as e: pass return msg = Message() try: info = await bot.get_group_member_info(group_id=groupId, user_id=banQQ) except CQHttpError as e: pass return msg.extend( f"投票对{info.get('nickname')}的禁言{len(groupBanList[banQQ])}/{limit}") await session.send(msg) if len(groupBanList[banQQ]) >= limit: try: info = await bot.set_group_ban(group_id=groupId, user_id=banQQ, duration=60 * limit) groupBanList[banQQ] = None except CQHttpError as e: pass return
async def sendMessageCached(): bot = nonebot.get_bot() try: pass data = {'formBot': True} try: async with aiohttp.request( 'POST', f'http://{configJs["serverip"]}:{configJs["messageServerListen"]}', data=json.dumps(data), timeout=aiohttp.client.ClientTimeout(total=timeWait - 1)) as r: js = await r.text() js = json.loads(js) # res = requests.post('http://127.0.0.1:50382', data=json.dumps(data),timeout=3) # js = json.loads(res.text) # print('messcache') except: return for i in js: print(i) msg = Message('') # int(i.get('qq_group_id')) if not i.get('ensure_private'): for j in i.get('qq_id_list'): msg.append(MessageSegment.at(int(j))) if len(i.get('qq_id_list')) > 0: msg.extend('\n') textObj = i.get('text') if isinstance(textObj, list): for j in textObj: msg.extend(j.replace('$', ' ')) else: try: msg.extend(textObj) except: print(f'i.get() error') imageList = i.get('img') if isinstance(imageList, list): for j in imageList: if len(j) > 0: msg.append(MessageSegment.image(j)) else: try: if len(imageList) > 0: msg.append(MessageSegment.image(imageList)) except: print(f'image send error') if i.get('ensure_private'): for qqid in i.get('qq_id_list'): await bot.send_private_msg(user_id=qqid, message=msg) else: await bot.send_group_msg(group_id=int(i.get('qq_group_id')), message=msg) # await bot.send_group_msg(group_id=967636480, # message=f'给爬') except CQHttpError: pass
async def var_replace(event: Event, message: Message, kwargs: Dict[str, Any]): origin_msg_str = str(message) repaced_msg_str = replace(origin_msg_str, event) message.clear() message.extend(repaced_msg_str)