5个版本
0.1.4 | 2024年5月23日 |
---|---|
0.1.3 | 2023年9月19日 |
0.1.2 | 2023年8月25日 |
0.1.1 | 2023年5月10日 |
0.1.0 | 2023年4月3日 |
#566 in Web编程
64KB
1.5K SLoC
tgreddit
一个Telegram机器人,可以为您提供您最喜欢的subreddit的顶级帖子的动态。
杀手级功能:无需访问Reddit,因为所有媒体都通过yt-dlp和Telegram的优秀媒体支持嵌入。
由于Reddit的API有速率限制,并且使用yt-dlp
下载视频可能会占用大量资源,因此建议自行托管。最简单的方法是使用包含必要依赖项的预构建docker镜像。
安装
$ cargo install tgreddit
需求
依赖于yt-dlp(并且为了获得良好的结果,yt-dlp需要ffmpeg)。
机器人命令
/sub<subreddit> [limit=<limit>] [time=<time>] [filter=<filter>]
添加订阅以获取subreddit的顶级帖子,可选选项。订阅是会话特定的,可以在机器人参与的频道或与机器人的私人聊天中添加。
如果没有提供选项,当检查新帖子时,程序将默认为config.toml中的配置(如果有)。
示例: /sub AnimalsBeingJerks limit=5 time=week filter=video
说明:订阅r/AnimalsBeingJerks的顶级帖子,以便考虑每周顶级列表的前5个帖子。每当新的帖子出现在这5个顶级帖子中时,它们将发布在会话中。
请参阅下面的示例配置以了解有关limit
、time
和filter
的更多说明。
/unsub<subreddit>
从当前会话中删除订阅。
/listsubs
列出当前会话的所有subreddit订阅。
/get<subreddit> [limit=<limit>] [time=<time>] [filter=<filter>]
获取当前的顶级帖子,类似于订阅subreddit将返回新帖子。
配置
环境变量
CONFIG_PATH
:TOML配置文件的路径。必需RUST_LOG
:日志级别。推荐使用info
以查看有意义的结果。
带有选项解释的示例toml配置
无注释的示例配置:config.example.toml
# Path to a SQLite database used to track seen posts.
# Optional. Defaults to $HOME/.local/state/tgreddit/data.db3.
db_path = "/path/to/data.db3"
# List of Telegram user ids that can use the commands provided by the bot.
authorized_users = [
123123123
]
# Token of your Telegram bot - you get this from @botfather.
telegram_bot_token = "..."
# How often to query each configured subreddit for new posts. Applies only if
# keep_running is enabled.
check_interval_secs = 600
# Whether posts seen on the first check of a new subreddit are considered new
# or not. Generally having this enabled is better unless you want multiple new
# messages when a new subreddit is added.
# Optional. Defaults to true.
skip_initial_send = true
# Set the post comments links to use an alternative frontend. Useful as the
# official Reddit web app is increasingly user hostile on mobile. Possible
# alternative frontends include teddit.net and libredd.it, but you can use any.
# Optional. Defaults to official Reddit.
links_base_url = "https://teddit.net"
# Set default limit of posts to fetch for each subreddit. Used when not
# specified for a subreddit in the /sub command.
#
# Explanation in more detail: Whenever the bot gets the list of top posts for a
# subreddit, it will only consider the first <limit> posts. For example, if
# your limit is 5, the first time around bot will see 5 new posts and mark those
# as seen and not post anything because it's the first check. Next time around, if
# there's an unseen post among those 5 top posts, it will be posted in Telegram.
#
# So essentially larger the number used as limit, the more posts you can
# expect to see. For example, with time=month and limit=1 you would see a new post
# only when the montly top post changes, which is not that often.
#
# Optional. The default is 1.
default_limit = 1
# Set default time period of top list fetched. Used when not specified for a
# subreddit. String and one of: hour, day, week, month, year, all.
# Optional. The default is `day`.
default_time = "day"
# Set default filter for post type. When fetching for new posts, only posts
# matching the filter are considered.
# String and one of: image, video, link, self_text, gallery
# Optional and unset by default, meaning all post types are considered.
default_filter = "video"
确定Telegram频道ID最简单的方法可能是打开频道在Telegram网页客户端中,并观察页面URL中的数字值。
开发
$ just dev
docker镜像
在rainevi/tgreddit中有一个包含依赖项的预构建Docker镜像。
当然,您也可以从Dockerfile构建自己的。
为Raspberry Pi交叉编译
您可以使用Docker容器为Raspberry Pi交叉编译tgreddit。生成的可执行文件将静态链接,应在Raspberry Pi上跨不同的Linux发行版工作。
docker run --rm -it \
-v "$(pwd)":/home/rust/src messense/rust-musl-cross:aarch64-musl \
cargo build --release --target aarch64-unknown-linux-gnu --features vendored-openssl
有想法、问题或错误报告吗?
请随意打开一个问题或开始一个新的讨论。
依赖项
~37–53MB
~1M SLoC