Plugin system based on khl.py
Project description
KHLDaemon
安装
使用命令 pip install khldaemon
来安装
使用
使用命令 python -m khldaemon init
来初始化机器人
将会生成 plugin
config
文件夹,以及 config.yml
配置文件
修改配置文件,填上你的开黑啦机器人的 token
然后使用命令 python -m khldaemon start
启动机器人
样例插件
from khl import Message
from khldaemon.api.all import *
# or
# from khldaemon.api.interface import *
# from khldaemon.api.utils import *
# plugin meta
PLUGIN_METADATA = {
'id': 'test_plugin',
'version': '1.0.0',
'name': 'Test Plugin',
'description': 'A test plugin',
'author': 'DancingSnow',
'link': 'https://github.com/DancingSnow0517/'
}
class Config(Serializable):
config1: str = 'c1'
config2: str = 'c1'
config3: bool = False
config: Config
# run when bot start
def on_load(interface: PluginInterface):
global config
interface.logger.info('plugin loaded')
bot = interface.bot
@bot.command(name='test')
async def test(msg: Message):
await msg.reply('test')
# config interface
config = interface.load_config_simple(file_name='test_config.json', target_class=Config, in_data_folder=True)
config.config1 = 't'
interface.save_config_simple(config=config, file_name='test_config.json', in_data_folder=True)
# run when bot stop
def on_unload(interface: PluginInterface):
interface.logger.info('plugin unloaded')
# run when a message is received
async def on_message(interface: MessageInterface):
interface.logger(interface.message.content)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
khldaemon-0.0.7.tar.gz
(15.5 kB
view hashes)
Built Distribution
khldaemon-0.0.7-py3-none-any.whl
(18.6 kB
view hashes)
Close
Hashes for khldaemon-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2510db7c8757f2ab919c1f1e642b304f71b929c8429d180f26c1e704f35df2 |
|
MD5 | 4ad82d635c559a0cbf776f4db8c52b79 |
|
BLAKE2b-256 | 56cad13c918570190b3ebba4724311dea05487edca78b83560e06254f3883fce |