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 khldaemon.api.all import *
# or
# from khldaemon.api.interface import *
# from khldaemon.api.utils import *
# from khldaemon.api.command import *
# from khldaemon.api.types 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')
interface.register_help_messages('!!hello', 'Hello World!')
# register a command
interface.register_command(
Literal('!!hello').runs(lambda src: src.reply('world!'))
)
# 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.info(interface.message.content)
# run when an event is received
async def on_event(interface: EventInterface):
interface.logger.info(interface.event.event_type)
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.1.2.tar.gz
(25.4 kB
view details)
Built Distribution
khldaemon-0.1.2-py3-none-any.whl
(31.8 kB
view details)
File details
Details for the file khldaemon-0.1.2.tar.gz
.
File metadata
- Download URL: khldaemon-0.1.2.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5469267c44179428ed8d4574fd3177cf13924a06e5749d1200b303089bfedaf5 |
|
MD5 | de4d60712afc0422419e3b27d67918df |
|
BLAKE2b-256 | 78bdf2d61d5a248141bf90558d80793134b10332af72a3b3da37e5d619f6c37c |
File details
Details for the file khldaemon-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: khldaemon-0.1.2-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1284e38278ad0e8db961dd2a683a684525bf92e49f050c98338fd2b37fdb8ed1 |
|
MD5 | 02282f0418f616138bf401e26c29d1ab |
|
BLAKE2b-256 | 341d00ac7291a73f1b7938adc587516e92ea24919942470001b5e0ae696995a4 |