mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-11 04:07:23 +08:00
first commit
This commit is contained in:
commit
d425cf8685
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
plugin
|
4
datapack/liteyuki_default/metadata.json
Normal file
4
datapack/liteyuki_default/metadata.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "Liteyuki Default",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
4
datapack/liteyuki_language/metadata.json
Normal file
4
datapack/liteyuki_language/metadata.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "Liteyuki Language Pack",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
6
main.py
Normal file
6
main.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from src.liteyuki import *
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
liteyuki = Liteyuki()
|
||||||
|
app = liteyuki.get_asgi()
|
||||||
|
liteyuki.run(app="main:app")
|
9
plugins/liteyuki_plugin_hello/__init__.py
Normal file
9
plugins/liteyuki_plugin_hello/__init__.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.rule import to_me
|
||||||
|
|
||||||
|
hello = on_command('hello', aliases={'你好'}, rule=to_me())
|
||||||
|
|
||||||
|
|
||||||
|
@hello.handle()
|
||||||
|
async def handle_first_receive(bot, event, state):
|
||||||
|
await hello.finish('Hello, world!')
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
nonebot2[fastapi]
|
||||||
|
watchdog==2.1.6
|
0
src/api/data.py
Normal file
0
src/api/data.py
Normal file
33
src/api/utils.py
Normal file
33
src/api/utils.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
from nonebot import logger
|
||||||
|
|
||||||
|
|
||||||
|
def load_config() -> dict[str, any]:
|
||||||
|
"""
|
||||||
|
Load config from config.yml
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
config = {
|
||||||
|
'host': '0.0.0.0',
|
||||||
|
'port': 20216,
|
||||||
|
'nickname': ['Liteyuki'],
|
||||||
|
'command_start': [''],
|
||||||
|
}
|
||||||
|
|
||||||
|
if not os.path.exists('config.yml'):
|
||||||
|
logger.warning('warn.config_file_not_found')
|
||||||
|
with open('config.yml', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(yaml.dump(config, indent=4))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
with open('config.yml', 'r', encoding='utf-8') as f:
|
||||||
|
config.update(yaml.load(f, Loader=yaml.FullLoader))
|
||||||
|
logger.success('success.config_loaded')
|
||||||
|
# 格式化后写入
|
||||||
|
with open('config.yml', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(yaml.dump(config, indent=4))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f'error.load_config: {e}')
|
||||||
|
|
||||||
|
return config
|
46
src/liteyuki.py
Normal file
46
src/liteyuki.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from typing import Any, Optional
|
||||||
|
from nonebot import DOTENV_TYPE
|
||||||
|
import nonebot
|
||||||
|
from nonebot import logger
|
||||||
|
from nonebot.adapters.onebot.v11 import Adapter as OnebotV11Adapter
|
||||||
|
from nonebot.adapters.onebot.v12 import Adapter as OnebotV12Adapter
|
||||||
|
|
||||||
|
from src.api.utils import load_config
|
||||||
|
|
||||||
|
app = None
|
||||||
|
adapters = [
|
||||||
|
OnebotV11Adapter,
|
||||||
|
OnebotV12Adapter
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Liteyuki:
|
||||||
|
def __init__(self, *, _env_file: Optional[DOTENV_TYPE] = None, **kwargs: Any):
|
||||||
|
print(
|
||||||
|
'\033[34m' + r''' __ ______ ________ ________ __ __ __ __ __ __ ______
|
||||||
|
/ | / |/ |/ |/ \ / |/ | / |/ | / |/ |
|
||||||
|
$$ | $$$$$$/ $$$$$$$$/ $$$$$$$$/ $$ \ /$$/ $$ | $$ |$$ | /$$/ $$$$$$/
|
||||||
|
$$ | $$ | $$ | $$ |__ $$ \/$$/ $$ | $$ |$$ |/$$/ $$ |
|
||||||
|
$$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |$$ $$< $$ |
|
||||||
|
$$ | $$ | $$ | $$$$$/ $$$$/ $$ | $$ |$$$$$ \ $$ |
|
||||||
|
$$ |_____ _$$ |_ $$ | $$ |_____ $$ | $$ \__$$ |$$ |$$ \ _$$ |_
|
||||||
|
$$ |/ $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |/ $$ |
|
||||||
|
$$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ ''' + '\033[0m'
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs = load_config()
|
||||||
|
self.nonebot = nonebot
|
||||||
|
self.nonebot.init(_env_file=_env_file, **kwargs)
|
||||||
|
self.driver = self.nonebot.get_driver()
|
||||||
|
|
||||||
|
def run(self, *args, **kwargs):
|
||||||
|
for adapter in adapters:
|
||||||
|
self.driver.register_adapter(adapter)
|
||||||
|
self.nonebot.load_plugin('src.liteyuki_main')
|
||||||
|
self.nonebot.load_plugins('src/builtin')
|
||||||
|
self.nonebot.load_plugins('plugins')
|
||||||
|
# Todo: load from database
|
||||||
|
self.nonebot.run(*args, **kwargs)
|
||||||
|
|
||||||
|
def get_asgi(self):
|
||||||
|
return self.nonebot.get_asgi()
|
16
src/liteyuki_main.py
Normal file
16
src/liteyuki_main.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.adapters.onebot.v11.event import MessageEvent
|
||||||
|
from nonebot.permission import SUPERUSER
|
||||||
|
import os
|
||||||
|
folders = ['plugins']
|
||||||
|
for folder in folders:
|
||||||
|
if not os.path.exists(folder):
|
||||||
|
os.makedirs(folder)
|
||||||
|
|
||||||
|
echo = on_command('echo', permission=SUPERUSER, priority=5)
|
||||||
|
|
||||||
|
|
||||||
|
@echo.handle()
|
||||||
|
async def _(event: MessageEvent):
|
||||||
|
print(event.get_message())
|
||||||
|
await echo.finish(event.get_message())
|
Loading…
Reference in New Issue
Block a user