예제 #1
0
    def __init__(self, name, use_priv=None, manage_priv=None, enable_on_default=None, visible=None,
                 help_=None):
        """
        定义一个服务
        配置的优先级别:配置文件 > 程序指定 > 缺省值
        """
        #assert not _re_illegal_char.search(name), r'Service name cannot contain character in `\/:*?"<>|.`'

        config = _load_service_config(name)
        self.name = name
        self.use_priv = config.get('use_priv') or use_priv or priv.NORMAL
        self.manage_priv = config.get('manage_priv') or manage_priv or priv.SUPERUSER
        self.enable_on_default = config.get('enable_on_default')
        if self.enable_on_default is None:
            self.enable_on_default = enable_on_default
        if self.enable_on_default is None:
            self.enable_on_default = True
        self.visible = config.get('visible')
        if self.visible is None:
            self.visible = visible
        if self.visible is None:
            self.visible = True
        self.help = help_
        self.enable_group = set(config.get('enable_group', []))
        self.disable_group = set(config.get('disable_group', []))

        self.logger = log.new_logger(name)

        assert self.name not in _loaded_services, f'Service name "{self.name}" already exist!'
        _loaded_services[self.name] = self
예제 #2
0
    def __init__(self, name, use_priv=None, manage_priv=None, broadcast_tag=None, enable_on_default=None, visible=None,
                 help_=None):
        """
        定义一个服务
        配置的优先级别:配置文件 > 程序指定 > 缺省值
        """
        #assert not _re_illegal_char.search(name), r'Service name cannot contain character in `\/:*?"<>|.`'

        config = _load_service_config(name)
        self._loaded_config = config # for sub-class init
        self.name = name
        self.use_priv = config.get('use_priv') or use_priv or priv.NORMAL
        self.manage_priv = config.get('manage_priv') or manage_priv or priv.ADMIN
        self.enable_on_default = config.get('enable_on_default')
        self.broadcast_tag = config.get('broadcast_tag') or broadcast_tag or BroadcastTag.default # default tag for  group bc tag
        if isinstance(self.broadcast_tag, str):
            self.broadcast_tag = [self.broadcast_tag]
        if self.enable_on_default is None:
            self.enable_on_default = enable_on_default
        if self.enable_on_default is None:
            self.enable_on_default = True
        self.visible = config.get('visible')
        if self.visible is None:
            self.visible = visible
        if self.visible is None:
            self.visible = True
        self.help = help_
        self.enable_group = set(config.get('enable_group', []))
        self.disable_group = set(config.get('disable_group', []))

        self.logger = log.new_logger(name)

        assert self.name not in _loaded_services, f'Service name "{self.name}" already exist!'
        _loaded_services[self.name] = self
import importlib
from kokkoro import log

logger = log.new_logger('config')

BOT_TYPE = "discord"
ENABLE_WEB = False

try:
    platform_config = importlib.import_module('kokkoro.config.bot.' + BOT_TYPE)
    logger.info(f'Succeeded to load config of "{BOT_TYPE}"')
except ModuleNotFoundError as e:
    logger.error(f'Not found config of "{BOT_TYPE}"')
    raise e

BOT_ID = platform_config.BOT_ID
SUPER_USER = platform_config.SUPER_USER
ENABLED_GROUP = platform_config.ENABLED_GROUP

DEFAULT_BROADCAST_TAG = "broadcast"

LOG_LEVEL = "DEBUG"

NICK_NAME = ['可可萝', '妈', 'kkr', 'kokkoro']

RES_PROTOCOL = 'file'
RES_DIR = '~/.kokkoro/res/'
RES_URL = '0.0.0.0'


def get_font_path(font_file):
예제 #4
0
import importlib
import pygtrie
from fuzzywuzzy import fuzz, process
from PIL import Image
from io import BytesIO
import requests

from kokkoro import R, log, util

from . import _pcr_data

logger = log.new_logger('chara')
UNKNOWN = 1000
UnavailableChara = {
    1067,  # 穗希
    1069,  # 霸瞳
    1072,  # 可萝爹
    1073,  # 拉基拉基
    1102,  # 泳装大眼
}

try:
    gadget_equip = R.img('priconne/gadget/equip.png').open()
    gadget_star = R.img('priconne/gadget/star.png').open()
    gadget_star_dis = R.img('priconne/gadget/star_disabled.png').open()
    gadget_star_pink = R.img('priconne/gadget/star_pink.png').open()
    unknown_chara_icon = R.img(
        f'priconne/unit/icon_unit_{UNKNOWN}31.png').open()
except Exception as e:
    logger.exception(e)
예제 #5
0
import os
import discord
from PIL import Image
from io import BytesIO
from typing import Union

from kokkoro import log, config
logger = log.new_logger('KokkoroBot', config.LOG_LEVEL)

import kokkoro
from kokkoro.msg_handler import handle_message
from kokkoro import util
from kokkoro.discord_adaptor import DiscordImage, DiscordEvent
from kokkoro.R import ResImg, RemoteResImg


class KokkoroBot(discord.Client):
    def __init__(self, config):
        super().__init__()
        self.config = config

        for module_name in self.config.MODULES_ON:
            util.load_modules(
                os.path.join(os.path.dirname(__file__), 'modules',
                             module_name), f'kokkoro.modules.{module_name}')

    async def on_ready(self):
        kokkoro.logger.info(f'Logged on as {self.user}')

    async def on_message(self, message):
        # don't respond to ourselves