Skip to content

Commit

Permalink
Fix tbot deprecated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iovxw committed Nov 2, 2020
1 parent 44175b5 commit 3146dd3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
19 changes: 11 additions & 8 deletions src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use std::sync::{
};

use futures::{future::FutureExt, select_biased};
use tbot::{
types::parameters::{self, WebPagePreviewState},
Bot,
};
use tbot::{types::parameters, Bot};
use tokio::{
self,
stream::StreamExt,
Expand Down Expand Up @@ -82,7 +79,13 @@ async fn fetch_and_push_updates(
title = Escape(&feed.title),
error = Escape(&e.to_user_friendly())
);
push_updates(&bot, &db, feed.subscribers, parameters::Text::html(&msg)).await?;
push_updates(
&bot,
&db,
feed.subscribers,
parameters::Text::with_html(&msg),
)
.await?;
}
return Ok(());
}
Expand Down Expand Up @@ -111,7 +114,7 @@ async fn fetch_and_push_updates(
&bot,
&db,
feed.subscribers.iter().copied(),
parameters::Text::html(&msg),
parameters::Text::with_html(&msg),
)
.await?;
}
Expand All @@ -127,7 +130,7 @@ async fn fetch_and_push_updates(
&bot,
&db,
feed.subscribers.iter().copied(),
parameters::Text::html(&msg),
parameters::Text::with_html(&msg),
)
.await?;
}
Expand All @@ -147,7 +150,7 @@ async fn push_updates<I: IntoIterator<Item = i64>>(
'retry: for _ in 0..3 {
match bot
.send_message(tbot::types::chat::Id(subscriber), msg)
.web_page_preview(WebPagePreviewState::Disabled)
.is_web_page_preview_disabled(true)
.call()
.await
{
Expand Down
60 changes: 31 additions & 29 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use either::Either;
use pinyin::{Pinyin, ToPinyin};
use tbot::{
contexts::{Command, Text},
types::{
input_file,
parameters::{self, WebPagePreviewState},
},
types::{input_file, parameters},
Bot,
};

Expand Down Expand Up @@ -40,7 +37,7 @@ pub async fn check_command(opt: &crate::Opt, cmd: Arc<Command<Text>>) -> bool {
Channel { .. } => {
let msg = tr!("commands_in_private_channel");
let _ignore_result =
update_response(&cmd.bot, target, parameters::Text::plain(&msg)).await;
update_response(&cmd.bot, target, parameters::Text::with_plain(&msg)).await;
return false;
}
// Restrict mode: bot commands are only accessible to admins.
Expand All @@ -55,7 +52,7 @@ pub async fn check_command(opt: &crate::Opt, cmd: Arc<Command<Text>>) -> bool {
let _ignore_result = update_response(
&cmd.bot,
target,
parameters::Text::plain(tr!("group_admin_only_command")),
parameters::Text::with_plain(tr!("group_admin_only_command")),
)
.await;
}
Expand Down Expand Up @@ -94,7 +91,7 @@ pub async fn start(
) -> Result<(), tbot::errors::MethodCall> {
let target = &mut MsgTarget::new(cmd.chat.id, cmd.message_id);
let msg = tr!("start_message");
update_response(&cmd.bot, target, parameters::Text::markdown(&msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_markdown(&msg)).await?;
Ok(())
}

Expand Down Expand Up @@ -142,12 +139,12 @@ pub async fn rss(

let mut prev_msg = cmd.message_id;
for msg in msgs {
let text = parameters::Text::html(&msg);
let text = parameters::Text::with_html(&msg);
let msg = cmd
.bot
.send_message(chat_id, text)
.reply_to_message_id(prev_msg)
.web_page_preview(WebPagePreviewState::Disabled)
.in_reply_to(prev_msg)
.is_web_page_preview_disabled(true)
.call()
.await?;
prev_msg = msg.id;
Expand Down Expand Up @@ -179,29 +176,29 @@ pub async fn sub(
}
[..] => {
let msg = tr!("sub_how_to_use");
update_response(&cmd.bot, target, parameters::Text::plain(&msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_plain(&msg)).await?;
return Ok(());
}
};
if db.lock().unwrap().is_subscribed(target_id.0, feed_url) {
update_response(
&cmd.bot,
target,
parameters::Text::plain(tr!("subscribed_to_rss")),
parameters::Text::with_plain(tr!("subscribed_to_rss")),
)
.await?;
return Ok(());
}

if cfg!(feature = "hosted-by-iovxw") && db.lock().unwrap().all_feeds().len() >= 1500 {
let msg = tr!("subscription_rate_limit");
update_response(&cmd.bot, target, parameters::Text::markdown(msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_markdown(msg)).await?;
return Ok(());
}
update_response(
&cmd.bot,
target,
parameters::Text::plain(tr!("processing_please_wait")),
parameters::Text::with_plain(tr!("processing_please_wait")),
)
.await?;
let msg = match pull_feed(feed_url).await {
Expand All @@ -218,7 +215,7 @@ pub async fn sub(
}
Err(e) => tr!("subscription_failed", error = Escape(&e.to_user_friendly())),
};
update_response(&cmd.bot, target, parameters::Text::html(&msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_html(&msg)).await?;
Ok(())
}

Expand Down Expand Up @@ -246,7 +243,7 @@ pub async fn unsub(
}
[..] => {
let msg = tr!("unsub_how_to_use");
update_response(&cmd.bot, target, parameters::Text::plain(&msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_plain(&msg)).await?;
return Ok(());
}
};
Expand All @@ -259,7 +256,7 @@ pub async fn unsub(
} else {
tr!("unsubscribed_from_rss").into()
};
update_response(&cmd.bot, target, parameters::Text::html(&msg)).await?;
update_response(&cmd.bot, target, parameters::Text::with_html(&msg)).await?;
Ok(())
}

Expand All @@ -286,7 +283,7 @@ pub async fn export(
update_response(
&cmd.bot,
target,
parameters::Text::plain(tr!("subscription_list_empty")),
parameters::Text::with_plain(tr!("subscription_list_empty")),
)
.await?;
return Ok(());
Expand All @@ -296,9 +293,9 @@ pub async fn export(
cmd.bot
.send_document(
chat_id,
input_file::Document::bytes("feeds.opml", opml.as_bytes()),
input_file::Document::with_bytes("feeds.opml", opml.as_bytes()),
)
.reply_to_message_id(cmd.message_id)
.in_reply_to(cmd.message_id)
.call()
.await?;
Ok(())
Expand All @@ -311,13 +308,13 @@ async fn update_response(
) -> Result<(), tbot::errors::MethodCall> {
let msg = if target.first_time {
bot.send_message(target.chat_id, message)
.reply_to_message_id(target.message_id)
.web_page_preview(WebPagePreviewState::Disabled)
.in_reply_to(target.message_id)
.is_web_page_preview_disabled(true)
.call()
.await?
} else {
bot.edit_message_text(target.chat_id, target.message_id, message)
.web_page_preview(WebPagePreviewState::Disabled)
.is_web_page_preview_disabled(true)
.call()
.await?
};
Expand All @@ -339,7 +336,7 @@ async fn check_channel_permission(
update_response(
bot,
target,
parameters::Text::plain(tr!("verifying_channel")),
parameters::Text::with_plain(tr!("verifying_channel")),
)
.await?;

Expand All @@ -350,7 +347,7 @@ async fn check_channel_permission(
..
}) => {
let msg = tr!("unable_to_find_target_channel", desc = description);
update_response(bot, target, parameters::Text::plain(&msg)).await?;
update_response(bot, target, parameters::Text::with_plain(&msg)).await?;
return Ok(None);
}
other => other?,
Expand All @@ -359,7 +356,7 @@ async fn check_channel_permission(
update_response(
bot,
target,
parameters::Text::plain(tr!("target_must_be_a_channel")),
parameters::Text::with_plain(tr!("target_must_be_a_channel")),
)
.await?;
return Ok(None);
Expand All @@ -371,7 +368,7 @@ async fn check_channel_permission(
..
}) => {
let msg = tr!("unable_to_get_channel_info", desc = description);
update_response(bot, target, parameters::Text::plain(&msg)).await?;
update_response(bot, target, parameters::Text::with_plain(&msg)).await?;
return Ok(None);
}
other => other?,
Expand All @@ -381,7 +378,7 @@ async fn check_channel_permission(
update_response(
bot,
target,
parameters::Text::plain(tr!("channel_admin_only_command")),
parameters::Text::with_plain(tr!("channel_admin_only_command")),
)
.await?;
return Ok(None);
Expand All @@ -391,7 +388,12 @@ async fn check_channel_permission(
.find(|member| member.user.id == *crate::BOT_ID.get().unwrap())
.is_some();
if !bot_is_admin {
update_response(bot, target, parameters::Text::plain(tr!("make_bot_admin"))).await?;
update_response(
bot,
target,
parameters::Text::with_plain(tr!("make_bot_admin")),
)
.await?;
return Ok(None);
}
Ok(Some(chat.id))
Expand Down

0 comments on commit 3146dd3

Please sign in to comment.