Пример #1
0
 def record(cls, rec_path) -> 'MessageSegment':
     if cls.check_exist(rec_path):
         return MessageSegment.record(f'file:///{rec_path}')
     elif cls.check_exist(path.join(cls.record_dir, rec_path)):
         return MessageSegment.record(
             f'file:///{path.join(cls.record_dir, rec_path)}')
     else:
         return '【图片丢了】'
Пример #2
0
 def image(cls, pic_path: str) -> 'MessageSegment':
     if cls.check_exist(pic_path):
         return MessageSegment.image(f'file:///{pic_path}')
     elif cls.check_exist(path.join(cls.image_dir, pic_path)):
         return MessageSegment.image(
             f'file:///{path.join(cls.image_dir, pic_path)}')
     else:
         return '【图片丢了】'
Пример #3
0
 def get_random_image(cls, folder=None) -> 'MessageSegment':
     if not folder:
         image_path = cls.image_dir
     else:
         image_path = path.join(cls.image_dir, folder)
     image_name = get_random_file(image_path)
     return MessageSegment.image(f'file:///{path.join(image_path, image_name)}')
Пример #4
0
async def abWord(session: CommandSession):
    target = session.current_arg_text.strip()
    imageList = await getImage(target, 5)
    for x in imageList:
        msg = Message()
        msg.append(MessageSegment.image(x))
        await session.send(msg, ensure_private=True)
Пример #5
0
 async def deco(*args):
     bot, event, _ = tuple(args)
     await func(bot, event, _)
     raw_message = event.raw_message
     cherugo_decode = cheru2str(raw_message)
     event.raw_message = cherugo_decode
     event.message.clear()
     event.message.append(MessageSegment.text(cherugo_decode))
     await func(bot, event, _)
Пример #6
0
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)
Пример #7
0
 def parse(cls, data: APIData_T) -> APIData_T:
     assert not data["code"], data["msg"]
     vidData = data["data"]
     return {
         "aid": vidData["aid"],
         "bid": IDCoverter.av2bv(vidData["aid"]),
         "title": vidData["title"],
         "desc": vidData["desc"],
         "cover": MessageSegment.image(vidData["pic"]),
         "duration": cls.encodeTime(vidData["duration"]),
         "time": cls.stamp2Time(vidData["pubdate"]),
         "part": vidData["videos"],
         "author": vidData["owner"]["name"],
         "author_id": vidData["owner"]["mid"],
         "author_face": MessageSegment.image(vidData["owner"]["face"]),
         "view": vidData["stat"]["view"],
         "danmaku": vidData["stat"]["danmaku"],
         "share": vidData["stat"]["share"],
         "like": vidData["stat"]["share"],
         "coin": vidData["stat"]["coin"],
         "favorite": vidData["stat"]["favorite"],
     }
Пример #8
0
 async def save_image(cls, event: Event) -> None:
     for i, m in enumerate(event.message):
         match = re.match('\[CQ:image.+?\]', str(m))
         if match:
             try:
                 url = re.findall(r'http.*?term=\d', str(m))[0]
                 save_name = re.findall(r'(?<=-)[^-]*?(?=/)', url)[0]
                 image_path = await download_async(url, cls.image_dir,
                                                   save_name)
                 event.message[i] = MessageSegment.image(image_path)
             except Exception as ex:
                 logger.warning(f'保存图片时发生错误{ex}')
     event.raw_message = str(event.message)
Пример #9
0
async def handle(context):
    #if str(context['message']) == '赞':
    # await bot.send_like(user_id=context['user_id'],times=10)
    # await bot.send(context,Message('已赞'))
    x = await bot.get_group_member_info(group_id=context['group_id'],
                                        user_id=context['user_id'],
                                        no_cache=True)
    a = context['group_id']
    print(a)
    n = x['card']
    if n == '':
        if a == 537154370:
            await bot.send(
                context,
                MessageSegment.at(context['user_id']) +
                Message('\n请修改群名片哦,群名片格式:\n年级-地区-名称'))
        else:
            await bot.send(
                context,
                MessageSegment.at(context['user_id']) +
                Message('\n请修改群名片哦,群名片格式:\n年级-专业-名称'))
    else:
        pass
Пример #10
0
async def music(session: CommandSession):
    #args = session.current_arg_text.strip(' ',1)
    #if not args[0]:
    keyword = session.get('keyword',
                          prompt='你想听什么歌呢?',
                          arg_filters=[
                              extractors.extract_text, str.strip,
                              validators.not_empty('歌名不能为空哦,请重新发送')
                          ])
    #else:
    #    keyword = args[0]
    song_id = await search_song_id(keyword)
    if song_id is None:
        await session.send('没有找到这首歌呢', at_sender=True)
    else:
        await session.send(MessageSegment.music('qq', song_id), at_sender=True)
