Beispiel #1
0
async def material_remind():
    # 每日提醒
    if time.strftime("%w") == "0":
        # 如果今天是周日就不发了
        return
    bot = get_bot()
    arms_material_CQ = get_today_material("武器突破材料")
    roles_material_CQ = get_today_material("角色天赋材料")
    for gid in group_list:
        await bot.send_group_msg(group_id=int(gid), message=arms_material_CQ)
        await bot.send_group_msg(group_id=int(gid), message=roles_material_CQ)
Beispiel #2
0
async def daily_music():
    bot = hoshino.get_bot()
    musicId, musicInfo = music_gener.__next__()
    msg = [
        "美食殿今日的晚间音乐~", f"{musicInfo[1]}",
        f"{R.img('priconne/dailymusic/', musicInfo[4]).cqcode}",
        f"歌曲名: {musicInfo[2]}", f"歌手: {musicInfo[3]}"
    ]
    music = MessageSegment.music(type_=musicInfo[0], id_=musicId)
    await bot.send_group_msg(group_id=602138153, message='\n'.join(msg))
    await bot.send_group_msg(group_id=602138153, message=music)
Beispiel #3
0
async def new_longwang(session: NoticeSession):
    if session.event['sub_type'] == 'honor' and session.event[
            'honor_type'] == 'talkative':
        uid = session.event['user_id']
        gid = session.event['group_id']
        at = MessageSegment.at(uid)
        bot = hoshino.get_bot()
        data = await bot.get_group_honor_info(group_id=gid, type='talkative')
        current_talkactive = data['current_talkative']
        day = current_talkactive['day_count']
        msg = f'新的龙王已经出现{at},已蝉联{day}天'
        await session.send(msg)
Beispiel #4
0
async def music_daily_push():
    bot = hoshino.get_bot()
    glist = await sv.get_enable_groups()
    info_head = '今日份的午间音乐广播~'
    for gid, selfids in glist.items():
        song_info, song_data = await get_next_song(gid)
        await bot.send_group_msg(self_id=random.choice(selfids),
                                 group_id=gid,
                                 message=info_head + song_info)
        await bot.send_group_msg(self_id=random.choice(selfids),
                                 group_id=gid,
                                 message=get_music_from_song_data(song_data))
        await asyncio.sleep(0.5)
Beispiel #5
0
async def clanbattle_rank_push_final():
    days = get_days_from_battle_start()
    if days != cycle_data['battle_days'] - 1:
        return
    bot = hoshino.get_bot()
    group_list = get_group_list()
    for gid in group_list:
        msg = '公会战即将结束,各位成员辛苦了!\n祝大家人生有梦,各自精彩!\n'
        msg += await get_follow_clan_report(gid)
        try:
            await bot.send_group_msg(group_id=int(gid), message=msg)
            hoshino.logger.info(f'群{gid} 推送排名成功')
        except:
            hoshino.logger.info(f'群{gid} 推送排名错误')
Beispiel #6
0
async def nga_spider():
    broadcast_groups = get_broadcast_groups()
    if not (broadcast_groups['cn']):
        return
    bot = hoshino.get_bot()
    NGASpider.set_cookies(await get_nga_cookies())
    for section in broadcast_groups.keys():
        if broadcast_groups[section]:
            if not NGASpider.idx_cache[section]:
                NGASpider.idx_cache[section] = load_file(
                    f'idx_cache_{section}.json', [])
            await spider_work(NGASpider, bot, section,
                              broadcast_groups[section], sv, '深渊战场爬虫')
            save_file(NGASpider.idx_cache[section],
                      f'idx_cache_{section}.json')
Beispiel #7
0
async def job():
    #改用interval+随机start_time方式,避开jitter的bug
    bot = hoshino.get_bot()
    updated = await check_update()

    available_group = await sv.get_enable_groups()
    glist = get_group_list()
    tasks = []
    for group_id in glist:
        if int(group_id) in available_group:
            if updated:
                await send_group_msg(bot, group_id, 'clanbattle_info插件检测到新的提交记录,请及时更新.')
            tasks.append(asyncio.ensure_future(group_process(bot, str(group_id))))
    for task in asyncio.as_completed(tasks):
        await task
Beispiel #8
0
async def twitter_search_spider():
    bot = hoshino.get_bot()
    config = load_config()
    for url in config.keys():
        gid = []
        for item in config[url]:
            gid.append(item[0])
        if gid:
            rss = RSS_class.rss()
            rss.url = url
            rss.gid = gid
            await spider_work(rss, bot, sv)
    for root, dirs, files in os.walk(hoshino_path):
        for name in files:
            if name.endswith('.jpg'):
                os.remove(os.path.join(root, name))
