Skip to content

Commit

Permalink
fix: detect url in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nanpuyue committed Mar 22, 2024
1 parent 987ec9e commit 80b96f9
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{env, io};
use lazy_static::lazy_static;
use teloxide::net::Download;
use teloxide::prelude::*;
use teloxide::types::{InputFile, MessageEntity, MessageEntityKind, StickerFormat::*};
use teloxide::types::{InputFile, MessageEntityKind, StickerFormat::*};
use teloxide::utils::command::BotCommands;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -120,22 +120,20 @@ impl Command {
} else {
None
}
} else if let Some(
&[MessageEntity {
kind: MessageEntityKind::Url,
offset,
length,
}, ..],
) = message.entities()
{
let url: String = message
.text()
.unwrap_or_default()
.chars()
.skip(offset)
.take(length)
.collect();
link_to_img(&url).await?
} else if let Some(entities) = message.entities() {
let mut buf = None;
for e in entities {
if e.kind == MessageEntityKind::Url {
if let Some(url) = message
.text()
.map(|x| x.chars().skip(e.offset).take(e.length).collect::<String>())
{
buf = link_to_img(&url).await?;
}
break;
}
}
buf
} else {
None
};
Expand Down

0 comments on commit 80b96f9

Please sign in to comment.