Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d043a3d
Use `SO_REUSEADDR` during server port binding (#27)
xrh0905 Jul 22, 2022
929d48f
less status log spam in cqhttp bot
Fallen-Breath Aug 22, 2022
c0a2144
Use mermaid to draw the flowchart image
Fallen-Breath Aug 22, 2022
2032621
online command client in flowchart image
Fallen-Breath Aug 22, 2022
ce56473
update discord.py
Fallen-Breath Sep 10, 2022
ef5433e
v2.3.0
Fallen-Breath Sep 10, 2022
bb318d2
zh_cn Disclaimer
Fallen-Breath Oct 18, 2022
0a5b599
`enable` switch in mcdr plugin config
Fallen-Breath Feb 3, 2023
b1b2ea5
v2.4.0
Fallen-Breath Feb 14, 2023
9c3c4a3
fixed cli entry typo
Fallen-Breath Feb 27, 2023
4f4915b
CQ bot client json data reading fail-proof
Fallen-Breath Feb 27, 2023
24b1cba
v2.4.1
Fallen-Breath Feb 27, 2023
2072823
custom packet type, and splits broadcast_chat / send_chat
Fallen-Breath Mar 13, 2023
1b0f109
fixed khl bot cannot broadcast !!qq message
Fallen-Breath Mar 13, 2023
251bb12
cqhttp client support sending any text via custom payload
Fallen-Breath Mar 13, 2023
a0131d4
v2.5.0
Fallen-Breath Mar 13, 2023
6ed1eb2
fix using undocumented api
Fallen-Breath Apr 4, 2023
e60f859
v2.5.1
Fallen-Breath Apr 4, 2023
5e6e55f
up-to-date online client bungee command impl
Fallen-Breath Oct 29, 2023
01d5b37
!!online command on mcdr client
Fallen-Breath Oct 29, 2023
6441c3d
v2.5.2
Fallen-Breath Oct 29, 2023
baded43
fixed cqhttp bot `anonymous` message data thing
Fallen-Breath Dec 7, 2023
51d72eb
docker image support
Fallen-Breath Dec 22, 2023
d358548
v2.5.3
Fallen-Breath Dec 23, 2023
bc89fc6
add satori bot support
Fallen-Breath May 24, 2024
ab36f31
satori correct nickname support, use regular queue for simpleness, up…
Fallen-Breath May 25, 2024
c768c29
khl bot update khl.py
Fallen-Breath May 25, 2024
0121204
action step update and image build linux/amd64 only for dev builds
Fallen-Breath May 25, 2024
f5cb1f4
cqhttp client don't install websocket
Fallen-Breath May 25, 2024
9e0191f
readme update and better satori-python requirement version range
Fallen-Breath May 25, 2024
4b673b5
extract cqhttp bot copy-writings into a separated file
Fallen-Breath May 25, 2024
56b9e1a
satori stop fast
Fallen-Breath May 25, 2024
7e22d01
make the docker build simple cuz everything has pre-built wheel
Fallen-Breath May 25, 2024
4e0f4bd
detect this
Fallen-Breath May 25, 2024
0f07aeb
simple
Fallen-Breath May 25, 2024
b0068ed
more logs and escape special chars for satori
Fallen-Breath May 25, 2024
02def9b
ci: add package.yml
Fallen-Breath Jun 15, 2024
d232a87
v2.6.0
Fallen-Breath Jun 15, 2024
615e24f
ci: only use linux/amd64 for docker image build
Fallen-Breath Jun 15, 2024
57708a7
-it in docker-compose.yml for server
Fallen-Breath Jun 15, 2024
cf3b9db
cli client, server, online cmd, ignore empty input
Fallen-Breath Jun 15, 2024
e1d59cc
v2.6.1
Fallen-Breath Jun 15, 2024
51cb4f2
ping `satori-python` version
Fallen-Breath Jul 19, 2024
a689ea0
cqhttp,satori: support disable !!stats or !!online command
Fallen-Breath Jul 19, 2024
0acafeb
v2.6.2
Fallen-Breath Jul 19, 2024
98db518
v2.6.3
Fallen-Breath Jul 19, 2024
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
__pycache__
50 changes: 50 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Docker Image

on:
push:
paths:
- ".github/workflows/image.yml"
- "docker/Dockerfile"
- "chatbridge/**"
- "lang/**"
- "__main__.py"
- "LICENSE"
- "mcdreforged.plugin.json"
- "**/requirements.txt"

jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: fallenbreath
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
fallenbreath/chatbridge
tags: |
type=ref,event=branch
type=semver,pattern={{version}}

- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: 'linux/amd64'
file: ./docker/Dockerfile
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
43 changes: 43 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI for MCDR Plugin

on:
push:
pull_request:

jobs:
package:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.9

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Pack Plugin
run: |
python -m mcdreforged pack -o ./package

- uses: actions/upload-artifact@v4
with:
name: Chatbridge distribution for ${{ github.sha }}
path: package/

- name: Publish distribution to release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
files: package/*.pyz
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
test.py
*.log
*.pyc
/__pycache__
__pycache__
StatsHelper.py
/stats_helper
/more_apis
*.zip
*.mcdr
*.pyz
*.bat
*.sh
ChatBridge_*.json
99 changes: 90 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

See [here](https://github.com/TISUnion/ChatBridge/tree/v1) for chatbridge v1. **NOT compatible with Chatbridge v1**

![topomap](https://raw.githubusercontent.com/TISUnion/ChatBridge/master/topomap.png)
```mermaid
flowchart LR
subgraph Minecraft Host
mcdr1("ChatBridge Client (MCDR plugin)")<--MCDR-->smp[Minecraft Surival Server]
mcdr2("ChatBridge Client (MCDR plugin)")<--MCDR-->cmp[Minecraft Creative Server]
mcdr3("ChatBridge Client (MCDR plugin)")<--MCDR-->smpc[Minecraft Mirror Server]
online("ChatBridge Online Command Client")<--RCON-->bc[Bungeecord Server]
end

server(["ChatBridge Server"])
server<-->mcdr1 & mcdr2 & mcdr3 & online
server<-->cli_client("CLI Client")<-.->user[/User/]
server<-->cq_client("ChatBridge CQHttp Client")<-->cqhttp[CQ Http bot]-.-QQ
server<-->khl_client("ChatBridge Khl Client")<-->khl["Kaiheila (Kook)"]
server<-->discord_client("ChatBridge Discord Client")<-->Discord
```

## Disclaimer

Expand All @@ -14,11 +29,12 @@ ChatBridge is mainly for custom use of TIS server, especially the bot/command co
- Discord client
- Kaiheila client
- Online command client
- ...

Therefore for these bot and related clients:
Therefore, for these bot and related clients:

- Expect hardcoded constants in codes and lack of document/usage/support
- PRs for features will not be accepted, related issues will probably be ignored
- PRs for features will not be accepted, issues complaining something don't work will probably be ignored. No after-sales support
- If you want more features, fork this repository and implement them yourself

But the basic chatbridge components are within the support range, including:
Expand All @@ -27,12 +43,51 @@ But the basic chatbridge components are within the support range, including:
- CLI server
- MCDR plugin

## 免责声明

ChatBridge 是一个为 TIS 服务器定制使用的工具,尤其是 bot/指令相关的组件:

- CQHttp 客户端
- Discord 客户端
- Kaiheila 客户端
- Online 指令客户端
- ...

因此,对于这些 bot 及相关的客户端:

- 代码中将会包含若干硬编码常量,缺乏相关的文档/用法等支持
- 功能方面的 PR 不会被接受,相关的 issue 大概率会被忽略,没有售后
- 如果你想要更多的功能,建议你去 fork 这个仓库,然后自己实现

但基本的 ChatBridge 组件都是在支持范围内,这包括:

- CLI 客户端
- CLI 服务端
- MCDR 插件

## Usage

Enter `python ChatBridge.pyz` in command line to see possible helps

At launch, if the configure file is missing, chatbridge will automatically generate a default one and exit

## Docker Image

[![Docker](https://img.shields.io/docker/v/fallenbreath/chatbridge/latest)](https://hub.docker.com/r/fallenbreath/chatbridge)

Docker Hub image: [`fallenbreath/chatbridge`](https://hub.docker.com/r/fallenbreath/chatbridge)

Image name examples:

- `fallenbreath/chatbridge:latest`
- `fallenbreath/chatbridge:v2.5.3`

Working directory: `/app`

Example usages: `docker run --rm fallenbreath/chatbridge:latest server`

See the [./docker](docker) directory in the repository for more details and docker compose example

## Requirement

Python 3.6+ required
Expand Down Expand Up @@ -94,6 +149,7 @@ Just put the `.pyz` file into the plugin folder
Extra configure fields (compared to [CLI client](#cli-client))

```json5
"enable": true, // for switching the functionality of the chatbridge plugin
"debug": false, // for switching debug logging on
```

Expand All @@ -104,7 +160,7 @@ Extra configure fields (compared to [CLI client](#cli-client))
Extra requirements (also listed in `/chatbridge/impl/discord/requirements.txt`):

```
discord.py
discord.py>=2.0.0
```

Extra configure fields (compared to [CLI client](#cli-client))
Expand Down Expand Up @@ -136,7 +192,6 @@ python ChatBridge.pyz cqhttp_bot
Extra requirements (also listed in `/chatbridge/impl/cqhttp/requirements.txt`):

```
websocket>=0.2.1
websocket-client>=1.2.1
```

Expand All @@ -163,21 +218,47 @@ Extra configure fields (compared to [CLI client](#cli-client))
"server_display_name": "TIS" // The name of the server, used for display in some places
```

## Client as a Satori client

```
python ChatBridge.pyz cqhttp_bot
```

Extra requirements (also listed in `/chatbridge/impl/satori/requirements.txt`):

```
satori-python>=0.11
```

Just like the CoolqHttp client, but it uses satori protocol

Extra configure fields (compared to [CLI client](#cli-client))

```json5
"ws_address": "127.0.0.1", // satori server address
"ws_port": 5500, // satori server port
"ws_path": "", // satori server optional path prefix
"satori_token": "xxxxx", // satori access token
"react_channel_id": 12345, // the target channel id (for QQ, it's the group id)
"chatbridge_message_prefix": "!!qq",
"client_to_query_stats": "MyClient1", // it should be a client as an MCDR plugin, with stats_helper plugin installed in the MCDR
"client_to_query_online": "MyClient2", // a client described in the following section "Client to respond online command"
"server_display_name": "TIS" // The name of the server, used for display in some places
```

## Kaiheila bot client

`python ChatBridge.pyz kaiheila_bot`
`python ChatBridge.pyz satori_bot`

Extra requirements (also listed in `/chatbridge/impl/kaiheila/requirements.txt`):

```
khl.py==0.0.10
khl.py~=0.3.17
```

Extra configure fields (compared to [CLI client](#cli-client))

```json5
"client_id": "", // kaiheila client id
"client_secret": "", // kaiheila client secret
"token": "", // kaiheila token
"channels_for_command": [ // a list of channels, public commands can be used here. use string
"123400000000000000",
Expand Down
8 changes: 7 additions & 1 deletion chatbridge/cli_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def cqhttp_bot():
entry.main()


def satori_bot():
from chatbridge.impl.satori import entry
entry.main()


def online_command():
from chatbridge.impl.online import entry
entry.main()
Expand All @@ -49,6 +54,7 @@ def main():
print('{} server: Start the ChatBridge server'.format(prefix))
print('{} discord_bot: Start a Discord bot as client'.format(prefix))
print('{} cqhttp_bot: Start a CQ-Http bot as client'.format(prefix))
print('{} satori_bot: Start a Satori bot as client'.format(prefix))
print('{} kaiheila_bot: Start a Kaiheila bot as client'.format(prefix))
print('{} online_command: Start a CQ-Http bot as client'.format(prefix))
print('{} online_command: Start a OnlineCommand bot as client'.format(prefix))

7 changes: 6 additions & 1 deletion chatbridge/common/serializer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from typing import TypeVar, Type

from mcdreforged.api.utils.serializer import Serializable

Self = TypeVar('Self', bound='NoMissingFieldSerializable')


class NoMissingFieldSerializable(Serializable):
@classmethod
def deserialize(cls, data: dict, **kwargs):
def deserialize(cls: Type[Self], data: dict, **kwargs) -> Self:
kwargs.setdefault('error_at_missing', True)
# noinspection PyTypeChecker
return super().deserialize(data, **kwargs)

@classmethod
Expand Down
Loading