Beispiel #9
0
async def clanbattle_rank_push_daily():
    days = get_days_from_battle_start()
    if days >= cycle_data['battle_days']:
        return
    bot = hoshino.get_bot()
    group_list = get_group_list()
    for gid in group_list:
        if days == 0:
            msg = '公会战开始啦!看看这都几点了?还不快起床出刀?'
        else:
            msg = await get_follow_clan_report(gid)
        try:
            await bot.send_group_msg(group_id=int(gid), message=msg)
            hoshino.logger.info(f'群{gid} 推送排名成功')
        except:
            hoshino.logger.info(f'群{gid} 推送排名错误')
Beispiel #10
0
async def del_deffend(session: CommandSession):
    ev = session.event
    uid = ev.user_id
    bot = hoshino.get_bot()
    if uid not in bot.config.SUPERUSERS:
        return
    defen = ev.message.extract_plain_text()
    defen = re.sub(r'[??,,_]', '', defen)
    defen, unknown = chara.roster.parse_team(defen)

    if unknown:
        _, name, score = chara.guess_id(unknown)
        if score < 70 and not defen:
            return  # 忽略无关对话
        msg = f'无法识别"{unknown}"' if score < 70 else f'无法识别"{unknown}" 您说的有{score}%可能是{name}'
        await session.finish(msg)
    if not defen:
        return
    if len(defen) > 5:
        await session.finish('编队不能多于5名角色')
    if len(defen) < 5:
        await session.finish('编队不能少于5名角色')
    if len(defen) != len(set(defen)):
        await session.finish('编队中含重复角色')
    if any(chara.is_npc(i) for i in defen):
        await session.finish('编队中含未实装角色')
    if 1004 in defen:
        await session.send('\n⚠️您正在查询普通版炸弹人\n※万圣版可用万圣炸弹人/瓜炸等别称')

    # 预处理缓存图片
    defen_list = defen.copy()
    defen_list.sort()
    filename = '-'.join(str(v) for v in defen_list)
    filename = f'{filename}.jpg'
    save_path = R.img('tmp/', filename).path
    if os.path.exists(save_path):
        os.remove(save_path)

    attack = ",".join(str(v) for v in defen_list)
    # zuoye = jijian.get_attack(attack)
    # if zuoye is None:
    #     await bot.send(ev, '作业不存在')
    # else:
    #     jijian.del_attack(attack)
    #     await bot.send(ev, '删除作业完了')
    jijian.del_attack(attack)
    await session.send('删除作业完了')
Beispiel #11
0
async def zhoubao(bot, ev):
    bot = hoshino.get_bot()
    response = req.get(getzhoubaoImg(sethtml1()))
    ls_f = base64.b64encode(BytesIO(response.content).read())
    imgdata = base64.b64decode(ls_f)
    save_dir = R.img('destiny2').path
    path_dir = os.path.join(save_dir, 'zhoubao.jpg')
    file = open(path_dir, 'wb')
    # 以base64的形式写入文件,用于下载图片
    file.write(imgdata)
    file.close()
    # 先用下面这个形式写,万一以后要加新功能呢
    pzhoubao = ' '.join(map(str, [
        R.img(f'destiny2/zhoubao.jpg').cqcode,
    ]))
    msg = f'命运2 周报:\n图片作者:seanalpha\n{pzhoubao}'
    await bot.send(ev, msg)
Beispiel #12
0
async def send_calendar(group_id):
    bot = hoshino.get_bot()
    available_group = await sv.get_enable_groups()
    if str(group_id) not in group_data or int(group_id) not in available_group:
        return
    for server in group_data[str(group_id)]['server_list']:
        im = await generate_day_schedule(server)
        base64_str = im2base64str(im)
        msg = f'[CQ:image,file={base64_str}]'
        for _ in range(5):  #失败重试5次
            try:
                await bot.send_group_msg(group_id=int(group_id), message=msg)
                sv.logger.info(f'群{group_id}推送{server}日历成功')
                break
            except:
                sv.logger.info(f'群{group_id}推送{server}日历失败')
            await asyncio.sleep(60)
