Skip to content

Commit

Permalink
1、消息格式修改:
Browse files Browse the repository at this point in the history
链接、关键词、分组、时间后面的内容都加粗显示
2、命令结构优化:
主菜单只保留四个命令:
/start - 开始使用并查看帮助
/stats - 查看推送统计
/view - 查看类命令合集
/edit - 编辑类命令合集
查看类命令(通过 /view 访问):
查看当前配置
查看推送统计
列出所有RSS订阅
4. 获取当前版本信息
编辑类命令(通过 /edit 访问):
添加RSS订阅
编辑RSS订阅
删除RSS订阅
向所有订阅添加关键词
从所有订阅删除关键词
  • Loading branch information
3377 committed Dec 17, 2024
1 parent 67a290a commit 34148ef
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 116 deletions.
111 changes: 51 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
## [English](#english-version) | [简体中文](#rss-to-telegram-bot-使用文档)

#
>
> [!TIP]
> ***简称rss2tg,用于将自定义RSS地址,字段,刷新时间里的相关帖子即时发送到自定义TG用户或频道,省去你刷帖子的时间*** <br>
> ***支持AMD64/ARM64*** <br>
> ***镜像大小17M,内存占用10M*** <br>
> **——By [drfyup](https://hstz.com)**
>

> [!TIP] > **_简称 rss2tg,用于将自定义 RSS 地址,字段,刷新时间里的相关帖子即时发送到自定义 TG 用户或频道,省去你刷帖子的时间_** <br> > **_支持 AMD64/ARM64_** <br> > **_镜像大小 17M,内存占用 10M_** <br> > **——By [drfyup](https://hstz.com)**
#

## 1. 部署方法
Expand All @@ -28,16 +24,16 @@ git clone https://github.com/3377/rss2tg.git

4. 编辑 `docker-compose.yml` 文件,修改环境变量:

-- 进入任意目录或直接当前目录,新建docker-compose.yml文件,填入以下内容
-- 进入任意目录或直接当前目录,新建 docker-compose.yml 文件,填入以下内容

```yaml
version: '3'
version: "3"
services:
rss2tg:
container_name: rss2tg
image: drfyup/rss2tg:latest
volumes:
- ./config:/app/config
- ./config/config.yaml:/app/config/config.yaml
- ./data:/app/data
environment:
- TELEGRAM_BOT_TOKEN=your_bot_token_here
Expand Down Expand Up @@ -67,15 +63,15 @@ docker pull drfyup/rss2tg:latest

```yaml
docker run -d \
--name rss2tg \
-v $(pwd)/config:/app/config \
-v $(pwd)/data:/app/data \
-e TELEGRAM_BOT_TOKEN=your_bot_token_here \
-e TELEGRAM_USERS=user_id_1,user_id_2 \
-e TELEGRAM_CHANNELS=@channel_1,@channel_2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
drfyup/rss2tg:latest
--name rss2tg \
-v $(pwd)/config:/app/config \
-v $(pwd)/data:/app/data \
-e TELEGRAM_BOT_TOKEN=your_bot_token_here \
-e TELEGRAM_USERS=user_id_1,user_id_2 \
-e TELEGRAM_CHANNELS=@channel_1,@channel_2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
drfyup/rss2tg:latest
```

请替换环境变量中的相应值。
Expand Down Expand Up @@ -138,28 +134,28 @@ Bot 支持以下命令:

#### 方式二

在当前config目录下新建config.ymal,填入以下内容。
在当前 config 目录下新建 config.ymal,填入以下内容。

```yaml
rss:
- url: https://rss.nodeseek.com
interval: 30
keywords:
- vps
- 甲骨文
- 免费
group: NS论坛
- url: https://linux.do/latest.rss
interval: 30
keywords:
- vps
- 甲骨文
- 免费
- 龟壳
group: LC论坛
- url: https://rss.nodeseek.com
interval: 30
keywords:
- vps
- 甲骨文
- 免费
group: NS论坛
- url: https://linux.do/latest.rss
interval: 30
keywords:
- vps
- 甲骨文
- 免费
- 龟壳
group: LC论坛
```

***两种方式都可以,系统会每1分钟自动检测,即使动态更改生效。***
**_两种方式都可以,系统会每 1 分钟自动检测,即使动态更改生效。_**

### 2.4 编辑 RSS 订阅

Expand Down Expand Up @@ -204,13 +200,14 @@ docker logs rss2tg
![image](https://github.com/user-attachments/assets/4e9ac180-5eb1-40a8-98e1-03b9fa68b691)

# English Version

# RSS to Telegram Bot usage documentation

#
> [!TIP]
>*** Referred to as rss2tg, it is used to instantly send related posts in custom RSS addresses, fields, and refresh times to custom TG users or channels, eliminating the time for you to swipe posts.*** <br>
>*** Support AMD64/ARM64*** <br>
>*** Image size 17M, memory footprint 10M*** <br>
> **——By [drfyup](https://hstz.com)**

> [!TIP] >**_ Referred to as rss2tg, it is used to instantly send related posts in custom RSS addresses, fields, and refresh times to custom TG users or channels, eliminating the time for you to swipe posts._** <br> >**_ Support AMD64/ARM64_** <br> >**_ Image size 17M, memory footprint 10M_** <br>
> **——By [drfyup](https://hstz.com)**

#

## 1. Deployment method
Expand All @@ -232,7 +229,7 @@ git clone https://github.com/3377/rss2tg.git
-- Enter any directory or directly the current directory and create a new docker-compose.yml file, fill in the following content

```yaml
version: '3'
version: "3"
services:
rss2tg:
container_name: rss2tg
Expand Down Expand Up @@ -268,15 +265,15 @@ docker pull drfyup/rss2tg:latest

```yaml
docker run -d \
--name rss2tg \
-v $(pwd)/config:/app/config \
-v $(pwd)/data:/app/data \
-e TELEGRAM_BOT_TOKEN=your_bot_token_here \
-e TELEGRAM_USERS=user_id_1,user_id_2 \
-e TELEGRAM_CHANNELS=@channel_1,@channel_2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
drfyup/rss2tg:latest
--name rss2tg \
-v $(pwd)/config:/app/config \
-v $(pwd)/data:/app/data \
-e TELEGRAM_BOT_TOKEN=your_bot_token_here \
-e TELEGRAM_USERS=user_id_1,user_id_2 \
-e TELEGRAM_CHANNELS=@channel_1,@channel_2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
drfyup/rss2tg:latest
```

Please replace the corresponding value in the environment variable.
Expand Down Expand Up @@ -318,14 +315,7 @@ rss:

The Bot supports the following commands:

-`/start`-Start using the robot
-`/help`-Get help information
-`/config`-View current configuration
-`/add`-add RSS subscription
-`/edit`-edit RSS feed
-`/delete`-delete RSS feed
-`/list`-list all RSS feeds
-`/statistics`-View push statistics
-`/start`-Start using the robot -`/help`-Get help information -`/config`-View current configuration -`/add`-add RSS subscription -`/edit`-edit RSS feed -`/delete`-delete RSS feed -`/list`-list all RSS feeds -`/statistics`-View push statistics

### 2.3 Add RSS feed

Expand Down Expand Up @@ -359,7 +349,8 @@ rss:
-Turtle shell
group: LC Forum
```
***Both methods are possible, the system will automatically detect every 1 minute, even if the dynamic changes take effect.***

**_Both methods are possible, the system will automatically detect every 1 minute, even if the dynamic changes take effect._**

### 2.4 Edit RSS feed

Expand Down
Binary file added README.pdf
Binary file not shown.
137 changes: 82 additions & 55 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ func (b *Bot) Start() {
log.Println("机器人已启动")

commands := []tgbotapi.BotCommand{
{Command: "start", Description: "开始使用机器人并查看帮助信息"},
{Command: "config", Description: "查看当前配置"},
{Command: "add", Description: "添加RSS订阅"},
{Command: "add_all", Description: "向所有订阅添加关键词"},
{Command: "del_all", Description: "从所有订阅删除关键词"},
{Command: "edit", Description: "编辑RSS订阅"},
{Command: "delete", Description: "删除RSS订阅"},
{Command: "list", Description: "列出所有RSS订阅"},
{Command: "stats", Description: "查看推送统计"},
{Command: "version", Description: "获取当前版本信息"},
{Command: "start", Description: "开始/帮助"},
{Command: "view", Description: "查看类命令"},
{Command: "edit", Description: "编辑类命令"},
{Command: "stats", Description: "推送统计"},
}

setMyCommandsConfig := tgbotapi.NewSetMyCommands(commands...)
Expand All @@ -106,24 +100,12 @@ func (b *Bot) Start() {
switch update.Message.Command() {
case "start":
b.handleStart(chatID)
case "config":
b.handleConfig(chatID)
case "add":
b.handleAdd(chatID, userID)
case "add_all":
b.handleAddAll(chatID, userID)
case "del_all":
b.handleDelAll(chatID, userID)
case "edit":
b.handleEdit(chatID, userID)
case "delete":
b.handleDelete(chatID, userID)
case "list":
b.handleList(chatID)
case "stats":
b.handleStats(chatID)
case "version":
b.handleVersion(chatID)
case "view":
b.handleView(chatID, userID)
case "edit":
b.handleEdit(chatID, userID)
default:
b.sendMessage(chatID, "未知命令,请使用 /start 查看可用命令。")
}
Expand All @@ -143,7 +125,7 @@ func (b *Bot) SendMessage(title, url, group string, pubDate time.Time, matchedKe
boldKeywords[i] = "*#" + keyword + "*"
}

text := fmt.Sprintf("*%s*\n\n*🌐 链接:*%s\n\n*🔍 关键词:*%s\n\n*🏷️ 分组:*%s\n\n*🕒 时间:*%s",
text := fmt.Sprintf("*%s*\n\n🌐 链接:*%s*\n\n🔍 关键词:*%s*\n\n🏷️ 分组:*%s*\n\n🕒 时间:*%s*",
title,
url,
strings.Join(boldKeywords, " "),
Expand Down Expand Up @@ -187,40 +169,54 @@ func (b *Bot) reloadConfig() error {
}

func (b *Bot) handleStart(chatID int64) {
// 更新命令列表
commands := []tgbotapi.BotCommand{
{Command: "start", Description: "开始使用机器人并查看帮助信息"},
{Command: "config", Description: "查看当前配置"},
{Command: "add", Description: "添加RSS订阅"},
{Command: "add_all", Description: "向所有订阅添加关键词"},
{Command: "del_all", Description: "从所有订阅删除关键词"},
{Command: "edit", Description: "编辑RSS订阅"},
{Command: "delete", Description: "删除RSS订阅"},
{Command: "list", Description: "列出所有RSS订阅"},
{Command: "stats", Description: "查看推送统计"},
{Command: "version", Description: "获取当前版本信息"},
}

setMyCommandsConfig := tgbotapi.NewSetMyCommands(commands...)
if _, err := b.api.Request(setMyCommandsConfig); err != nil {
log.Printf("更新命令列表失败: %v", err)
}

helpText := `欢迎使用RSS订阅机器人!
可用命令:
/config - 查看当前配置
/add - 添加RSS订阅
/add_all - 向所有订阅添加关键词
/del_all - 从所有订阅删除关键词
/edit - 编辑RSS订阅
/delete - 删除RSS订阅
/list - 列出所有RSS订阅
主要命令:
/start - 开始使用机器人并查看帮助信息
/stats - 查看推送统计
/version - 获取当前版本信息`
/view - 查看类命令合集
/edit - 编辑类命令合集
查看类命令(使用 /view 选择):
1 - 查看当前配置
2 - 查看推送统计
3 - 列出所有RSS订阅
4 - 获取当前版本信息
编辑类命令(使用 /edit 选择):
1 - 添加RSS订阅
2 - 编辑RSS订阅
3 - 删除RSS订阅
4 - 向所有订阅添加关键词
5 - 从所有订阅删除关键词`
b.sendMessage(chatID, helpText)
}

func (b *Bot) handleView(chatID int64, userID int64) {
text := `请选择要执行的查看命令:
1 - 查看当前配置
2 - 查看推送统计
3 - 列出所有RSS订阅
4 - 获取当前版本信息
请输入命令编号(1-4):`
b.userState[userID] = "view_command"
b.sendMessage(chatID, text)
}

func (b *Bot) handleEdit(chatID int64, userID int64) {
text := `请选择要执行的编辑命令:
1 - 添加RSS订阅
2 - 编辑RSS订阅
3 - 删除RSS订阅
4 - 向所有订阅添加关键词
5 - 从所有订阅删除关键词
请输入命令编号(1-5):`
b.userState[userID] = "edit_command"
b.sendMessage(chatID, text)
}

func (b *Bot) handleConfig(chatID int64) {
if err := b.reloadConfig(); err != nil {
b.sendMessage(chatID, "加载配置时出错:" + err.Error())
Expand Down Expand Up @@ -268,6 +264,37 @@ func (b *Bot) handleUserInput(message *tgbotapi.Message) {
text := message.Text

switch b.userState[userID] {
case "view_command":
switch text {
case "1":
b.handleConfig(chatID)
case "2":
b.handleStats(chatID)
case "3":
b.handleList(chatID)
case "4":
b.handleVersion(chatID)
default:
b.sendMessage(chatID, "无效的命令编号,请使用 /view 重新选择。")
}
delete(b.userState, userID)
case "edit_command":
switch text {
case "1":
b.handleAdd(chatID, userID)
case "2":
b.handleEdit(chatID, userID)
case "3":
b.handleDelete(chatID, userID)
case "4":
b.handleAddAll(chatID, userID)
case "5":
b.handleDelAll(chatID, userID)
default:
b.sendMessage(chatID, "无效的命令编号,请使用 /edit 重新选择。")
delete(b.userState, userID)
return
}
case "add_url":
b.userState[userID] = "add_interval"
b.config.RSS = append(b.config.RSS, struct {
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.1-24.12.17
2.1-24.12.18

0 comments on commit 34148ef

Please sign in to comment.