Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 引用消息回复功能 #55

Merged
merged 9 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 43 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# WeChatter
# WeChatter: Make WeChat Better

<div align="center">

[![CI/CD](https://github.com/Cassius0924/WeChatter/actions/workflows/test.yml/badge.svg)](https://github.com/Cassius0924/WeChatter/actions/workflows/test.yml)
[![GitHub Release](https://img.shields.io/github/v/release/Cassius0924/WeChatter)](https://github.com/Cassius0924/WeChatter/releases)
[![GitHub License](https://img.shields.io/github/license/Cassius0924/WeChatter)](https://github.com/Cassius0924/WeChatter/blob/master/LICENSE)
![Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)

</div>

## 介绍

基于 [wechatbot-webhook](https://github.com/danni-cool/wechatbot-webhook) 的微信机器人💬,支持 GPT 问答、热搜、天气预报、消息转发、Webhook提醒等功能。

[![wechatter show](docs/images/wechatter_show.png)](docs/command_show.md)

## 快速开始

### 运行 wechatbot-webhook
Expand Down Expand Up @@ -57,6 +60,8 @@ cd WeChatter
2. 安装依赖项

```bash
# 如果需要,则创建虚拟环境...

pip install -r requirements.txt
```

Expand All @@ -80,37 +85,34 @@ python3 main.py
## 支持的命令

- [x] GPT 问答,基于 [Copilot-GPT4-Server](https://github.com/aaamoon/copilot-gpt4-service)
- [x] 获取 Bilibili 热搜
- [x] 获取知乎热搜
- [x] 获取微博热搜
- [x] 获取抖音热搜
- [x] 获取 GitHub 趋势
- [x] 单词/词语翻译
- [x] 获取少数派早报
- [x] 获取历史上的今天
- [x] 二维码生成器
- [x] Bilibili 热搜
- [x] 知乎热搜
- [x] 微博热搜
- [x] 抖音热搜
- [x] GitHub 趋势
- [x] 单词词语翻译
- [x] 少数派早报
- [x] 历史上的今天
- [x] 二维码生成
- [x] 待办清单(TODO)
- [x] 获取人民日报PDF
- [x] 获取天气预报
- [x] 获取食物热量/卡路里
- [x] 随机获取冷知识
- [x] 获取中石化92号汽油指导价
- [x] 人民日报PDF
- [x] 天气预报
- [x] 食物热量
- [x] 冷知识
- [x] 中石化92号汽油指导价

> [!TIP]
> 更多命令使用 `/help` 命令查看
> 命令帮助请使用 `/help` 命令查询或查看[命令功能展示](docs/command_show.md)

## 支持的功能

- [x] 消息转发,需[配置](#%EF%B8%8F-message-forwarding-配置)
- [x] 天气预报定时推送,需[配置](#%EF%B8%8F-weather-cron-配置)
- [x] 中石化92号汽油指导价定时推送,需[配置](#%EF%B8%8F-gasoline-price-cron-配置)
- [x] 消息转发,需[配置](#%EF%B8%8F-message-forwarding-配置)
- [x] 消息可引用回复,用户通过引用并回复可以进一步获取消息内容。带“(可引用:***)”的机器人消息均为可进一步互动的可引用消息。
- [x] 天气预报定时推送,需[配置](#%EF%B8%8F-weather-cron-配置)

## 支持的 Webhook

- [x] GitHub 仓库 Webhook,需[配置](#%EF%B8%8F-github-webhook-配置)

> [!NOTE]
> 需要在 GitHub 仓库 Settings 中添加 Webhook
- [x] GitHub 仓库 Webhook,需在 GitHub 仓库 Settings 中添加 Webhook 并[配置](#%EF%B8%8F-github-webhook-配置)

## 配置文件

Expand All @@ -127,43 +129,41 @@ python3 main.py
### ⚙️ WxBotWebhook 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| `wx_webhook_host` | 发送消息的地址 | 默认为 `localhost`,需和 `wxBotWebhook` 的 Docker IP 地址一致 |
| `wx_webhook_port` | 发送消息的端口 | 默认为 `3001`,需和 `wxBotWebhook` 的 Docker 端口一致 |
| `wx_webhook_recv_api_path` | 接收消息的接口路径 | 默认为 `/receive_msg`,此路径为 `RECV_MSG_API` 的路径 |
| --- | --- | --- |
| `wx_webhook_base_api` | 发送消息的 BaseAPI | 默认为 `localhost:3001`,即 `wxBotWebhook` Docker 的地址 |
| `wx_webhook_recv_api_path` | 接收消息的接口路径 | 默认为 `/receive_msg`,此路径为 Docker 参数 `RECVD_MSG_API` 的路径 |

### ⚙️ Admin 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `admin_list` | 设置管理员,用于接收机器人状态变化通知 | 填入管理员微信名(不是备注) |
| `admin_group_list` | 与 `admin_list` 同理,接收机器人状态变化通知 | 填入群名称(不是群备注) |

### ⚙️ Bot 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `bot_name` | 微信机器人的名字 | 微信名称,非微信号 |

### ⚙️ Chat 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `command_prefix` | 机器人命令前缀 | 默认为 `/` ,可以设置为`>>`、`!` 等 |
| `need_mentioned` | 群聊中的命令是否需要@机器人 | 默认为 `True` |

### ⚙️ Copilot GPT4 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| `cp_gpt4_api_host` | CopilotGPT4 服务的API地址 | 默认为 `http://localhost` |
| `cp_gpt4_port` | CopilotGPT4 服务的端口 | 默认为 `8080` |
| `cp_token` | Copilot 的 Token | 以 `ghu_` 开头的字符串 |
| --- | --- | --- |
| `cp_gpt4_base_api` | CopilotGPT4 服务的 BaseAPI | 默认为 `http://localhost:8080` |
| `cp_token` | GitHub Copilot 的 Token | 以 `ghu_` 开头的字符串 |

### ⚙️ GitHub Webhook 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `github_webhook_enabled` | 功能开关,是否接收 GitHub Webhook | 默认为 `False` |
| `github_webhook_api_path` | 接收 GitHub Webhook 的接口路径 | 默认为 `/webhook/github` |
| `github_webhook_receiver_list` | 接收 GitHub Webhook 的微信用户 | |
Expand All @@ -175,14 +175,14 @@ python3 main.py
| --- | --- | --- | --- |
| `message_forwarding_enabled` | | 功能开关,是否开启消息转发 | 默认为 `False` |
| `message_forwarding_rule_list` | | 消息规则列表,每个规则包含三个字段:`froms`, `to_persons` 和 `to_groups` | 规则是由字典组成的JSON列表,最后的 `]` 不能单独一行 |
| ➤➤➤ | `froms` | 消息转发来源列表,即消息发送者 | 可以填多个用户名称或群名称 |
| ➤➤➤ | `to_persons` | 消息转发目标用户列表,即消息接收用户 | 可以填多个用户名称或为空列表 |
| ➤➤➤ | `to_groups` | 消息转发目标群列表,即消息接收群 | 可以填多个群名称或为空列表 |
| | `froms` | 消息转发来源列表,即消息发送者 | 可以填多个用户名称或群名称 |
| | `to_persons` | 消息转发目标用户列表,即消息接收用户 | 可以填多个用户名称或为空列表 |
| | `to_groups` | 消息转发目标群列表,即消息接收群 | 可以填多个群名称或为空列表 |

### ⚙️ Weather Cron 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `weather_cron_enabled` | 功能开关,是否开启定时天气推送 | 默认为 `False` |
| `weather_cron_rule_list` | 推送规则列表,每个规则包含两个字段:`cron` 和 `tasks` | |

Expand All @@ -191,19 +191,16 @@ python3 main.py
### ⚙️ Custom Command Key 配置

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| --- | --- | --- |
| `custom_command_key_dict` | 自定义命令关键词字典,格式为 `command: [key1, key2, ...]`, 其中 `command` 为命令名称,`key1` 和 `key2` 为自定义命令关键词 | |

关于命令名称可选值详见[自定义命令关键词配置详细](docs/custom_command_key_config_detail.md)

### ⚙️ Gasoline Price Cron 配置
# 贡献者

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| `gasoline_price_cron_enabled` | 功能开关,是否开启定时推送92号汽油指导价 | 默认为 `False` |
| `gasoline_price_cron_rule_list` | 推送规则列表,每个规则包含两个字段:`cron` 和 `tasks` | |
Thanks to the following people who have contributed to this project:

关于 `cron` 和 `tasks` 的配置见[中石化92号汽油指导价定时任务配置详细](docs/gasoline_price_cron_config_detail.md)
[![Contributors](https://contrib.rocks/image?repo=Cassius0924/WeChatter)](https://github.com/Cassius0924/WeChatter/graphs/contributors)

## 插件化

Expand Down
14 changes: 5 additions & 9 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ wechatter_port = 4000


[wx-bot-webhook]
# 发送消息的 API 地址,必须包含http(s)://(<<http://localhost>>)
wx_webhook_host = http://localhost
# 发送消息的端口,wxBotWebhook Docker 的端口(<<3001>>)
wx_webhook_port = 3001
# 发送消息的 API 地址,必须包含"http(s)://"(<<http://localhost:3001>>)
wx_webhook_base_api = http://localhost:3001
# 接收消息的接口路径,RECV_MSG_API的路径(<</receive_msg>>)
wx_webhook_recv_api_path = /receive_msg

Expand All @@ -36,17 +34,15 @@ need_mentioned = True


[copilot-gpt4]
# Copilot GPT4 服务的 API 地址,必须包含http(s)://(<<http://localhost>>)
cp_gpt4_api_host = http://localhost
# Copilot GPT4 服务的端口(<<999>>)
cp_gpt4_port = 999
# Copilot GPT4 服务的 API 地址,必须包含http(s)://(<<http://localhost:999>>)
cp_gpt4_base_api = http://localhost:999
# Copilot 的 Token
cp_token = ghu_your_token


[github-webhook]
# 是否接收 GitHub Webhook (True/<<False>>)
github_webhook_enabled = True
github_webhook_enabled = False
# 接收 GitHub Webhook 的接口路径(<</webhook/github>>)
github_webhook_api_path = /webhook/github
# 接收 GitHub Webhook 的微信用户
Expand Down
127 changes: 127 additions & 0 deletions docs/command_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# 命令功能展示

本文档展示了 WeChatter 支持的命令功能。

## 目录
- [天气预报](#天气预报)
- [待办清单](#待办清单)
- [添加待办](#添加待办)
- [删除待办](#删除待办)
- [查看待办](#查看待办)
- [Bilibili 热搜](#Bilibili-热搜)
- [知乎热搜](#知乎热搜)
- [微博热搜](#微博热搜)
- [抖音热搜](#抖音热搜)
- [GitHub 趋势](#GitHub-趋势)
- [GPT 问答](#GPT-问答)
- [持续对话](#持续对话)
- [新建对话](#新建对话)
- [所有对话](#所有对话)
- [继续对话](#继续对话)
- [对话记录](#对话记录)
- [单词词语翻译](#单词词语翻译)
- [少数派早报](#少数派早报)
- [人民日报](#人民日报)
- [二维码生成](#二维码生成)
- [食物热量](#食物热量)
- [中石化92号汽油指导价](#中石化92号汽油指导价)
- [冷知识](#冷知识)
- [历史上的今天](#历史上的今天)

## 天气预报

![获取天气预报](./images/cmd_weather.png)

## 待办清单

### 添加待办

![待办清单](./images/cmd_todo_1.png)

### 删除待办

![待办清单](./images/cmd_todo_2.png)

### 查看待办

![待办清单](./images/cmd_todo_3.png)

## Bilibili 热搜

![获取 Bilibili 热搜](./images/cmd_bili_hot.png)

## 知乎热搜

![获取知乎热搜](./images/cmd_zhihu_hot.png)

## 微博热搜

![获取微博热搜](./images/cmd_weibo_hot.png)

## 抖音热搜

![获取抖音热搜](./images/cmd_douyin_hot.png)

## GitHub 趋势

![获取 GitHub 趋势](./images/cmd_github_trending.png)

## GPT 问答

### 持续对话

![GPT 问答](./images/cmd_gpt4_1.png)

### 新建对话

![GPT 问答](./images/cmd_gpt4_2.png)

### 所有对话

![GPT 问答](./images/cmd_gpt4_3.png)

### 继续对话

![GPT 问答](./images/cmd_gpt4_4.png)

### 对话记录

![GPT 问答](./images/cmd_gpt4_5.png)

## 单词词语翻译

![单词词语翻译](./images/cmd_word.png)

## 少数派早报

![少数派早报](./images/cmd_pai_post.png)

## 人民日报

### PDF 文件

![人民日报](./images/cmd_people_daily_1.png)

### 日报链接

![人民日报](./images/cmd_people_daily_2.png)

## 二维码生成

![二维码生成](./images/cmd_qrcode.png)

## 食物热量

![食物热量](./images/cmd_food_calories.png)

## 中石化92号汽油指导价

![中石化92号汽油指导价](./images/cmd_gasoline_price.png)

## 冷知识

![冷知识](./images/cmd_trivia.png)

## 历史上的今天

![历史上的今天](./images/cmd_today_in_history.png)
Binary file added docs/images/cmd_bili_hot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_douyin_hot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_food_calories.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gasoline_price.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_github_trending.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gpt4_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gpt4_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gpt4_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gpt4_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_gpt4_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_pai_post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_people_daily_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_people_daily_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_today_in_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_todo_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_todo_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_todo_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_trivia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_weather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_weibo_hot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_word.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cmd_zhihu_hot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wechatter_show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wechatter_show2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# WeChatter 启动文件
#
# __ __ ______ ______ __ __ ______ ______ ______ ______ ______
# /\ \ _ \ \ /\ ___\ /\ ___\ /\ \_\ \ /\ __ \ /\__ _\/\__ _\/\ ___\ /\ == \
# \ \ \/ ".\ \\ \ __\ \ \ \____\ \ __ \\ \ __ \\/_/\ \/\/_/\ \/\ \ __\ \ \ __<
# \ \__/".~\_\\ \_____\\ \_____\\ \_\ \_\\ \_\ \_\ \ \_\ \ \_\ \ \_____\\ \_\ \_\
# \/_/ \/_/ \/_____/ \/_____/ \/_/\/_/ \/_/\/_/ \/_/ \/_/ \/_____/ \/_/ /_/
#

import uvicorn
from loguru import logger

import wechatter.database as db
import wechatter.utils.file_manager as fm
Expand Down Expand Up @@ -28,7 +35,6 @@ def main():

db.create_tables()

logger.info("WeChatter 启动成功!")
# 启动uvicorn
uvicorn.run(app, host="0.0.0.0", port=config.wechatter_port)

Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from wechatter.init_logger import init_logger

init_logger("CRITICAL")
7 changes: 7 additions & 0 deletions tests/commands/test_bili_hot/test_bili_hot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ def test_generate_bili_hot_message_success(self):
def test_generate_bili_hot_message_empty_list(self):
result = bili_hot._generate_bili_hot_message([])
self.assertEqual(result, "暂无Bilibili热搜")

def test_generate_bili_hot_quoted_response_success(self):
result = bili_hot._generate_bili_hot_quoted_response(
self.r_json["data"]["list"]
)
true_result = '{"1": "https://search.bilibili.com/all?keyword=%E5%A4%8D%E6%97%A6%E6%95%99%E5%B8%88%E6%9D%80%E5%AE%B3%E5%AD%A6%E9%99%A2%E4%B9%A6%E8%AE%B0%E8%A2%AB%E5%88%A4%E6%AD%BB%E7%BC%93", "2": "https://search.bilibili.com/all?keyword=%E5%85%8D%E8%B4%B9%E9%A2%86%E5%8F%96%E5%BF%83%E9%AD%94", "3": "https://search.bilibili.com/all?keyword=%E6%89%8E%E5%85%8B%E4%BC%AF%E6%A0%BC%E9%81%93%E6%AD%89", "4": "https://search.bilibili.com/all?keyword=%E6%98%93%E7%83%8A%E5%8D%83%E7%8E%BA%E5%BD%93%E9%80%89%E4%B8%AD%E5%9B%BD%E5%BD%B1%E5%8D%8F%E7%90%86%E4%BA%8B", "5": "https://search.bilibili.com/all?keyword=kei%E5%92%8Cmarin%E5%88%86%E6%89%8B", "6": "https://search.bilibili.com/all?keyword=%E4%B8%8A%E6%B5%B7%E7%A6%81%E6%AD%A2%E7%BD%91%E7%BA%A6%E8%BD%A6%E5%9C%A8%E6%B5%A6%E4%B8%9C%E6%9C%BA%E5%9C%BA%E8%BF%90%E8%90%A5", "7": "https://search.bilibili.com/all?keyword=%E4%B8%AD%E5%9B%BD%E8%B1%86%E6%B5%86%E6%9C%BA%E5%9C%A8%E9%9F%A9%E5%9B%BD%E7%83%AD%E9%94%80", "8": "https://search.bilibili.com/all?keyword=%E4%BD%95%E5%90%8C%E5%AD%A6%E5%B7%A5%E4%BD%9C%E5%AE%A4%E9%A6%96%E6%AC%A1%E5%85%AC%E5%BC%80", "9": "https://search.bilibili.com/all?keyword=%E5%AE%98%E6%96%B9%E7%A7%B0%E7%A1%AE%E5%AE%9A%E5%9B%BD%E8%8A%B1%E6%97%B6%E6%9C%BA%E6%9C%AA%E6%88%90%E7%86%9F", "10": "https://search.bilibili.com/all?keyword=Aimer%E5%8F%82%E6%BC%94%E5%8E%9F%E7%A5%9E%E6%96%B0%E6%98%A5%E4%BC%9A", "11": "https://search.bilibili.com/all?keyword=%E6%80%BB%E5%8F%B0%E9%BE%99%E5%B9%B4%E6%98%A5%E6%99%9A%E5%8A%A8%E7%94%BB%E5%AE%A3%E4%BC%A0%E7%89%87", "12": "https://search.bilibili.com/all?keyword=%E5%8F%AA%E8%A7%A3%E5%86%BB%E5%88%98%E5%BE%B7%E5%8D%8E%E5%A4%AA%E4%BF%9D%E5%AE%88%E4%BA%86", "13": "https://search.bilibili.com/all?keyword=%E7%83%9F%E8%8A%B1%E5%BC%95%E5%8F%91%E4%BD%8F%E5%AE%85%E8%B5%B7%E7%81%AB%E8%87%B4%E8%80%81%E4%BA%BA%E5%8E%BB%E4%B8%96", "14": "https://search.bilibili.com/all?keyword=750%E4%B8%87%E4%BA%BA%E5%9C%A8%E7%AD%89%E5%B0%8A%E4%B8%A5%E6%AD%BB", "15": "https://search.bilibili.com/all?keyword=%E5%9D%A0%E4%BA%A1%E5%A7%90%E5%BC%9F%E7%94%9F%E6%AF%8D%E8%A2%AB%E9%80%81%E5%8C%BB%E9%99%A2", "16": "https://search.bilibili.com/all?keyword=%E4%B8%8D%E7%BB%B5%E4%B9%8B%E5%A4%9C", "17": "https://search.bilibili.com/all?keyword=%E6%B8%85%E5%8D%8E%E5%AE%A3%E5%B8%83%E8%84%91%E6%9C%BA%E6%8E%A5%E5%8F%A3%E9%87%8D%E5%A4%A7%E7%AA%81%E7%A0%B4", "18": "https://search.bilibili.com/all?keyword=Uzi%20%E4%BD%BF%E7%94%A8%E6%9B%BF%E8%BA%AB%E6%94%BB%E5%87%BB", "19": "https://search.bilibili.com/all?keyword=%E6%8D%A1%E9%9B%AA%E5%90%83%E6%82%A3%E7%97%85%E8%BF%9E%E7%83%A7%E5%85%AB%E5%A4%A9", "20": "https://search.bilibili.com/all?keyword=%E5%B9%BB%E5%A1%94EVA%E8%81%94%E5%8A%A8%E6%98%8E%E6%97%A5%E9%A6%99%E7%99%BB%E5%9C%BA"}'
self.assertEqual(result, true_result)
7 changes: 7 additions & 0 deletions tests/commands/test_douyin_hot/test_douyin_hot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ def test_generate_douyin_hot_message_success(self):
def test_generate_douyin_hot_message_empty_list(self):
result = douyin_hot._generate_douyin_hot_message([])
self.assertEqual(result, "暂无抖音热搜")

def test_generate_douyin_hot_quoted_response_success(self):
result = douyin_hot._generate_douyin_hot_quoted_response(
self.r_json["word_list"]
)
true_result = '{"1": "https://www.douyin.com/search/%E8%91%A3%E5%AE%87%E8%BE%89%E5%AF%B9%E5%88%98%E5%BE%B7%E5%8D%8E%E8%AF%B4%E6%83%B3%E6%BC%94%E5%85%B5%E9%A9%AC%E4%BF%91", "2": "https://www.douyin.com/search/%E4%BB%8A%E5%B9%B4%E6%98%A5%E8%81%94%E6%98%AF%E8%87%AA%E5%B7%B1%E5%86%99%E7%9A%84", "3": "https://www.douyin.com/search/%E4%B8%AD%E5%9B%BD%E5%90%8C23%E5%9B%BD%E5%85%A8%E9%9D%A2%E4%BA%92%E5%85%8D%E7%AD%BE%E8%AF%81", "4": "https://www.douyin.com/search/%E6%9A%97%E5%A4%9C%E5%8F%98%E8%A3%85%E6%8C%91%E6%88%98", "5": "https://www.douyin.com/search/%E6%99%92%E5%87%BA%E4%BD%A0%E7%9A%84%E6%96%B0%E6%98%A5%E7%BA%A2", "6": "https://www.douyin.com/search/%E7%9B%B8%E4%BA%B2%E7%9B%B8%E7%88%B1%E6%8E%A5%E5%8A%9B%E6%8C%91%E6%88%98", "7": "https://www.douyin.com/search/%E8%AF%80%E5%88%AB%E4%B9%A6%E7%9A%84%E6%AD%A3%E7%A1%AE%E6%89%93%E5%BC%80%E6%96%B9%E5%BC%8F", "8": "https://www.douyin.com/search/2%E6%9C%88%E7%AC%AC%E4%B8%80%E5%A4%A9", "9": "https://www.douyin.com/search/%E5%8C%97%E4%BA%AC%E4%BA%A7%E6%9D%83%E4%BA%A4%E6%98%93%E6%89%80%E6%BE%84%E6%B8%85%E5%A3%B0%E6%98%8E", "10": "https://www.douyin.com/search/%E8%B4%B5%E5%B7%9E%E6%9C%89%E5%A4%9A%E9%92%9F%E7%88%B1%E5%8A%9E%E9%85%92%E5%B8%AD", "11": "https://www.douyin.com/search/%E5%90%84%E5%9C%B0%E4%BA%BA%E8%BF%99%E4%B9%88%E5%81%9A%E4%B8%80%E5%AE%9A%E6%9C%89%E5%8E%9F%E5%9B%A0", "12": "https://www.douyin.com/search/%E9%9F%A9%E5%9B%BD%E7%91%9C%E5%BD%93%E9%80%89%E5%8F%B0%E7%AB%8B%E6%B3%95%E6%9C%BA%E6%9E%84%E8%B4%9F%E8%B4%A3%E4%BA%BA", "13": "https://www.douyin.com/search/%E4%B8%80%E8%B5%B7%E8%B7%B3%E7%94%9C%E5%A6%B9%E6%89%8B%E5%8A%BF%E8%88%9E", "14": "https://www.douyin.com/search/%E4%B8%8A%E6%B5%B7%E6%A5%BC%E6%88%BF%E5%87%8C%E6%99%A8%E5%9D%8D%E5%A1%8C%20%E5%A4%9A%E6%96%B9%E5%9B%9E%E5%BA%94", "15": "https://www.douyin.com/search/%E5%88%98%E5%BE%B7%E5%8D%8E%E5%AE%81%E6%B5%A9%E7%BA%A2%E6%AF%AF%E5%85%88%E7%94%9F%E4%BB%8A%E6%99%9A%E7%9B%B4%E6%92%AD", "16": "https://www.douyin.com/search/%E6%B2%A1%E6%9C%89%E5%90%8C%E6%A1%8C%E6%88%91%E5%8F%AF%E6%80%8E%E4%B9%88%E5%8A%9E%E5%95%8A", "17": "https://www.douyin.com/search/%E6%B2%B3%E5%8C%97%E4%B8%80%E4%BF%9D%E5%AE%89%E9%98%BB%E6%AD%A2%E5%A5%94%E9%A9%B0%E5%8A%A0%E5%A1%9E%E8%A2%AB%E9%A1%B6%E6%92%9E", "18": "https://www.douyin.com/search/%E7%BD%91%E5%8F%8B%E8%BF%87%E5%B9%B4%E7%88%B1%E4%B8%8A%E7%BB%84%E5%85%BB%E7%94%9F%E5%B1%80%E4%BA%86", "19": "https://www.douyin.com/search/%E5%8F%AC%E9%9B%86%E5%85%A8%E6%8A%96%E9%9F%B3%E6%99%9A8%E6%89%BE%E4%B9%90%E5%AD%90", "20": "https://www.douyin.com/search/%E6%98%A5%E8%BF%90%E6%9C%9F%E9%97%B4%E5%A4%A9%E6%B0%94%E9%A2%84%E6%B5%8B"}'
self.assertEqual(result, true_result)
Loading
Loading