| import os |
| import re |
| from dotenv import load_dotenv |
|
|
| |
| load_dotenv() |
|
|
| import nonebot |
| from nonebot.adapters.qq import Adapter as QQAdapter |
| from nonebot.adapters.qq.message import Message, MessageSegment |
|
|
| |
| URL_REGEX = re.compile( |
| r"(http|https)://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(/[a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~]*)?" |
| ) |
|
|
| |
| |
| |
| nonebot.init( |
| driver="~fastapi+~httpx+~websockets", |
| qq_is_sandbox=True, |
| orm_upgrade_on_start=True, |
| qq_bots=[ |
| { |
| "id": os.getenv("QQ_APP_ID"), |
| "token": os.getenv("QQ_TOKEN"), |
| "secret": os.getenv("QQ_SECRET"), |
| |
| "intent": { |
| "c2c_group_at_messages": True, |
| "direct_message": True, |
| "at_messages": True, |
| "guild_messages": True, |
| }, |
| } |
| ], |
| ) |
|
|
| |
| driver = nonebot.get_driver() |
| driver.register_adapter(QQAdapter) |
|
|
| from nonebot.adapters import Bot |
|
|
| |
| @Bot.on_calling_api |
| async def handle_api_call(bot, api, data): |
| |
| if api in ["post_group_messages", "post_c2c_messages", "post_messages"]: |
| if "content" in data and isinstance(data["content"], str): |
| |
| data["content"] = URL_REGEX.sub("", data["content"]) |
| |
| if "message" in data: |
| msg = data["message"] |
| if isinstance(msg, str): |
| data["message"] = URL_REGEX.sub("", msg) |
|
|
|
|
| |
| nonebot.load_builtin_plugins("echo") |
|
|
| |
| nonebot.load_plugin("nonebot_plugin_skland") |
| nonebot.load_plugin("haruka_bot") |
|
|
| |
| nonebot.load_plugin("src.plugins.order_notifier") |
|
|
| if __name__ == "__main__": |
| |
| nonebot.run(host="0.0.0.0", port=7860) |
|
|