mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
fix: ignore non-command telegram group messages
This commit is contained in:
@@ -238,7 +238,7 @@ mkdir -p data cache media downloads
|
||||
```bash
|
||||
cat > .env <<'EOF'
|
||||
# 固定版本;需要升级时改成新的 MediaStationGo-vX.Y.Z 后执行 docker compose pull && docker compose up -d
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
MEDIASTATION_HTTP_PORT=18080
|
||||
|
||||
# 程序数据和缓存建议放在 MediaStationGo 部署目录下,便于备份和迁移。
|
||||
@@ -307,7 +307,7 @@ vim docker-compose.yml
|
||||
#
|
||||
# 镜像版本:
|
||||
# 默认拉取 latest;如需固定版本,创建 .env 并写入:
|
||||
# MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
# MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
#
|
||||
# 路径映射总览:
|
||||
# /data 程序数据目录。保存 SQLite 数据库、JWT secret、系统配置等,必须持久化。
|
||||
@@ -516,7 +516,7 @@ docker compose up -d
|
||||
|
||||
```bash
|
||||
cat > .env <<'EOF'
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
MEDIASTATION_HTTP_PORT=18080
|
||||
MEDIASTATION_DATA_DIR=./data
|
||||
MEDIASTATION_CACHE_DIR=./cache
|
||||
@@ -779,26 +779,26 @@ cd MediaStationGo
|
||||
|
||||
| 平台 | 包名示例 |
|
||||
| --- | --- |
|
||||
| Linux x86_64 | `MediaStationGo-v0.0.25-linux-amd64.tar.gz` |
|
||||
| Linux ARM64 | `MediaStationGo-v0.0.25-linux-arm64.tar.gz` |
|
||||
| Windows x86_64 | `MediaStationGo-v0.0.25-windows-amd64.zip` |
|
||||
| macOS Intel | `MediaStationGo-v0.0.25-darwin-amd64.tar.gz` |
|
||||
| macOS Apple Silicon | `MediaStationGo-v0.0.25-darwin-arm64.tar.gz` |
|
||||
| Linux x86_64 | `MediaStationGo-v0.0.26-linux-amd64.tar.gz` |
|
||||
| Linux ARM64 | `MediaStationGo-v0.0.26-linux-arm64.tar.gz` |
|
||||
| Windows x86_64 | `MediaStationGo-v0.0.26-windows-amd64.zip` |
|
||||
| macOS Intel | `MediaStationGo-v0.0.26-darwin-amd64.tar.gz` |
|
||||
| macOS Apple Silicon | `MediaStationGo-v0.0.26-darwin-arm64.tar.gz` |
|
||||
|
||||
部署步骤:
|
||||
|
||||
```bash
|
||||
# Linux 示例
|
||||
tar -xzf MediaStationGo-v0.0.25-linux-amd64.tar.gz
|
||||
cd MediaStationGo-v0.0.25-linux-amd64
|
||||
tar -xzf MediaStationGo-v0.0.26-linux-amd64.tar.gz
|
||||
cd MediaStationGo-v0.0.26-linux-amd64
|
||||
MEDIASTATION_APP_PORT=18080 ./mediastation-go
|
||||
```
|
||||
|
||||
Windows:
|
||||
|
||||
```powershell
|
||||
Expand-Archive .\MediaStationGo-v0.0.25-windows-amd64.zip
|
||||
cd .\MediaStationGo-v0.0.25-windows-amd64
|
||||
Expand-Archive .\MediaStationGo-v0.0.26-windows-amd64.zip
|
||||
cd .\MediaStationGo-v0.0.26-windows-amd64
|
||||
$env:MEDIASTATION_APP_PORT = "18080"
|
||||
.\mediastation-go.exe
|
||||
```
|
||||
|
||||
+11
-11
@@ -235,7 +235,7 @@ mkdir -p data cache media downloads
|
||||
|
||||
```bash
|
||||
cat > .env <<'EOF'
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
MEDIASTATION_HTTP_PORT=18080
|
||||
MEDIASTATION_DATA_DIR=./data
|
||||
MEDIASTATION_CACHE_DIR=./cache
|
||||
@@ -344,7 +344,7 @@ For production, pin a specific release tag instead of using `latest`. Recommende
|
||||
|
||||
```bash
|
||||
cat > .env <<'EOF'
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
MEDIASTATION_HTTP_PORT=18080
|
||||
MEDIASTATION_DATA_DIR=./data
|
||||
MEDIASTATION_CACHE_DIR=./cache
|
||||
@@ -593,25 +593,25 @@ Each release provides multi-platform archives:
|
||||
|
||||
| Platform | Package example |
|
||||
| --- | --- |
|
||||
| Linux x86_64 | `MediaStationGo-v0.0.25-linux-amd64.tar.gz` |
|
||||
| Linux ARM64 | `MediaStationGo-v0.0.25-linux-arm64.tar.gz` |
|
||||
| Windows x86_64 | `MediaStationGo-v0.0.25-windows-amd64.zip` |
|
||||
| macOS Intel | `MediaStationGo-v0.0.25-darwin-amd64.tar.gz` |
|
||||
| macOS Apple Silicon | `MediaStationGo-v0.0.25-darwin-arm64.tar.gz` |
|
||||
| Linux x86_64 | `MediaStationGo-v0.0.26-linux-amd64.tar.gz` |
|
||||
| Linux ARM64 | `MediaStationGo-v0.0.26-linux-arm64.tar.gz` |
|
||||
| Windows x86_64 | `MediaStationGo-v0.0.26-windows-amd64.zip` |
|
||||
| macOS Intel | `MediaStationGo-v0.0.26-darwin-amd64.tar.gz` |
|
||||
| macOS Apple Silicon | `MediaStationGo-v0.0.26-darwin-arm64.tar.gz` |
|
||||
|
||||
Linux example:
|
||||
|
||||
```bash
|
||||
tar -xzf MediaStationGo-v0.0.25-linux-amd64.tar.gz
|
||||
cd MediaStationGo-v0.0.25-linux-amd64
|
||||
tar -xzf MediaStationGo-v0.0.26-linux-amd64.tar.gz
|
||||
cd MediaStationGo-v0.0.26-linux-amd64
|
||||
MEDIASTATION_APP_PORT=18080 ./mediastation-go
|
||||
```
|
||||
|
||||
Windows example:
|
||||
|
||||
```powershell
|
||||
Expand-Archive .\MediaStationGo-v0.0.25-windows-amd64.zip
|
||||
cd .\MediaStationGo-v0.0.25-windows-amd64
|
||||
Expand-Archive .\MediaStationGo-v0.0.26-windows-amd64.zip
|
||||
cd .\MediaStationGo-v0.0.26-windows-amd64
|
||||
$env:MEDIASTATION_APP_PORT = "18080"
|
||||
.\mediastation-go.exe
|
||||
```
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
#
|
||||
# 镜像版本:
|
||||
# 默认拉取 latest;如需固定版本,创建 .env 并写入:
|
||||
# MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.25
|
||||
# MEDIASTATION_IMAGE_TAG=MediaStationGo-v0.0.26
|
||||
#
|
||||
# 路径映射总览:
|
||||
# /data 程序数据目录。保存 SQLite 数据库、JWT secret、系统配置等,必须持久化。
|
||||
|
||||
@@ -96,3 +96,18 @@ func TestTelegramProxyCandidatesDefaultLocalFallbacks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTelegramCommandFiltering(t *testing.T) {
|
||||
if telegramIsCommandText("今天看什么") {
|
||||
t.Fatal("plain chat message should not be treated as command")
|
||||
}
|
||||
if !telegramIsCommandText("/start user pass") {
|
||||
t.Fatal("/start should be treated as command")
|
||||
}
|
||||
if got := telegramCommandName("/hideadult@MediaStationGoBot on"); got != "/hideadult" {
|
||||
t.Fatalf("telegramCommandName = %q, want /hideadult", got)
|
||||
}
|
||||
if telegramSupportedCommand("/签到") {
|
||||
t.Fatal("unrelated group bot command should not be handled")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,12 @@ func (s *TelegramBotService) HandleWebhook(ctx context.Context, body []byte) err
|
||||
|
||||
msg := update.Message
|
||||
text := strings.TrimSpace(msg.Text)
|
||||
if !telegramIsCommandText(text) {
|
||||
return nil
|
||||
}
|
||||
if msg.Chat.Type != "" && msg.Chat.Type != "private" && !telegramSupportedCommand(telegramCommandName(text)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.log.Info("telegram command received",
|
||||
zap.Int("chat_id", msg.Chat.ID),
|
||||
@@ -150,7 +156,7 @@ func (s *TelegramBotService) executeCommand(ctx context.Context, channel *model.
|
||||
return telegramCommandReply{}, nil
|
||||
}
|
||||
|
||||
cmd := strings.ToLower(parts[0])
|
||||
cmd := telegramCommandName(parts[0])
|
||||
args := parts[1:]
|
||||
if msg.Chat.Type != "" && msg.Chat.Type != "private" && !s.telegramChatAllowed(channel, msg.Chat.ID) {
|
||||
return telegramCommandReply{Text: "此群组/频道未绑定到 Bot 管理入口,请在通知渠道里填写「绑定群组 ID」或「绑定频道 ID」。"}, nil
|
||||
@@ -188,6 +194,34 @@ func (s *TelegramBotService) executeCommand(ctx context.Context, channel *model.
|
||||
}
|
||||
}
|
||||
|
||||
func telegramIsCommandText(text string) bool {
|
||||
return strings.HasPrefix(strings.TrimSpace(text), "/") && telegramCommandName(text) != ""
|
||||
}
|
||||
|
||||
func telegramCommandName(text string) string {
|
||||
parts := strings.Fields(strings.TrimSpace(text))
|
||||
if len(parts) == 0 {
|
||||
return ""
|
||||
}
|
||||
cmd := strings.ToLower(strings.TrimSpace(parts[0]))
|
||||
if !strings.HasPrefix(cmd, "/") {
|
||||
return ""
|
||||
}
|
||||
if at := strings.Index(cmd, "@"); at > 0 {
|
||||
cmd = cmd[:at]
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func telegramSupportedCommand(cmd string) bool {
|
||||
switch cmd {
|
||||
case "/start", "/help", "/hideadult", "/hide_adult", "/adult", "/status", "/search", "/downloads", "/stats":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// cmdStart 处理 /start 命令。
|
||||
func (s *TelegramBotService) cmdStart(ctx context.Context, msg *TelegramMessage, args []string) telegramCommandReply {
|
||||
name := msg.From.FirstName
|
||||
|
||||
Reference in New Issue
Block a user