Beispiel #1
0
async def task(event, url):
    message = await _bot.send(event, MessageSegment.image(url))
    await asyncio.sleep(20)
    if message is not None:
        await _bot.delete_msg(message_id=message['message_id'])
    else:
        await _bot.send(event, "警告:撤回失败")
async def _(session: CommandSession):
    user_id, group_id = session.event.user_id, session.event.group_id
    if session.current_arg and session.current_arg.strip() == '文本':
        await session.send(await group_user_check(user_id, group_id), at_sender=True)
    else:
        # 使用 bot 对象来主动调用 api
        nickname = (await get_bot().get_stranger_info(user_id=user_id))['nickname'] # type: ignore
        im_b64 = await group_user_check_use_b64img(user_id, group_id, nickname)
        await session.send(MessageSegment.image(f'base64://{im_b64}'), at_sender=True)
Beispiel #3
0
async def _(session: CommandSession):
    args = session.current_arg_text.strip().split(' ', 1)

    if not args[0]:
        stock = await session.aget(key='city', prompt='请输入股票或指数代码(仅支持沪深市场,上交所代码前请加SH,深交所代码前请加SZ)', at_sender=True)
    else:
        stock = args[0]

    try:
        func = get_stock_message
        result = await func(stock)
    except ServiceException as e:
        result = e.message
    await session.send(result,at_sender=True)
    await session.send(MessageSegment.image("http://image.sinajs.cn/newchart/min/n/"+stock.lower()+".gif"))
Beispiel #4
0
async def _(session: CommandSession):
    index = str(random.randint(1, 50))
    res = requests.get("https://api.bilibili.com/x/web-interface/popular?ps=1&pn=" + index)
    json_res = json.loads(res.text)
    title=json_res["data"]["list"][0]["title"]
    pic=json_res["data"]["list"][0]["pic"]
    up=json_res["data"]["list"][0]["owner"]["name"]
    link=json_res["data"]["list"][0]["short_link"]
    bv=json_res["data"]["list"][0]["bvid"]
    localtime = time.asctime(time.localtime(time.time()))
    await session.send('北京时间:' + localtime + "\n哔哩哔哩随机热门第"+index+":"
                       + "\n视频标题:" + title
                       + "\nUP主:" + up
                       + "\nBV号:" + bv
                       + "\n视频链接:" + link
                       + "\n视频封面:" + MessageSegment.image(pic))
Beispiel #5
0
async def _(session: CommandSession):
    end_time = datetime.datetime.now()
    start_time = datetime.datetime.now() + datetime.timedelta(days=-600)
    a1 = tuple(start_time.timetuple()[0:9])
    a2 = tuple(end_time.timetuple()[0:9])
    start = time.mktime(a1)
    end = time.mktime(a2)
    t = random.randint(int(start), int(end))
    date_touple = time.localtime(t)
    date = time.strftime("%Y-%m-%d", date_touple)
    res = requests.get(
        "http://sentence.iciba.com/index.php?c=dailysentence&m=getdetail&title="
        + date)
    json_str = json.loads(res.text)
    chinese = json_str["note"]
    english = json_str["content"]
    pic = json_str["picture2"]
    voice = json_str["tts"]
    await session.send("英文原文:" + english + "\n翻译:" + chinese + "\n封面:" +
                       MessageSegment.image(pic))
    await session.send(MessageSegment.record(voice))
async def _(session: CommandSession):
    header = {
        "user-agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/89.0.4389.90 "
        "Safari/537.36 "
    }
    res = requests.get("https://news-at.zhihu.com/api/3/stories/latest",
                       headers=header)
    json_str = json.loads(res.text)
    index = random.randint(0, len(json_str["stories"]) - 1)
    title = json_str["stories"][index]["title"]
    image = json_str["stories"][index]["images"][0]
    url = json_str["stories"][index]["url"]
    print(title)
    print(image)
    print(url)
    localtime = time.asctime(time.localtime(time.time()))
    await session.send('北京时间:' + localtime + " 知乎日报" + "\n文章标题:" + title +
                       "\n文章链接:" + url + "\n文章封面:" +
                       MessageSegment.image(image))
Beispiel #7
0
def getVideoInfo(param_aid, param_bvid):
    url = f'https://api.bilibili.com/x/web-interface/view?aid={param_aid}&bvid={param_bvid}'
    try:
        with requests.get(url, timeout=20) as resp:
            res = resp.json()
            data = res['data']
            bvid = data['bvid']
            aid = data['aid']
            pic = data['pic']
            title = data['title']
            name = data['owner']['name']
            view = data['stat']['view']
            danmaku = data['stat']['danmaku']
            play = humanNum(view)
            danku = humanNum(danmaku)
            cover = MessageSegment.image(pic)
            result = f'{cover}\nav{aid}\n{title}\nUP:{name}\n{play}播放 {danku}弹幕\nhttps://www.bilibili.com/video/{bvid}'.strip(
            )
            return result
    except Exception as ex:
        sv.logger.error(f'[getVideoInfo ERROR]:{ex}')
        return None
