Exemplo n.º 1
0
async def start_check_weekly(app):
    @scheduler.schedule(crontabify('30 8 * * MON'))
    async def check_weekly():
        logger_info('Checking MCWZH weekly...')
        result = json.loads(await get_url(
            'https://minecraft.fandom.com/zh/api.php?action=parse&page=Minecraft_Wiki/weekly&prop=text|revid&format=json'
        ))
        html = result['parse']['text']['*']
        text = re.sub(r'<p>', '\n', html)  # 分段
        text = re.sub(r'<(.*?)>', '', text, flags=re.DOTALL)  # 移除所有 HTML 标签
        text = re.sub(r'\n\n\n', '\n\n', text)  # 移除不必要的空行
        text = re.sub(r'\n*$', '', text)
        img = re.findall(
            r'(?<=src=")(.*?)(?=/revision/latest/scale-to-(width|height)-down/\d{3}\?cb=\d{14}?")',
            html)
        page = re.findall(r'(?<=<b><a href=").*?(?=")', html)
        sended_img = Image.fromNetworkAddress(
            img[0][0]) if img else Plain('\n(发生错误:图片获取失败)')
        msg = '发生错误:本周页面已过期,请联系中文 Minecraft Wiki 更新。' if page[0] == '/zh/wiki/%E7%8E%BB%E7%92%83' else '本周的每周页面:\n\n' + text + '\n图片:' + \
                                                                                                      img[0][
                                                                                                          0] + '?format=original\n\n页面链接:https://minecraft.fandom.com' + \
                                                                                                      page[
                                                                                                          0] + '\n每周页面:https://minecraft.fandom.com/zh/wiki/?oldid=' + str(
        result['parse']['revid'])
        chain = MessageChain.create([Plain(msg), sended_img])
        for qqgroup in check_enable_modules_all('group_permission',
                                                'weekly_rss'):
            try:
                await app.sendGroupMessage(int(qqgroup), chain)
                await asyncio.sleep(0.5)
            except Exception:
                traceback.print_exc()

        for qqfriend in check_enable_modules_all('friend_permission',
                                                 'weekly_rss'):
            try:
                await app.sendFriendMessage(int(qqfriend), chain)
                await asyncio.sleep(0.5)
            except Exception:
                traceback.print_exc()

        logger_info(msg)
        logger_info('Weekly checked.')
Exemplo n.º 2
0
                group_repeat[group.id]["thisMsg"] = msg[1].asDisplay()
                lock.release()
        elif len(message) > 1 and message[0] == "bizhi*":
            for _ in range(message[1]):
                msg = await get_pic("bizhi", group.id, message_info.sender.id)
                await app.sendGroupMessage(group, msg[1])
                lock.acquire()
                group_repeat[group.id]["lastMsg"] = group_repeat[group.id]["thisMsg"]
                group_repeat[group.id]["thisMsg"] = msg[1].asDisplay()
                lock.release()
    except AccountMuted:
        pass


# 定时任务
@sche.schedule(timers.crontabify("30 22 * * *"))
async def declare_dragon():
    groups = await app.groupList()
    print(groups)
    for i in groups:
        print(i.id)
        if await get_setting(i.id, "setu") or await get_setting(i.id, "real"):
            msg = await get_dragon_king(i.id, app)
            await update_dragon_data(i.id, 0, "all")
            print(msg)
            try:
                await app.sendGroupMessage(i.id, msg)
            except AccountMuted:
                pass

Exemplo n.º 3
0
from sagiri_bot.utils import group_setting
from sagiri_bot.orm.async_orm import Setting
from sagiri_bot.core.app_core import AppCore

saya = Saya.current()
channel = Channel.current()
host_qq = AppCore.get_core_instance().get_config().host_qq

channel.name("DailyNewspaper")
channel.author("SAGIRI-kawaii")
channel.description("一个定时发送每日日报的插件\n"
                    "主人私聊bot发送 `发送早报` 可在群中发送早报\n"
                    "在群中发送 `今日早报` 可在群中发送早报")


@channel.use(SchedulerSchema(crontabify("30 8 * * *")))
async def something_scheduled(app: Ariadne):
    await send_newspaper(app)


@channel.use(
    ListenerSchema(listening_events=[FriendMessage],
                   inline_dispatchers=[Twilight([FullMatch("发送早报")])]))
async def main(app: Ariadne, friend: Friend):
    if not friend.id == host_qq:
        return None
    await send_newspaper(app)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
Exemplo n.º 4
0
bcc = saya.broadcast
channel = Channel.current()

_report_sleep = "0 0 * * *"
_report_wake_up = "30 7 * * *"
# _report_arknights_jiaomie = "5 12 * * 0"

_go_to_sleep_img_path = "./modules/TimeAnnouncement/快去睡觉.png"
_voice_wake_up_path = "./modules/TimeAnnouncement/wake-the-fxxk-up_.silk"

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:\n\u3000{__usage__}")
channel.author(__author__)


@channel.use(SchedulerSchema(timer=crontabify(_report_wake_up)))
async def wake_up(app: GraiaMiraiApplication):
    group_list = await app.groupList()
    for group in group_list:
        await app.sendGroupMessage(group.id,
                                   MessageChain.create([Plain("七点半辣!!")]))
        await app.sendGroupMessage(
            group.id,
            MessageChain.create([Voice().fromLocalFile(_voice_wake_up_path)]))


@channel.use(SchedulerSchema(timer=crontabify(_report_sleep)))
async def sleep_time(app: GraiaMiraiApplication):
    group_list = await app.groupList()
    for group in group_list:
        await app.sendGroupMessage(
Exemplo n.º 5
0
__description__ = "#  每日新闻"
__author__ = "KuTaKe"
__usage__ = "每天九点半触发\n\u3000手动获取:'今日新闻'"

_report_news = "30 9 * * *"

saya = Saya.current()
bcc = saya.broadcast
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:\n\u3000{__usage__}")
channel.author(__author__)


@channel.use(SchedulerSchema(timer=crontabify(_report_news)))
async def auto_send_news(app: GraiaMiraiApplication):
    await news.update()
    if news.is_update:
        group_list = await app.groupList()
        for group in group_list:
            await app.sendGroupMessage(
                group.id,
                MessageChain.create([Image.fromUnsafeBytes(news.img_bytes)]))
        await app.sendFriendMessage(
            master_id,
            MessageChain.create([Image.fromUnsafeBytes(news.img_bytes)]))


@channel.use(SchedulerSchema(timer=every_custom_hours(5)))
async def check_news_update(app: GraiaMiraiApplication):