Skip to content

Commit

Permalink
feat: 支持 Docker 和 Docker Compose 部署
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassius0924 committed Mar 6, 2024
1 parent f38f9de commit cef44fb
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 50 deletions.
98 changes: 98 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Git
.git
.gitignore
.gitattributes


# CI
.codeclimate.yml
.travis.yml
.taskcluster.yml

# Docker
docker-compose.yml
Dockerfile
.docker
.dockerignore

# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

/docs

# PyBuilder
target/

# Virtual environment
.env
.venv/
venv/

# PyCharm
.idea

# Python mode for VIM
.ropeproject
**/.ropeproject

# Vim swap files
**/*.swp

# VS Code
.vscode/

.pre-commit-config.yaml
config.yaml.example
config.yaml
compose_config.yaml.example
/.github
/tests
.DS_Store
/.ruff_cache
README.md
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.9-alpine3.18
LABEL authors="Cassius0924"

WORKDIR /wechatter

ADD . /wechatter

RUN pip install --no-cache-dir -r requirements.txt

# 使 loguru 支持颜色输出
ENV LOGURU_COLORIZE=True
# 设置日志级别
ENV WECHATTER_LOG_LEVEL=INFO

EXPOSE 4000

CMD ["python3", "-m", "wechatter"]
63 changes: 15 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,45 @@

## 介绍

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

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


## 快速开始

### 运行 wechatbot-webhook
WeChatter 支持 [Docker Compose 部署](#docker-compose-部署)[Docker 部署](./docs/development.md#docker-部署)[本地部署](./docs/development.md#本地部署)

1. 拉取 Docker 镜像

```bash
docker pull dannicool/docker-wechatbot-webhook
```

2. 运行 Docker

```bash
docker run -d \
--name wxBotWebhook \
-p 3001:3001 \
-e LOGIN_API_TOKEN="<Token>" \
-e RECVD_MSG_API="http(s)://<宿主机IP>:<接收消息端口>/receive_msg" \
dannicool/docker-wechatbot-webhook
```

- `<Token>`:令牌
- `<宿主机IP>`:填入 Docker 的宿主机地址。
- `<接收消息端口>`:设置一个接收消息的端口,默认为 `4000`

3. 登录微信

使用下面命令查看 Docker 日志中的微信二维码,扫码登录微信。

```bash
docker logs -f wxBotWebhook
```
> [!TIP]
> 推荐使用 Docker-compose 部署。
### 启动 WeChatter
### Docker Compose 部署

1. 下载源代码
1. 下载 WeChatter 配置文件

```bash
git clone https://github.com/Cassius0924/WeChatter
cd WeChatter
mkdir WeChatter && cd WeChatter
wget -O compose_config.yaml https://cdn.jsdelivr.net/gh/cassius0924/wechatter@master/compose_config.yaml.example
```

2. 安装依赖项
2. 编辑 `compose_config.yaml` 配置文件

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

pip install -r requirements.txt
vim compose_config.yaml
```

3. 复制并编辑配置文件
3. 下载 docker-compose.yml

```bash
cp config.yaml.example config.yaml
vim config.yaml
wget https://cdn.jsdelivr.net/gh/cassius0924/wechatter@master/docker-compose.yml
```

4. 启动 WeChatter
4. 运行 Docker Compose

```bash
python3 -m wechatter
docker-compose -f docker-compose.yml up -d
```

5. 测试机器人

使用另一个微信给机器人发送 `/help` 指令。

## 支持的命令

- [x] GPT 问答(不支持定时任务)
Expand Down Expand Up @@ -147,7 +114,7 @@ python3 -m wechatter

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| `wx_webhook_base_api` | 发送消息的 BaseAPI | 默认为 `localhost:3001`,即 `wxBotWebhook` Docker 的地址 |
| `wx_webhook_base_api` | 发送消息的 BaseAPI | 默认为 `http://localhost:3001`,即 `wxBotWebhook` Docker 的地址。Docker Compose 部署时默认为 `http://wxbotwebhook:3001` |
| `wx_webhook_recv_api_path` | 接收消息的接口路径 | 默认为 `/receive_msg`,此路径为 Docker 参数 `RECVD_MSG_API` 的路径 |
| `wx_webhook_token` | wxBotWebhook 的 Token | |

Expand Down
96 changes: 96 additions & 0 deletions compose_config.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 微信机器人配置文件
# 配置说明:https://github.com/Cassius0924/WeChatter?tab=readme-ov-file#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6


# Wechatter
wechatter_port: 4000


# WX Webhook
# Docker 部署时,wx_webhook_base_api 需要配置为 wxbotwebhook,端口需要与 docker-compose.yml 中的端口一致
wx_webhook_base_api: http://wxbotwebhook:3001
wx_webhook_recv_api_path: /receive_msg
wx_webhook_token: "wechatter"


# Admin
admin_list: [ "文件传输助手", "AdminName" ]
admin_group_list: [ "AdminGroupName" ]
bark_url: your_bark_url


# Bot
bot_name: Cassius


# Chat
command_prefix: /
need_mentioned: False


# LLM
openai_base_api: https://api.openai.com
openai_token: sk_your_openai_token


# GitHub Webhook
github_webhook_enabled: True
github_webhook_api_path: /webhook/github
github_webhook_receive_person_list: [ ]
github_webhook_receive_group_list: [ ]


# Message Forwarding:消息转发
message_forwarding_enabled: False
message_forwarding_rule_list:
- from_list: [ "%ALL" ]
from_list_exclude: [ "You" ]
to_person_list: [ "You" ]
to_group_list: [ ]
- from_list: [ "Jay", "Tom" ]
to_person_list: [ "Cassius" ]
to_group_list: [ "Team" ]


# 公众号消息提醒
official_account_reminder_enabled: True
official_account_reminder_rule_list:
- oa_name_list: [ "央视新闻", "人民日报" ]
to_person_list: [ "You" ]
to_group_list: [ "Team" ]


# Task Cron:定时任务
# 配置说明:https://github.com/Cassius0924/WeChatter/blob/master/docs/task_cron_config_detail.md
all_task_cron_enabled: True
task_cron_list:
- task: "每天早上8点发送天气预报和知乎热搜"
enabled: True
cron:
hour: "8"
minute: "0"
second: "0"
timezone: "Asia/Shanghai"
commands:
- cmd: "weather"
args: [ "广州" ]
to_person_list: [ "You" ]
- cmd: "zhihu-hot"
to_group_list: [ "Team" ]


# Custom Command Key: 自定义命令关键词
# 配置说明:https://github.com/Cassius0924/WeChatter/blob/master/docs/custom_command_key_config_detail.md
custom_command_key_dict:
gpt4: [ ">" ]
bili-hot: [ "bh" ]
play: [ "p" ]
weather: [ "w", "温度" ]


# Discord Message Forwarding:Discord 消息转发
discord_message_forwarding_enabled: False
discord_message_forwarding_rule_list:
- from_list: [ "%ALL" ]
from_list_exclude: [ "" ]
webhook_url: "your_discord_webhook_url"
2 changes: 1 addition & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ custom_command_key_dict:


# Discord Message Forwarding:Discord 消息转发
discord_message_forwarding_enabled: True
discord_message_forwarding_enabled: False
discord_message_forwarding_rule_list:
- from_list: [ "%ALL" ]
from_list_exclude: [ "" ]
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.8"
services:
wxbotwebhook:
image: dannicool/docker-wechatbot-webhook
container_name: wxbotwebhook
ports:
- "3001:3001"
environment:
- LOGIN_API_TOKEN=wechatter
- ACCEPT_RECVD_MSG_MYSELF=true
- RECVD_MSG_API=http://wechatter:4000/receive_msg

wechatter:
image: cassius0924/wechatter:v0.5.10
container_name: wechatter
ports:
- "4000:4000"
volumes:
- ./compose_config.yaml.example:/wechatter/config.yaml
environment:
- WECHATTER_LOG_LEVEL=INFO
depends_on:
- wxbotwebhook
Loading

0 comments on commit cef44fb

Please sign in to comment.