Beispiel #8
0
def getSearchVideoInfo(keyword):
    url = f'https://api.bilibili.com/x/web-interface/search/all/v2?keyword={keyword}'
    try:
        with requests.get(url, timeout=20) as resp:
            res = resp.json()
            data = res['data']['result']
            videos = [x for x in data if x['result_type'] == 'video']
            if len(videos) == 0:
                return ''
            video_list = videos[0]['data']
            if len(video_list) > 10:
                video_list = video_list[0:10]
            result = ''
            for item in video_list:
                aid = item['aid']
                bvid = item['bvid']
                pic = item['pic']
                desc = html2text.html2text(item['description'])
                play = humanNum(item['play'])
                danku = humanNum(item['video_review'])
                title = html2text.html2text(item['title'])
                title = title.strip()
                cover = MessageSegment.image(f'https:{pic}')
                author = item['author']
                result += f'''{cover}
{title}
{desc}
av{aid}
UP:{author}
{play}播放  {danku}弹幕
源地址:https://www.bilibili.com/video/{bvid}
===========>
                '''.strip()
            result += '\n搜索结束,冷却时间120秒'
            return result
    except Exception as ex:
        sv.logger.error(f'[getSearchVideoInfo ERROR]:{ex}')
        return f'搜索{keyword}出错,请稍后再试~'
Beispiel #9
0
def getSearchVideoInfo(keyword):
    url = f'https://api.bilibili.com/x/web-interface/search/all/v2?{keyword}'
    try:
        with requests.get(url, timeout=20) as resp:
            res = resp.json()
            data = res['data']['result']
            videos = [x for x in data if x['result_type'] == 'video']
            if (len(videos) == 0):
                return None
            video = videos[0]['data'][0]
            aid = video['aid']
            bvid = video['bvid']
            pic = video['pic']
            play = humanNum(video['play'])
            danku = humanNum(video['video_view'])
            title = html2text.html2text(video['title'])
            cover = MessageSegment.image(f'http://{pic}')
            author = video['author']
            result = f'{cover}\n(搜索)av{aid}\n{title}\nUP:{author}\n{play}播放 {danku}弹幕\nhttps://www.bilibili.com/video/{bvid}'.strip(
            )
            return result
    except Exception as ex:
        sv.logger.error(f'[getSearchVideoInfo ERROR]:{ex}')
        return None
async def send_common_setu(bot, event: Event):
    uid = event.user_id
    self_id = event.self_id
    gid = event.group_id
    user_priv = get_user_priv(event)
    is_to_delete = True if gid in g_delete_groups else False

    if not _num_limiter.check(uid):
        await bot.send(event, EXCEED_NOTICE)
        return

    if not _freq_limiter.check(uid):
        await bot.send(event, TOO_FREQUENT_NOTICE)
        return

    if not ONLINE_MODE:
        sv.logger.info('发送本地涩图')
        pic = R.get_random_image('nr18_setu')
        ret = await bot.send(event, pic)
        msg_id = ret['message_id']
        if is_to_delete:
            #30秒后删除
            await asyncio.sleep(30)
            await bot.delete_msg(self_id=self_id, message_id=msg_id)
        return

    robj = event['match']
    try:
        num = int(robj.group(1))
    except:
        num = 1

    #按照数量设置limiter
    _num_limiter.increase(uid, num)
    _freq_limiter.start_cd(uid, num * 5)

    keyword = robj.group(2).strip()
    if keyword:
        await bot.send(event, '正在搜索,请稍等~')
        sv.logger.info(f'含有关键字{keyword},尝试搜索')
        if user_priv < SUPERUSER:
            setus = await get_final_setu_async(search_path,
                                               keyword=keyword,
                                               r18=0)
        else:
            setus = await get_final_setu_async(search_path,
                                               keyword=keyword,
                                               r18=2)
        if not setus:
            await bot.send(event, f'没有找到关键字{keyword}的涩图,您将被禁用涩图服务60s')
            _freq_limiter.start_cd(uid, 60)
            sv.logger.info(
                f'{uid} searched keyword {keyword} and returned no result')
            return
        setu = setus[0]
        pic_path = await download_async(setu.url, search_path, setu.pid)
        pic = MessageSegment.image(pic_path)
        reply = f'{setu.title}\n画师:{setu.author}\npid:{setu.pid}{pic}'
        try:
            await bot.send(event, reply, at_sender=False)
            _num_limiter.increase(uid)
            _freq_limiter.start_cd(uid, 30)
        except Exception as ex:
            await bot.send(event, f'搜索关键字{keyword}发生异常')
            sv.logger.error(f'搜索涩图时发生异常 {ex}')
    else:
        setus = wh.fetch(num)
        if not setus:  #send_setus为空
            await bot.send(event, '色图库正在补充,下次再来吧', at_sender=False)
            return
        else:
            await send_setus(bot, event, 'nr18_setu', setus, WITH_URL,
                             is_to_delete)