Пример #11
0
def _(session: CommandSession):
    session.send("开始生成词云")
    latestTime = datetime.datetime.now() - DELTA_TIME
    if "group_id" in session.ctx:
        messageIter = messageGenterator(group_id=session.ctx["group_id"],
                                        latestTime=latestTime)
    else:
        messageIter = messageGenterator(user_id=session.ctx["user_id"],
                                        latestTime=latestTime)
    wordcloud = WordcloudMaker()
    for data in messageIter:
        data: models.RecordsRead
        sentence = data.content
        wordcloud.update(sentence)
    imageData = wordcloud.save()
    return MessageSegment.image(f"base64://{b64encode(imageData).decode()}")
Пример #12
0
async def creep(bot: HoshinoBot, ev: CQEvent):
    match = re.match(r'(?:(?:rua)|(?:Rua)|搓)\[CQ:at,qq=(\d+?)\]',
                     ev.raw_message)
    if not match:
        match = re.match(r'\[CQ:at,qq=(.+?)\] (?:(?:rua)|(?:Rua)|搓)',
                         ev.raw_message)
    if not match:
        return
    creep_id = match.group(1)

    url = f'http://q1.qlogo.cn/g?b=qq&nk={creep_id}&s=160'
    resp = await aiorequests.get(url)
    resp_cont = await resp.content
    avatar = Image.open(BytesIO(resp_cont))
    output = generate_gif(data_dir, avatar)
    print(output)
    await bot.send(ev, MessageSegment.image(f'file:///{output}'))
Пример #13
0
 async def save_image(cls, event: Event, folder=None) -> None:
     if not folder:
         image_path = cls.image_dir
     else:
         image_path = path.join(cls.image_dir, folder)
     if not path.isdir(image_path):
         os.mkdir(image_path)
     for i, m in enumerate(event.message):
         match = re.match('\[CQ:image.+?\]', str(m))
         if match:
             try:
                 url = re.findall(r'http.*?term=\d', str(m))[0]
                 save_name = re.findall(r'(?<=-)[^-]*?(?=/)', url)[0]
                 image = await download_async(url, image_path, save_name)
                 event.message[i] = MessageSegment.image(f'file:///{image}')
             except Exception as ex:
                 print_exc()
     event.raw_message = str(event.message)
Пример #14
0
def _(session: CommandSession):
    session.send("开始生成统计")
    latestTime = datetime.datetime.now() - DELTA_TIME
    newestTime = _datetimeRound(datetime.datetime.now())
    frameMaker = DataFrameMaker({"date": str, "time": float})
    if "group_id" in session.ctx:
        messageIter = messageGenterator(
            group_id=session.ctx["group_id"],
            newestTime=newestTime,
            latestTime=latestTime,
        )
    else:
        messageIter = messageGenterator(user_id=session.ctx["user_id"],
                                        newestTime=newestTime,
                                        latestTime=latestTime)
    for data in messageIter:
        date = str(data.time.date())
        time = _time2Int(data.time.time())
        frameMaker.update({"date": date, "time": time})
    imageData = Chart.chatFrequency(frameMaker.read())
    return MessageSegment.image(f"base64://{b64encode(imageData).decode()}")
Пример #15
0
 async def image_from_url(cls, url: str, cache=True) -> 'MessageSegment':
     fname = get_str_md5(url)
     image = path.join(cls.image_dir, f'{fname}.jpg')
     if not path.exists(image) or not cache:
         image = await download_async(url, cls.image_dir, fname, 'jpg')
     return MessageSegment.image(f'file://{image}')
Пример #16
0
 def record(cls, rec_path) -> 'MessageSegment':
     return MessageSegment.record(
         f'file:///{path.join(cls.record_dir, rec_path)}')
Пример #17
0
 def image(cls, pic_path: str) -> 'MessageSegment':
     return MessageSegment.image(
         f'file:///{path.join(cls.image_dir, pic_path)}')
Пример #18
0
async def _(session: CommandSession):
    city = session.get('city', prompt='输入您所在城市')
    keyword = session.get('keyword', prompt='输入您要查询的具体位置')
    location = get_location(keyword, city)
    reps = MessageSegment.location(location['lat'], location['lng'])
    await session.send(reps)
Пример #19
0
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
Пример #20
0
 def image(cls, pic_path: str) -> 'MessageSegment':
     return MessageSegment.image(path.join(cls.image_dir, pic_path))
Пример #21
0
 def record(cls, rec_path) -> 'MessageSegment':
     return MessageSegment.record(path.join(cls.record_dir, rec_path))
Пример #22
0
async def _(session: CommandSession):
    path = await get_Pic()
    file='file:///' + path
    seq = MessageSegment(type_='image',data={'file':file, 'destruct':'0'})
    await session.send(seq)