Example #1
0
def _load_config(services_config):
    for sv_config in services_config:
        sv.logger.debug(sv_config)
        service_name = sv_config["service_name"]
        enable_on_default = sv_config.get("enable_on_default", False)
        broadcast_tag = sv_config.get("broadcast_tag", BroadcastTag.default)

        users_config = sv_config["users"]

        sv_spider_list = []
        for user_config in users_config:
            wb_spider = WeiboSpider(user_config)
            sv_spider_list.append(wb_spider)
            alias_list = user_config.get("alias", [])
            for alias in alias_list:
                if alias in alias_dic:
                    raise DuplicateError(f"Alias {alias} is duplicate")
                alias_dic[alias] = {
                    "service_name": service_name,
                    "user_id": wb_spider.get_user_id()
                }

        subService = BroadcastService(service_name,
                                      broadcast_tag=broadcast_tag,
                                      enable_on_default=enable_on_default)
        subr_dic[service_name] = {
            "service": subService,
            "spiders": sv_spider_list
        }
Example #2
0
async def lsbcsv(bot: KokkoroBot, ev: EventInterface):
    parser = ArgumentParser()
    parser.add_argument('-a', '--all', action='store_true')
    parser.add_argument('-i', '--invisible', action='store_true')
    parser.add_argument('-g', '--group', type=int, default=0)
    args = parser.parse_args(ev.get_param().remain)

    verbose_all = args.all
    only_hidden = args.invisible
    if ev.get_author_id() in bot.config.SUPER_USER:
        gid = args.group or ev.get_group_id()
        if not gid:
            await bot.kkr_send(ev, 'Usage: -g|--group <group_id> [-a|--all]')
            return
    else:
        gid = ev.get_group_id()

    msg = svs_to_msg(BroadcastService.get_loaded_bc_services().values(),
                     gid,
                     verbose_all,
                     only_hidden,
                     bc=True)
    await bot.kkr_send(ev, msg)
Example #3
0
import os
import re
import random
import asyncio
from urllib.parse import urljoin, urlparse, parse_qs
try:
    import ujson as json
except:
    import json

from kokkoro import aiorequests, R
from kokkoro.service import BroadcastService, BroadcastTag
from kokkoro.common_interface import KokkoroBot, EventInterface

sv = BroadcastService('pcr-comic', broadcast_tag=BroadcastTag.jp_broadcast)


def load_index():
    with open(R.get('img/priconne/comic/index.json').path,
              encoding='utf8') as f:
        return json.load(f)


def get_pic_name(id_):
    pre = 'episode_'
    end = '.png'
    return f'{pre}{id_}{end}'


@sv.on_prefix('官漫')
async def comic(bot: KokkoroBot, ev: EventInterface):
from kokkoro.service import BroadcastTag, BroadcastService

sv9 = BroadcastService('pcr-arena-reminder-utc9',
    broadcast_tag=[BroadcastTag.cn_broadcast, BroadcastTag.tw_broadcast],
    enable_on_default=False, help_='背刺时间提醒(UTC+9)')

sv8 = BroadcastService('pcr-arena-reminder-utc8',
    broadcast_tag=BroadcastTag.jp_broadcast,
    enable_on_default=False, help_='背刺时间提醒(UTC+8)')

msg = '主さま、准备好背刺了吗?'

@sv8.scheduled_job('cron', hour='14', minute='45', misfire_grace_time=60*10)
async def pcr_reminder_utc8():
    await sv8.broadcast(msg)

@sv9.scheduled_job('cron', hour='13', minute='45', misfire_grace_time=60*10)
async def pcr_reminder_utc9():
    await sv9.broadcast(msg)
from kokkoro.service import BroadcastTag, BroadcastService
from kokkoro import R

sv9 = BroadcastService('pcr-portion-reminder-utc9',
                       broadcast_tag=BroadcastTag.jp_broadcast,
                       enable_on_default=False,
                       help_='药水购买小助手(UTC+9)')

sv8 = BroadcastService(
    'pcr-portion-reminder-utc8',
    broadcast_tag=[BroadcastTag.cn_broadcast, BroadcastTag.tw_broadcast],
    enable_on_default=False,
    help_='药水购买小助手(UTC+8)')

img = R.img('提醒药水小助手.jpg')


@sv8.scheduled_job('cron', hour='0,6,12,18', misfire_grace_time=60 * 10)
async def pcr_portion_reminder_utc8():
    await sv8.broadcast(img)


@sv9.scheduled_job('cron', hour='23,5,11,17', misfire_grace_time=60 * 10)
async def pcr_portion_reminder_utc9():
    await sv9.broadcast(img)
from kokkoro.service import BroadcastService, BroadcastTag
from kokkoro import priv
from kokkoro.common_interface import KokkoroBot, EventInterface

sv = BroadcastService('su-broadcast', broadcast_tag=BroadcastTag.default, use_priv=priv.SUPERUSER, manage_priv=priv.SUPERUSER, enable_on_default=True, visible=False)

@sv.on_prefix(('广播', 'bc', 'broadcast'))
async def broadcast(bot: KokkoroBot, ev: EventInterface):
    msg = ev.get_param().remain
    await sv.broadcast(msg)
Example #7
0
import asyncio
from kokkoro.service import Service, BroadcastTag, BroadcastService
from .spider import *

svtw = BroadcastService('pcr-news-tw', broadcast_tag=BroadcastTag.tw_broadcast, help_='台服官网新闻')
svbl = BroadcastService('pcr-news-bili', broadcast_tag=BroadcastTag.cn_broadcast, help_='B服官网新闻')

async def news_poller(spider:BaseSpider, sv:Service, LOG_TAG, send=True):
    if not spider.item_cache:
        await spider.get_update()
        sv.logger.info(f'{LOG_TAG}新闻缓存为空,已加载至最新')
        return
    news = await spider.get_update()
    if not news:
        sv.logger.info(f'未检索到{LOG_TAG}新闻更新')
        return
    sv.logger.info(f'检索到{len(news)}条{LOG_TAG}新闻更新!')
    if send:
        await sv.broadcast(spider.format_items(news))

async def _async_init():
    await news_poller(BiliAllSpider, svbl, 'B服官网')

#asyncio.run(_async_init())

@svtw.scheduled_job('cron', minute='*/20', jitter=20)
async def sonet_news_poller():
    await news_poller(SonetSpider, svtw, '台服官网')

@svbl.scheduled_job('cron', minute='*/20', jitter=20)
async def bili_news_poller():