Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jan 12, 2022
1 parent 98855ec commit 85ef148
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ full = [

[dependencies]
#teloxide-core = { version = "0.3.3", default-features = false }
teloxide-core = { git = "https://github.com/teloxide/teloxide-core.git", rev = "dad5d5d", default-features = false }
teloxide-core = { git = "https://github.com/teloxide/teloxide-core.git", rev = "3ccb8f0", default-features = false }
teloxide-macros = { version = "0.4", optional = true }

serde_json = "1.0"
Expand Down
18 changes: 4 additions & 14 deletions examples/admin_bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{error::Error, str::FromStr};

use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use chrono::Duration;
use teloxide::{prelude::*, types::{ChatPermissions, Me}, utils::command::BotCommand};

// Derive BotCommand to parse text with a command into this enumeration.
Expand Down Expand Up @@ -71,14 +71,9 @@ async fn mute_user(cx: &Cx, time: Duration) -> Result<(), Box<dyn Error + Send +
.restrict_chat_member(
cx.update.chat_id(),
msg1.from().expect("Must be MessageKind::Common").id,
ChatPermissions::default(),
)
.until_date(
DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp(cx.update.date as i64, 0),
Utc,
) + time,
ChatPermissions::empty(),
)
.until_date(cx.update.date + time)
.await?;
}
None => {
Expand Down Expand Up @@ -114,12 +109,7 @@ async fn ban_user(cx: &Cx, time: Duration) -> Result<(), Box<dyn Error + Send +
cx.update.chat_id(),
message.from().expect("Must be MessageKind::Common").id,
)
.until_date(
DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp(cx.update.date as i64, 0),
Utc,
) + time,
)
.until_date(cx.update.date + time)
.await?;
}
None => {
Expand Down
6 changes: 2 additions & 4 deletions examples/heroku_ping_pong_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
let server = warp::post()
.and(warp::path(path))
.and(warp::body::json())
.map(move |json: serde_json::Value| {
if let Ok(update) = Update::try_parse(&json) {
tx.send(Ok(update)).expect("Cannot send an incoming update from the webhook")
}
.map(move |update: Update| {
tx.send(Ok(update)).expect("Cannot send an incoming update from the webhook");

StatusCode::OK
})
Expand Down
4 changes: 2 additions & 2 deletions examples/inline_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async fn run() {
))),
)
.description("DuckDuckGo Search")
.thumb_url("https://duckduckgo.com/assets/logo_header.v108.png")
.url("https://duckduckgo.com/about"); // Note: This is the url that will open if they click the thumbnail
.thumb_url("https://duckduckgo.com/assets/logo_header.v108.png".parse().unwrap())
.url("https://duckduckgo.com/about".parse().unwrap()); // Note: This is the url that will open if they click the thumbnail

let results = vec![
InlineQueryResult::Article(google_search),
Expand Down
6 changes: 2 additions & 4 deletions examples/ngrok_ping_pong_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene

let server = warp::post()
.and(warp::body::json())
.map(move |json: serde_json::Value| {
if let Ok(update) = Update::try_parse(&json) {
tx.send(Ok(update)).expect("Cannot send an incoming update from the webhook")
}
.map(move |update: Update| {
tx.send(Ok(update)).expect("Cannot send an incoming update from the webhook");

StatusCode::OK
})
Expand Down

0 comments on commit 85ef148

Please sign in to comment.