Skip to content

Commit 5efb991

Browse files
author
Liki4
committed
fix: command parsing process
1 parent 881989e commit 5efb991

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ RUST_LOG=DEBUG
55
MEDIA_GROUP_MAPPING_TIMEOUT=86400
66

77
TELOXIDE_TOKEN=<BOT_TOKEN>
8+
# Without `@`, to precisely parse commands
9+
BOT_NAME=xxx_bot
810
# Uncomment TELOXIDE_PROXY to use proxy
911
# TELOXIDE_PROXY=http://127.0.0.1:7890/
1012

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ random 和 generate 的入参逻辑都是一样的
8383

8484
然后参数最后会根据 meme 对应的最大入参量截断,比如你给一个 2 个入参的 meme 发 3 个参数,最后生效的也只是前 2 个
8585

86+
注意!如果要同时使用多张图片,无论是回复还是直接发,都要求把 [Privacy Mode](https://core.telegram.org/bots/features#privacy-mode) 关闭,否则只能取出来第一张图片
87+
8688
## Generator
8789

8890
Rust 版在:https://github.com/MemeCrafters/meme-generator-rs

src/bot/handler/endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub async fn media_group_with_command_handler(bot: Bot, msg: Message) -> Respons
4949
.await;
5050

5151
if let Some(caption) = msg.caption() {
52-
if let Some(cmd) = Command::parse(caption, "").ok() {
52+
if let Some(cmd) = Command::parse(caption, &env::var("BOT_NAME").unwrap()).ok() {
5353
command_handler(bot, msg, cmd).await.ok();
5454
}
5555
}
@@ -61,7 +61,7 @@ pub async fn media_group_with_command_handler(bot: Bot, msg: Message) -> Respons
6161
pub async fn single_photo_with_command_handler(bot: Bot, msg: Message) -> ResponseResult<()> {
6262
tokio::spawn(async move {
6363
if let Some(caption) = msg.caption() {
64-
if let Some(cmd) = Command::parse(caption, "").ok() {
64+
if let Some(cmd) = Command::parse(caption, &env::var("BOT_NAME").unwrap()).ok() {
6565
command_handler(bot, msg, cmd).await.ok();
6666
}
6767
}

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod bot;
22
mod meme;
33

4+
use std::env;
45
use {
56
crate::bot::{
67
bot_init,
@@ -43,7 +44,7 @@ async fn main() {
4344
.branch(
4445
dptree::filter(|msg: Message| {
4546
msg.caption()
46-
.map_or(false, |caption| Command::parse(caption, "").is_ok())
47+
.map_or(false, |caption| Command::parse(caption, &env::var("BOT_NAME").unwrap()).is_ok())
4748
})
4849
.endpoint(media_group_with_command_handler),
4950
)

0 commit comments

Comments
 (0)