Compare commits
18
Commits
65fa057ab4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f0c700d9f | ||
|
|
aaa1ee91ae | ||
|
|
faf6b39e45 | ||
|
|
0a938100a8 | ||
|
|
37b4cfac9a | ||
|
|
dd880b49fb | ||
|
|
aa824d3257 | ||
|
|
63b97d2d2f | ||
|
|
2dc3faaf03 | ||
|
|
1da7bc067d | ||
|
|
cf14fc22c2 | ||
|
|
a30c3699a1 | ||
|
|
29a96bb1ff | ||
|
|
89aa8f2bf7 | ||
|
|
758fe4b1f0 | ||
|
|
d456805d46 | ||
|
|
fe244d95b4 | ||
|
|
06266378e1 |
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
tests
|
tests
|
||||||
.env
|
.env
|
||||||
src/data/pics
|
src/data
|
||||||
src/logs
|
src/logs
|
||||||
|
src/config.yaml
|
||||||
|
|||||||
@@ -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
|
||||||
Executable
+1
@@ -0,0 +1 @@
|
|||||||
|
3.13
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
由于一上来就采用了远程开发的模式,所以在bot连接的过程中,需要在 ```bot.run()``` 函数中另外传入参数
|
由于一上来就采用了远程开发的模式,所以在bot连接的过程中,需要在 ```bot.run()``` 函数中另外传入参数
|
||||||
|
|
||||||
```python
|
```python
|
||||||
bot.run(
|
bot.run(
|
||||||
bt_uin="bot account",
|
bt_uin="bot account",
|
||||||
@@ -13,7 +14,12 @@ bot.run(
|
|||||||
webui_token="Your token"
|
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) 中提及。
|
具体的信息在 [配置项文档](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://```
|
一些报错是由于webui的token所导致的,默认值为napcat,另外连接都需要带上协议,例如连接webui时需要带上 ```http://```
|
||||||
---
|
---
|
||||||
|
|
||||||
|
官方文档已经给出了解析消息的示例,但是我仍然使用了raw_message来手动解析消息。我觉得这个锅要甩***1/3***给文档,
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
@@ -2,3 +2,4 @@ requests~=2.32.4
|
|||||||
ncatbot~=3.8.8.post7
|
ncatbot~=3.8.8.post7
|
||||||
dotenv~=0.9.9
|
dotenv~=0.9.9
|
||||||
python-dotenv~=1.1.1
|
python-dotenv~=1.1.1
|
||||||
|
sqlmodel~=0.0.24
|
||||||
+17
-2
@@ -1,11 +1,26 @@
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from ncatbot.core import BotClient
|
from ncatbot.core import BotClient, GroupMessage, PrivateMessage
|
||||||
|
from ncatbot.utils import get_log
|
||||||
|
|
||||||
load_dotenv(dotenv_path=r"../.env")
|
load_dotenv(dotenv_path=r".env")
|
||||||
|
|
||||||
bot = BotClient()
|
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(
|
bot.run(
|
||||||
bt_uin=os.getenv("BOT_ACCOUNT"),
|
bt_uin=os.getenv("BOT_ACCOUNT"),
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# DataBase
|
||||||
|
> 用于开发功能而做的插件。只是为了便于重载和测试。
|
||||||
|
|
||||||
|
用于和数据库进行交互。
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from .dataBase import DataBase
|
||||||
|
|
||||||
|
__all__ = ['DataBase']
|
||||||
Binary file not shown.
Binary file not shown.
@@ -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."
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ncatbot~=3.8.8.post7
|
||||||
|
dotenv~=0.9.9
|
||||||
|
python-dotenv~=1.1.1
|
||||||
|
sqlmodel~=0.0.24
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# GetFile
|
||||||
|
> 用于开发功能而做的插件。只是为了便于重载和测试。
|
||||||
|
|
||||||
|
用来保存所有的照片和视频的插件。
|
||||||
|
|
||||||
|
> **特殊说明**: 这个插件编写的时间略早,所以消息解析使用了一个极为不成熟的方法。不推荐再做更改。
|
||||||
Binary file not shown.
Binary file not shown.
@@ -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")
|
||||||
|
)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
ncatbot~=3.8.8.post7
|
||||||
|
dotenv~=0.9.9
|
||||||
|
python-dotenv~=1.1.1
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Memigo 插件
|
||||||
|
|
||||||
|
## 简介
|
||||||
|
|
||||||
|
这是一个 NcatBot 插件模板。
|
||||||
|
|
||||||
|
## 功能
|
||||||
|
|
||||||
|
- 群消息事件处理
|
||||||
|
- 好友消息事件处理
|
||||||
|
- 测试功能 (/test)
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
1. 在群聊中发送 "测试" 消息
|
||||||
|
2. 在私聊中发送 "测试" 消息
|
||||||
|
3. 使用 `/test` 命令测试功能
|
||||||
|
|
||||||
|
## 配置项
|
||||||
|
|
||||||
|
- `greeting`: 问候语,默认值为 "你好",可选值: ["你好", "Hello", "Hi"]
|
||||||
|
|
||||||
|
## 依赖
|
||||||
|
|
||||||
|
- NcatBot
|
||||||
|
|
||||||
|
## 作者
|
||||||
|
|
||||||
|
Your Name
|
||||||
|
|
||||||
|
## 许可证
|
||||||
|
|
||||||
|
MIT
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from .main import Memigo
|
||||||
|
|
||||||
|
__all__ = ["Memigo"]
|
||||||
@@ -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)
|
||||||
@@ -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! ")
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Test 插件
|
||||||
|
|
||||||
|
## 简介
|
||||||
|
|
||||||
|
这是一个 NcatBot 插件模板。
|
||||||
|
|
||||||
|
## 功能
|
||||||
|
|
||||||
|
- 群消息事件处理
|
||||||
|
- 好友消息事件处理
|
||||||
|
- 测试功能 (/test)
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
1. 在群聊中发送 "测试" 消息
|
||||||
|
2. 在私聊中发送 "测试" 消息
|
||||||
|
3. 使用 `/test` 命令测试功能
|
||||||
|
|
||||||
|
## 配置项
|
||||||
|
|
||||||
|
- `greeting`: 问候语,默认值为 "你好",可选值: ["你好", "Hello", "Hi"]
|
||||||
|
|
||||||
|
## 依赖
|
||||||
|
|
||||||
|
- NcatBot
|
||||||
|
|
||||||
|
## 作者
|
||||||
|
|
||||||
|
Your Name
|
||||||
|
|
||||||
|
## 许可证
|
||||||
|
|
||||||
|
MIT
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from .main import Test
|
||||||
|
|
||||||
|
__all__ = ["Test"]
|
||||||
@@ -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}")
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# 插件依赖项
|
||||||
|
# 例如: requests==2.28.1
|
||||||
Submodule
+1
Submodule src/plugins/Weather added at 6d2b885b7b
Submodule
+1
Submodule src/plugins/YiYanAPI added at 88e4f85afd
Binary file not shown.
@@ -1,4 +0,0 @@
|
|||||||
from sqlmodel import SQLModel, Session, select, create_engine
|
|
||||||
|
|
||||||
class Data(SQLModel, table=True):
|
|
||||||
__tablename__ = 'file'
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,129 +0,0 @@
|
|||||||
from ncatbot.core import BotClient, GroupMessage, PrivateMessage
|
|
||||||
# from ncatbot.core import (MessageChain, Text, Image)
|
|
||||||
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 beta"
|
|
||||||
|
|
||||||
@bot.private_event()
|
|
||||||
async def on_receive_images_private_event(self, msg: PrivateMessage):
|
|
||||||
meta_message = str(msg)
|
|
||||||
_log.info(f"The message's meta data is: {meta_message}")
|
|
||||||
_log.info(f"The message's raw message is: {msg.raw_message}")
|
|
||||||
|
|
||||||
if "[CQ:image," in msg.raw_message:
|
|
||||||
divided_message = msg.raw_message.split(',')
|
|
||||||
|
|
||||||
for item in divided_message:
|
|
||||||
if "file=" in item:
|
|
||||||
file_name = item.split("=")[1]
|
|
||||||
_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"D:/Projects/memebot/src/data/pics/{file_name}", 'wb') as f:
|
|
||||||
f.write(img)
|
|
||||||
|
|
||||||
@bot.group_event()
|
|
||||||
async def on_receive_images_group_event(self, 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}")
|
|
||||||
|
|
||||||
# if "[CQ:image," in msg.raw_message:
|
|
||||||
if msg.raw_message.startswith("[CQ:image,"):
|
|
||||||
divided_message = msg.raw_message.split(',')
|
|
||||||
|
|
||||||
for item in divided_message:
|
|
||||||
# if "file=" in item:
|
|
||||||
if item.startswith("file="):
|
|
||||||
file_name = item.split("=")[1]
|
|
||||||
_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):
|
|
||||||
_log.info(f"The message's meta data is: {str(msg)}")
|
|
||||||
_log.info(f"The message's raw message is: {msg.raw_message}")
|
|
||||||
|
|
||||||
message = msg.raw_message[1: -1]
|
|
||||||
|
|
||||||
if message.startswith("CQ:video,"):
|
|
||||||
divided_message = message.split(',')
|
|
||||||
for item in divided_message:
|
|
||||||
if item.startswith("file="):
|
|
||||||
file_name = item.split("=")[1]
|
|
||||||
_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):
|
|
||||||
_log.info(f"The message's meta data is: {str(msg)}")
|
|
||||||
_log.info(f"The message's raw message is: {msg.raw_message}")
|
|
||||||
|
|
||||||
message = msg.raw_message[1: -1]
|
|
||||||
|
|
||||||
if message.startswith("CQ:video,"):
|
|
||||||
divided_message = message.split(',')
|
|
||||||
for item in divided_message:
|
|
||||||
if item.startswith("file="):
|
|
||||||
file_name = item.split("=")[1]
|
|
||||||
_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")
|
|
||||||
)
|
|
||||||
|
|
||||||
# [2025-07-25 17:07:40,602] INFO [MainThread|MainProcess] Logger (get_image.py:on_receive_images_group_event:40) | The message's raw message is: [CQ:video,file=3d13c5917a796a92d91d8f9de44b0bf4.mp4,url=https://multimedia.nt.qq.com.cn:443/download?appid=1415&format=origin&orgfmt=t265&spec=0&client_proto=ntv2&client_appid=537298509&client_type=linux&client_ver=3.2.18-36580&client_down_type=auto&client_aio_type=aio&rkey=CAMSoAHGtzhaJAf05S58aBorSh34zdFk2POE-DFhRWajbvwClbIFzBwF7L6O3xQ7vGtHcK3uh3lqvl9-WhxzqeO_EtfFrx6Em_sJMdepoSJKwoBLIZHPA84yP0MoG10RNQylp1U4ZWQFTCG6h6dFARX4rHyJkvpAi1Zit8neB9En2OELgwcSzyUnVqTWluv8OxiQpEW3QmeAhR2O0SSO0v40V_Yi,file_size=2130820]
|
|
||||||
Reference in New Issue
Block a user