upgrade deps

This commit is contained in:
ihciah 2022-12-27 18:57:28 +08:00
parent 956129abee
commit bde7889b55
No known key found for this signature in database
GPG Key ID: A72018B6522333D3
8 changed files with 588 additions and 338 deletions

825
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,14 +8,14 @@ eh2telegraph = {path = "../eh2telegraph"}
anyhow = "1"
chrono = "0.4"
clap = {version = "3", features = ["derive"]}
dptree = "0.2"
clap = {version = "4", features = ["derive"]}
dptree = "0.3"
once_cell = "1"
regex = "1"
reqwest = {version = "0.11", default-features = false, features = ["json", "multipart", "rustls-tls"]}
serde = {version = "1", features = ["derive"]}
singleflight-async = {version = "0.1", features = ["hardware-lock-elision"]}
teloxide = {version = "0.9", features = ["macros", "ctrlc_handler", "auto-send"]}
teloxide = {version = "0.11", features = ["macros", "ctrlc_handler", "auto-send"]}
time = {version = "0.3", features = ["local-offset", "std", "macros"]}
tokio = {version = "1", default-features = false, features = ["rt-multi-thread", "macros", "net", "sync", "time", "parking_lot"]}
tracing = "0.1"

View File

@ -29,7 +29,7 @@ const MIN_SIMILARITY_PRIVATE: u8 = 50;
#[derive(BotCommands, Clone)]
#[command(
rename = "lowercase",
rename_rule = "lowercase",
description = "\
This is a gallery synchronization robot that is convenient for users to view pictures directly in Telegram.\n\
便 Telegram \n\
@ -56,7 +56,7 @@ pub enum Command {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "Command for admins")]
#[command(rename_rule = "lowercase", description = "Command for admins")]
pub enum AdminCommand {
#[command(description = "Delete cache with given key.")]
Delete(String),
@ -89,7 +89,7 @@ where
/// Executed when a command comes in and parsed successfully.
pub async fn respond_cmd(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
command: Command,
) -> ControlFlow<()> {
@ -149,7 +149,7 @@ where
pub async fn respond_admin_cmd(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
command: AdminCommand,
) -> ControlFlow<()> {
@ -167,7 +167,7 @@ where
pub async fn respond_text(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
) -> ControlFlow<()> {
let maybe_link = {
@ -217,7 +217,7 @@ where
pub async fn respond_caption(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
) -> ControlFlow<()> {
let caption_entities = msg.caption_entities();
@ -276,7 +276,7 @@ where
pub async fn respond_photo(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
) -> ControlFlow<()> {
let first_photo = match msg.photo().and_then(|x| x.first()) {
@ -286,9 +286,9 @@ where
}
};
let f = ok_or_break!(bot.get_file(&first_photo.file_id).await);
let mut buf: Vec<u8> = Vec::with_capacity(f.file_size as usize);
ok_or_break!(teloxide::net::Download::download_file(&bot, &f.file_path, &mut buf).await);
let f = ok_or_break!(bot.get_file(&first_photo.file.id).await);
let mut buf: Vec<u8> = Vec::with_capacity(f.size as usize);
ok_or_break!(teloxide::net::Download::download_file(&bot, &f.path, &mut buf).await);
let search_result: SaucenaoOutput = ok_or_break!(self.searcher.search(buf).await);
let mut url_sim = None;
@ -348,7 +348,7 @@ where
pub async fn respond_default(
&'static self,
bot: AutoSend<DefaultParseMode<Bot>>,
bot: DefaultParseMode<Bot>,
msg: Message,
) -> ControlFlow<()> {
if msg.chat.is_private() {

View File

@ -97,29 +97,26 @@ async fn main() {
let handler = Box::leak(Box::new(Handler::new(synchronizer, admins))) as &Handler<_>;
// === Bot related ===
let command_handler = move |bot: AutoSend<DefaultParseMode<Bot>>,
message: Message,
command: Command| async move {
let command_handler = move |bot: DefaultParseMode<Bot>, message: Message, command: Command| async move {
handler.respond_cmd(bot, message, command).await
};
let admin_command_handler = move |bot: AutoSend<DefaultParseMode<Bot>>,
message: Message,
command: AdminCommand| async move {
handler.respond_admin_cmd(bot, message, command).await
};
let text_handler = move |bot: AutoSend<DefaultParseMode<Bot>>, message: Message| async move {
let admin_command_handler =
move |bot: DefaultParseMode<Bot>, message: Message, command: AdminCommand| async move {
handler.respond_admin_cmd(bot, message, command).await
};
let text_handler = move |bot: DefaultParseMode<Bot>, message: Message| async move {
handler.respond_text(bot, message).await
};
let caption_handler = move |bot: AutoSend<DefaultParseMode<Bot>>, message: Message| async move {
let caption_handler = move |bot: DefaultParseMode<Bot>, message: Message| async move {
handler.respond_caption(bot, message).await
};
let photo_handler = move |bot: AutoSend<DefaultParseMode<Bot>>, message: Message| async move {
let photo_handler = move |bot: DefaultParseMode<Bot>, message: Message| async move {
handler.respond_photo(bot, message).await
};
let default_handler = move |bot: AutoSend<DefaultParseMode<Bot>>, message: Message| async move {
let default_handler = move |bot: DefaultParseMode<Bot>, message: Message| async move {
handler.respond_default(bot, message).await
};
let permission_filter = |bot: AutoSend<DefaultParseMode<Bot>>, message: Message| async move {
let permission_filter = |bot: DefaultParseMode<Bot>, message: Message| async move {
// If the bot is blocked, we will leave chat and not respond.
let blocked = message
.chat
@ -148,9 +145,7 @@ async fn main() {
}
};
let bot = Bot::new(base_config.bot_token)
.parse_mode(ParseMode::MarkdownV2)
.auto_send();
let bot = Bot::new(base_config.bot_token).parse_mode(ParseMode::MarkdownV2);
let mut bot_dispatcher = Dispatcher::builder(
bot.clone(),
dptree::entry()
@ -219,14 +214,12 @@ async fn main() {
Box::pin(async {})
}))
.error_handler(std::sync::Arc::new(IgnoringErrorHandler))
.enable_ctrlc_handler()
.build();
bot_dispatcher.setup_ctrlc_handler();
let bot_listener = update_listeners::polling(
bot,
Some(std::time::Duration::from_secs(10)),
None,
Some(vec![AllowedUpdate::Message]),
);
let bot_listener = update_listeners::Polling::builder(bot)
.allowed_updates(vec![AllowedUpdate::Message])
.timeout(std::time::Duration::from_secs(10))
.build();
tracing::info!("initializing finished, bot is running");
bot_dispatcher

View File

@ -8,23 +8,21 @@ impl<'a> std::fmt::Debug for PrettyChat<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0.is_group() || self.0.is_supergroup() {
write!(f, "GroupChat")?;
self.0.title().map(|x| write!(f, " title: {}", x));
self.0
.description()
.map(|x| write!(f, " description: {}", x));
self.0.title().map(|x| write!(f, " title: {x}"));
self.0.description().map(|x| write!(f, " description: {x}"));
} else if self.0.is_private() {
write!(f, "PrivateChat")?;
self.0.username().map(|x| write!(f, " username: @{}", x));
self.0.first_name().map(|x| write!(f, " first_name: {}", x));
self.0.last_name().map(|x| write!(f, " last_name: {}", x));
self.0.bio().map(|x| write!(f, " bio: {}", x));
self.0.username().map(|x| write!(f, " username: @{x}"));
self.0.first_name().map(|x| write!(f, " first_name: {x}"));
self.0.last_name().map(|x| write!(f, " last_name: {x}"));
self.0.bio().map(|x| write!(f, " bio: {x}"));
} else if self.0.is_channel() {
write!(f, "Channel")?;
self.0.username().map(|x| write!(f, " username: @{}", x));
self.0.title().map(|x| write!(f, " title: {}", x));
self.0.username().map(|x| write!(f, " username: @{x}"));
self.0.title().map(|x| write!(f, " title: {x}"));
self.0
.description()
.map(|x| write!(f, ", description: {}", x));
.map(|x| write!(f, ", description: {x}"));
}
Ok(())
}

View File

@ -228,7 +228,7 @@ mod tests {
.fetch("/g/2122174/fd2525031e".to_string())
.await
.unwrap();
println!("album: {:?}", album);
println!("album: {album:?}");
let maybe_first_image = image_stream.next().unwrap().await;
if let Ok((meta, data)) = maybe_first_image {

View File

@ -235,13 +235,13 @@ mod tests {
ipb_member_id: "balabala".to_string(),
igneous: "balabala".to_string(),
};
println!("config {:#?}", config);
println!("config {config:#?}");
let collector = EXCollector::new(&config, ProxiedClient::default()).unwrap();
let (album, mut image_stream) = collector
.fetch("/g/2129939/01a6e086b9".to_string())
.await
.unwrap();
println!("album: {:?}", album);
println!("album: {album:?}");
let maybe_first_image = image_stream.next().unwrap().await;
if let Ok((meta, data)) = maybe_first_image {
@ -258,11 +258,11 @@ mod tests {
ipb_member_id: "balabala".to_string(),
igneous: "balabala".to_string(),
};
println!("config {:#?}", config);
println!("config {config:#?}");
let collector = EXCollector::new(&config, ProxiedClient::default()).unwrap();
let output = collector.fetch("/g/2129939/00000".to_string()).await;
assert!(output.is_err());
println!("output err {:?}", output);
println!("output err {output:?}");
}
#[ignore]

View File

@ -235,7 +235,7 @@ mod tests {
author_url: Some("https://t.co".to_string()),
};
let page = telegraph.create_page(&page).await.unwrap();
println!("test page: {:?}", page);
println!("test page: {page:?}");
}
#[ignore]
@ -279,6 +279,6 @@ mod tests {
author_url: None,
};
let page = telegraph.create_page(&page).await.unwrap();
println!("test page: {:?}", page);
println!("test page: {page:?}");
}
}