Beispiel #13
0
async def job():
    bot = hoshino.get_bot()
    updated = await check_update()

    available_group = {}
    bot_group_list = await bot.get_group_list()
    for item in bot_group_list:
        available_group[int(item['group_id'])] = True

    glist = get_group_list()
    tasks = []
    for group_id in glist:
        if int(group_id) in available_group:
            if updated:
                await bot.send_group_msg(
                    group_id=int(group_id),
                    message='clanbattle_info插件检测到新的提交记录,请及时更新.')
            tasks.append(
                asyncio.ensure_future(group_process(bot, str(group_id))))
    for task in asyncio.as_completed(tasks):
        await task
Beispiel #14
0
async def music_daily_push():
    bot = hoshino.get_bot()
    glist = await sv.get_enable_groups()
    info_head = '今日份的午间音乐广播~'
    for gid, selfids in glist.items():
        song_info, song_data = await get_next_song(gid)
        if song_data[0] == 'bili':
            music = MessageSegment.share(
                url='https://www.bilibili.com/video/' + song_data[1],
                title=song_data[3],
                content=song_data[4],
                image_url=
                "http://i0.hdslb.com/bfs/archive/b28c463d04db58f6eb79e238757b78ab1f609ec0.png"
            )
        else:
            music = MessageSegment.music(type_=song_data[0], id_=song_data[1])
        await bot.send_group_msg(self_id=random.choice(selfids),
                                 group_id=gid,
                                 message=info_head + song_info)
        await bot.send_group_msg(self_id=random.choice(selfids),
                                 group_id=gid,
                                 message=music)
        await asyncio.sleep(0.5)
            f"番剧更新:{ep.title}\n下载链接:{self.config['public_url']}{os.path.basename(src)}"
        )


mikan = Mikan()

if not Episode.table_exists():
    Episode.create_table()


@sv.scheduled_job('interval', minutes='3')
async def mikan_poller():
    await mikan.scheduled_job()


app = hoshino.get_bot().server_app


@app.before_serving
async def initial():
    loop.create_task(mikan.initial_async())


admin = Blueprint('mikan', __name__, url_prefix='/mikan/admin')


@app.route('/')
async def homepage():
    pass

async def bili_search_spider():
    bot = hoshino.get_bot()
    config = load_config()
    for gid in config.keys():
        BiliSearchSpider.set_url(gid, config[gid])
        await spider_work(BiliSearchSpider, bot, gid, sv, 'B站搜索爬虫')
Beispiel #17
0
                               user_id=uid,
                               group_id=gid,
                               message=image_data_report[1])
        if not (image_data_report[0] or image_data_report[1]):
            logger.error("ascii2d not found imageInfo")
            await bot.send_msg(self_id=sid,
                               user_id=uid,
                               group_id=gid,
                               message='ascii2d检索失败…')


@bot.on_message('guild')
async def gpicfinder(ev: CQEvent):
    if (tid := ev.user_id) == ev.self_tiny_id:
        return
    if int(ev.channel_id) not in enableguild.get(int(ev.guild_id), []):
        return
    ret = []
    for i in ev.message:
        if i['type'] == 'image':
            ret.append(i['data']['url'])
    if not ret:
        return
    if not lmtd.check(tid):
        await gsend(ev, f'您今天已经搜过{DAILY_LIMIT}次图了,休息一下明天再来吧~')
        return
    await gsend(ev, '正在搜索,请稍候~')
    bot = hoshino.get_bot()
    for url in ret:
        asyncio.get_event_loop().create_task(picfinder(bot, ev, url))
Beispiel #18
0
import asyncio
import importlib

from hoshino import Service, priv, sucmd, get_bot
from hoshino.config import twitter as cfg
from hoshino.typing import MessageSegment as CommandSession

sv = Service("twitter-poller", use_priv=priv.SU, manage_priv=priv.SU, visible=False)
bot = get_bot()
daemon = None

from .follow import follow_stream
from .track import track_stream

@bot.on_startup
async def start_daemon():
    global daemon

    loop = asyncio.get_event_loop()
    daemon = loop.create_task(stream_daemon(follow_stream))
    loop.create_task(stream_daemon(track_stream))


async def stream_daemon(stream_func):
    while True:
        try:
            await stream_func()
        except (KeyboardInterrupt, asyncio.CancelledError):
            sv.logger.info("Twitter stream daemon exited.")
            return
        except Exception as e:
Beispiel #19
0
async def gsend(ev: CQEvent, msg):
    hbot = hoshino.get_bot()
    return await hbot.send_guild_channel_msg(guild_id=ev.guild_id,
                                             channel_id=ev.channel_id,
                                             message=msg,
                                             self_id=ev.self_id)
Beispiel #20
0
 def bot(self):
     return hoshino.get_bot()
async def rank_poller():
    bot = hoshino.get_bot()
    await send_rank(bot)