Compare commits

..
22 Commits
Author SHA1 Message Date
pythagodzilla 0f0c700d9f submodule 2025-08-04 07:07:17 +01:00
Pyhtagodzilla aaa1ee91ae test 2025-08-03 16:06:35 +08:00
Pyhtagodzilla faf6b39e45 Add Weather as submodule 2025-08-03 15:46:49 +08:00
Pyhtagodzilla 0a938100a8 test 2025-08-03 15:42:50 +08:00
Pyhtagodzilla 37b4cfac9a 加了一言插件 2025-07-31 01:10:26 +08:00
Pyhtagodzilla dd880b49fb Some little changes 2025-07-31 00:51:36 +08:00
pythagodzilla aa824d3257 uv 2025-07-30 17:49:15 +01:00
Pyhtagodzilla 63b97d2d2f 重写了GetFile的解析逻辑。 2025-07-31 00:44:06 +08:00
Pyhtagodzilla 2dc3faaf03 some little changes 2025-07-25 22:36:11 +08:00
Pyhtagodzilla 1da7bc067d some little changes 2025-07-25 22:35:21 +08:00
Pyhtagodzilla cf14fc22c2 some little changes 2025-07-25 22:14:38 +08:00
Pyhtagodzilla a30c3699a1 some little changes 2025-07-25 22:13:16 +08:00
Pyhtagodzilla 29a96bb1ff remove some useless directories 2025-07-25 21:43:45 +08:00
Pyhtagodzilla 89aa8f2bf7 Merge branch 'master' of https://git.bluemangoo.net/pythagodzilla/memebot 2025-07-25 21:37:42 +08:00
Pyhtagodzilla 758fe4b1f0 换了文档推荐的工作方式,并且,为了使用热重载而将一些功能外挂为插件。这些功能并不一定要以插件形式存在。若有必要,可以合并进启动程序。 2025-07-25 21:22:55 +08:00
Pyhtagodzilla 65fa057ab4 换了文档推荐的工作方式,并且,为了使用热重载而将一些功能外挂为插件。这些功能并不一定要以插件形式存在。若有必要,可以合并进启动程序。 2025-07-25 21:22:55 +08:00
Pyhtagodzilla d456805d46 同步 2025-07-20 23:31:42 +08:00
Pyhtagodzilla a3c5ae75d3 同步 2025-07-20 23:31:42 +08:00
Pyhtagodzilla fe244d95b4 Merge remote-tracking branch 'origin/master' 2025-07-20 23:29:25 +08:00
Pyhtagodzilla 58b5dcff73 Merge remote-tracking branch 'origin/master' 2025-07-20 23:29:25 +08:00
Pyhtagodzilla 06266378e1 呃呃重写了解析图片消息的 2025-07-19 11:48:46 +08:00
Pyhtagodzilla 504a472b22 呃呃重写了解析图片消息的 2025-07-19 11:48:46 +08:00
37 changed files with 431 additions and 100 deletions
+4
View File
@@ -1 +1,5 @@
tests
.env
src/data
src/logs
src/config.yaml
+6
View File
@@ -0,0 +1,6 @@
[submodule "src/plugins/Weather"]
path = src/plugins/Weather
url = https://github.com/pythagodzi11a/Weather.git
[submodule "src/plugins/YiYanAPI"]
path = src/plugins/YiYanAPI
url = https://github.com/pythagodzi11a/YiYanAPI
+1
View File
@@ -0,0 +1 @@
3.13
+12 -6
View File
@@ -3,17 +3,23 @@
---
由于一上来就采用了远程开发的模式,所以在bot连接的过程中,需要在 ```bot.run()``` 函数中另外传入参数
```python
bot.run(
bt_uin = "bot account",
root = "bot's master account",
ws_uri = "ws://",
ws_token = "Your token",
webui_uri = "http://Your server:port",
webui_token = "Your token"
bt_uin="bot account",
root="bot's master account",
ws_uri="ws://",
ws_token="Your token",
webui_uri="http://Your server:port",
webui_token="Your token"
)
```
具体的信息在 [配置项文档](https://docs.ncatbot.xyz/guide/kfcvme50/#%E9%85%8D%E7%BD%AE%E9%A1%B9%E5%88%97%E8%A1%A8) 中提及。
一些报错是由于webui的token所导致的,默认值为napcat,另外连接都需要带上协议,例如连接webui时需要带上 ```http://```
---
官方文档已经给出了解析消息的示例,但是我仍然使用了raw_message来手动解析消息。我觉得这个锅要甩***1/3***给文档,
---
+5
View File
@@ -0,0 +1,5 @@
requests~=2.32.4
ncatbot~=3.8.8.post7
dotenv~=0.9.9
python-dotenv~=1.1.1
sqlmodel~=0.0.24
+6
View File
@@ -0,0 +1,6 @@
BOT_ACCOUNT="Your-bot-account"
ROOT_ACCOUNT="Your-root-account"
WS_URI="ws://Your-uri:port"
WS_TOKEN="Your-token"
WEBUI_URI="http://Your-uri:port"
WEBUI_TOKEN="Your-token
View File
+32
View File
@@ -0,0 +1,32 @@
import time
import os
from dotenv import load_dotenv
from ncatbot.core import BotClient, GroupMessage, PrivateMessage
from ncatbot.utils import get_log
load_dotenv(dotenv_path=r".env")
bot = BotClient()
_log = get_log()
@bot.group_event()
async def on_receive_group_message(msg: GroupMessage):
_log.info(f"The message's meta data is: {str(msg)}")
_log.info(f"The message's raw message is: {msg.raw_message}")
@bot.private_event()
async def on_receive_private_event(msg: PrivateMessage):
_log.info(f"The message's meta data is: {str(msg)}")
_log.info(f"The message's raw message is: {msg.raw_message}")
bot.run(
bt_uin=os.getenv("BOT_ACCOUNT"),
root=os.getenv("ROOT_ACCOUNT"),
ws_uri=os.getenv("WS_URI"),
ws_token=os.getenv("WS_TOKEN"),
webui_uri=os.getenv("WEBUI_URI"),
webui_token=os.getenv("WEBUI_TOKEN")
)
-92
View File
@@ -1,92 +0,0 @@
from ncatbot.core import BotClient, GroupMessage, PrivateMessage
# from ncatbot.core import (MessageChain, Text, Image)
from ncatbot.utils import get_log
import requests
bot = BotClient()
_log = get_log()
@bot.private_event()
async def on_receive_images_private_event(msg: PrivateMessage):
_log.info(msg)
if "url=https://" not in msg.raw_message:
return
else:
try:
file_name = msg.raw_message.split(",")[1].split("=")[1]
image_url = await bot.api.get_image(file_name)
real_url = image_url['data']['url']
except IndexError as e:
_log.debug(e)
real_url = "None"
file_name = "None"
except TypeError as e:
_log.debug(e)
real_url = "None"
file_name = "None"
if real_url == "None":
return
else:
response = requests.get(real_url)
img = response.content
with open(f"data/pics/{file_name}", 'wb') as f:
f.write(img)
# file_name = msg.raw_message.split(",")[1].split("=")[1]
# image_url = await bot.api.get_image(file_name)
# real_url = image_url['data']['url']
#
# _log.debug(f"image's real url: {real_url}")
#
# try:
# response = requests.get(real_url)
# img = response.content
# with open(f"data/pics/{file_name}", 'wb') as f:
# f.write(img)
# except Exception as e:
# _log.error(e)
# pass
@bot.group_event()
async def on_receive_images_group_event(msg: GroupMessage):
_log.info(msg)
if "url=https://" not in msg.raw_message:
return
else:
try:
file_name = msg.raw_message.split(",")[1].split("=")[1]
image_url = await bot.api.get_image(file_name)
real_url = image_url['data']['url']
except IndexError as e:
_log.debug(e)
real_url = "None"
file_name = "None"
except TypeError as e:
_log.debug(e)
real_url = "None"
file_name = "None"
if real_url == "None":
return
else:
response = requests.get(real_url)
img = response.content
with open(f"data/pics/{file_name}", 'wb') as f:
f.write(img)
if __name__ == "__main__":
api = bot.run(
bt_uin="203758258",
root="1670671958",
ws_uri="ws://192.168.10.78:3001",
ws_token="",
webui_uri="http://192.168.10.78:6099",
webui_token="@Jtbx2mtblj"
)
+4
View File
@@ -0,0 +1,4 @@
# DataBase
> 用于开发功能而做的插件。只是为了便于重载和测试。
用于和数据库进行交互。
+3
View File
@@ -0,0 +1,3 @@
from .dataBase import DataBase
__all__ = ['DataBase']
+16
View File
@@ -0,0 +1,16 @@
from sqlmodel import SQLModel, Session, select, create_engine
from ncatbot.plugin import BasePlugin, CompatibleEnrollment
from ncatbot.utils import get_log
bot = CompatibleEnrollment()
_log = get_log()
class Data(SQLModel, table=True):
__tablename__ = 'file'
class DataBase(BasePlugin):
name = "DataBase"
version = "0.0.1"
author = "pythagodzilla"
info = "A plugin to control data base."
+4
View File
@@ -0,0 +1,4 @@
ncatbot~=3.8.8.post7
dotenv~=0.9.9
python-dotenv~=1.1.1
sqlmodel~=0.0.24
+6
View File
@@ -0,0 +1,6 @@
# GetFile
> 用于开发功能而做的插件。只是为了便于重载和测试。
用来保存所有的照片和视频的插件。
> **特殊说明**: 这个插件编写的时间略早,所以消息解析使用了一个极为不成熟的方法。不推荐再做更改。
+3
View File
@@ -0,0 +1,3 @@
from .get_file import GetFile
__all__ = ['GetFile']
+102
View File
@@ -0,0 +1,102 @@
from ncatbot.core import BotClient, GroupMessage, PrivateMessage
from ncatbot.utils import get_log
from ncatbot.plugin import BasePlugin, CompatibleEnrollment
from dotenv import load_dotenv
import requests
import os
# bot = BotClient()
bot = CompatibleEnrollment
_log = get_log()
class GetFile(BasePlugin):
name = "GetFile"
version = "0.0.1"
author = "pythagodzilla"
info = "A plugin to get images and videos"
async def on_load(self):
_log.info(f"Plugin {self.name} loaded! ")
@bot.private_event()
async def on_receive_images_private_event(self, msg: PrivateMessage):
if msg.message[0]["type"] == "image":
file_name = msg.message[0]["data"]["file"]
_log.info(f"Name of the image is: {file_name}")
image_url = await self.api.get_image(file_name)
_log.info(f"Image's information collected by \"get_image\" is: {image_url}")
real_url = image_url['data']['url']
_log.info(f"Image's real url is: {real_url}")
response = requests.get(real_url)
img = response.content
with open(f"../data/pics/{file_name}", 'wb') as f:
f.write(img)
@bot.group_event()
async def on_receive_images_group_event(self, msg: GroupMessage):
if msg.message[0]["type"] == "image":
file_name = msg.message[0]["data"]["file"]
_log.info(f"Name of the image is: {file_name}")
image_url = await self.api.get_image(file_name)
_log.info(f"Image's information collected by \"get_image\" is: {image_url}")
real_url = image_url['data']['url']
_log.info(f"Image's real url is: {real_url}")
response = requests.get(real_url)
img = response.content
with open(f"../data/pics/{file_name}", 'wb') as f:
f.write(img)
@bot.group_event()
async def on_receive_videos_group_event(self, msg: GroupMessage):
if msg.message[0]["type"] == "video":
file_name = msg.message[0]["data"]["file"]
_log.info(f"Name of the video is: {file_name}")
video_url = await self.api.get_file(file_name)
_log.info(f"Video's information collected by \"get_video\" is: {video_url}")
real_url = video_url['data']['url']
_log.info(f"Video's real url is: {real_url}")
response = requests.get(real_url)
video = response.content
with open(f"../data/videos/{file_name}", 'wb') as f:
f.write(video)
@bot.private_event()
async def on_receive_videos_private_event(self, msg: PrivateMessage):
if msg.message[0]["type"] == "video":
file_name = msg.message[0]["data"]["file"]
_log.info(f"Name of the video is: {file_name}")
video_url = await self.api.get_file(file_name)
_log.info(f"Video's information collected by \"get_video\" is: {video_url}")
real_url = video_url['data']['url']
_log.info(f"Video's real url is: {real_url}")
response = requests.get(real_url)
video = response.content
with open(f"../data/videos/{file_name}", 'wb') as f:
f.write(video)
"""
当单独运行这个程序时,会连接napcat并保存图片和视频到本地。
"""
if __name__ == "__main__":
load_dotenv(dotenv_path=r"../../../.env")
bot = BotClient()
api = bot.run(
bt_uin=os.getenv("BOT_ACCOUNT"),
root=os.getenv("ROOT_ACCOUNT"),
ws_uri=os.getenv("WS_URI"),
ws_token=os.getenv("WS_TOKEN"),
webui_uri=os.getenv("WEBUI_URI"),
webui_token=os.getenv("WEBUI_TOKEN")
)
+3
View File
@@ -0,0 +1,3 @@
ncatbot~=3.8.8.post7
dotenv~=0.9.9
python-dotenv~=1.1.1
+35
View File
@@ -0,0 +1,35 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Virtual Environment
venv/
ENV/
# IDE
.idea/
.vscode/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
+33
View File
@@ -0,0 +1,33 @@
# Memigo 插件
## 简介
这是一个 NcatBot 插件模板。
## 功能
- 群消息事件处理
- 好友消息事件处理
- 测试功能 (/test)
## 使用方法
1. 在群聊中发送 "测试" 消息
2. 在私聊中发送 "测试" 消息
3. 使用 `/test` 命令测试功能
## 配置项
- `greeting`: 问候语,默认值为 "你好",可选值: ["你好", "Hello", "Hi"]
## 依赖
- NcatBot
## 作者
Your Name
## 许可证
MIT
+3
View File
@@ -0,0 +1,3 @@
from .main import Memigo
__all__ = ["Memigo"]
+28
View File
@@ -0,0 +1,28 @@
import os
from sqlmodel import Field, SQLModel, create_engine
from dotenv import load_dotenv
from pathlib import Path
load_dotenv("../../.env")
class ConnectDatabase(SQLModel, table=True):
__tablename__ = 'BasicInformation'
id: int | None = Field(primary_key=True)
fileName: str | None
includedText: str | None
imageContent: str | None
memeKind: str | None
database_path = Path(os.getenv("DATA_PATH")) / "DataBase" / "data.db"
# if not database_path.exists():
# engine = create_engine(f"sqlite:///{database_path}")
#
# else:
# engine = create_engine(f"sqlite:///{database_path}")
# SQLModel.metadata.create_all(engine)
engine = create_engine(f"sqlite:///{database_path}")
SQLModel.metadata.create_all(engine)
+18
View File
@@ -0,0 +1,18 @@
import os
from ncatbot.plugin import BasePlugin, CompatibleEnrollment
from ncatbot.core import GroupMessage, PrivateMessage, BaseMessage
from ncatbot.utils import get_log
bot = CompatibleEnrollment # 兼容回调函数注册器
_log = get_log()
class Memigo(BasePlugin):
name = "Memigo" # 插件名称
version = "0.0.1" # 插件版本
author = "pythagodzilla" # 插件作者
info = "你的meme分类好伙伴" # 插件描述
@bot.startup_event()
async def startup(self):
_log.info("Plugin Memigo has started up! ")
+7
View File
@@ -0,0 +1,7 @@
# 插件依赖项
# 例如: requests==2.28.1
ncatbot~=3.8.8.post7
sqlmodel~=0.0.24
dotenv~=0.9.9
python-dotenv~=1.1.1
+35
View File
@@ -0,0 +1,35 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Virtual Environment
venv/
ENV/
# IDE
.idea/
.vscode/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
+33
View File
@@ -0,0 +1,33 @@
# Test 插件
## 简介
这是一个 NcatBot 插件模板。
## 功能
- 群消息事件处理
- 好友消息事件处理
- 测试功能 (/test)
## 使用方法
1. 在群聊中发送 "测试" 消息
2. 在私聊中发送 "测试" 消息
3. 使用 `/test` 命令测试功能
## 配置项
- `greeting`: 问候语,默认值为 "你好",可选值: ["你好", "Hello", "Hi"]
## 依赖
- NcatBot
## 作者
Your Name
## 许可证
MIT
+3
View File
@@ -0,0 +1,3 @@
from .main import Test
__all__ = ["Test"]
+23
View File
@@ -0,0 +1,23 @@
from ncatbot.core import PrivateMessage
from ncatbot.plugin import BasePlugin, CompatibleEnrollment
from ncatbot.utils import get_log
bot = CompatibleEnrollment # 兼容回调函数注册器
_log = get_log()
class Test(BasePlugin):
name = "Test" # 插件名称
version = "0.0.1" # 插件版本
author = "Your Name" # 插件作者
info = "这是一个示例插件,用于演示插件系统的基本功能" # 插件描述
dependencies = {} # 插件依赖,格式: {"插件名": "版本要求"}
# @bot.private_event()
# async def test_unzip(self, msg: PrivateMessage):
# _log.info(f"{msg.message[0]["type"]}")
@bot.private_event()
async def on_receive_images_private_event(self, msg: PrivateMessage):
if msg.message[0]["type"] == "image":
file_name = msg.message[0]["data"]["file"]
_log.warning(f"{file_name}")
+2
View File
@@ -0,0 +1,2 @@
# 插件依赖项
# 例如: requests==2.28.1
Submodule src/plugins/Weather added at 6d2b885b7b
Binary file not shown.
Binary file not shown.
Binary file not shown.