Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,016 changes: 535 additions & 481 deletions Cargo.lock

Large diffs are not rendered by default.

1,050 changes: 566 additions & 484 deletions examples/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/album_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"
log = "0.4"
Expand Down
32 changes: 18 additions & 14 deletions examples/album_bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
//! This is a copy of the repo
//! https://github.com/LasterAlex/AlbumTeloxideBot/blob/main/src/main.rs
use std::collections::HashMap;
use std::error::Error;
use std::sync::{Arc, Mutex};
use std::{
collections::HashMap,
error::Error,
sync::{Arc, Mutex},
};

use dotenv::dotenv;
use teloxide::dispatching::UpdateHandler;
use teloxide::prelude::*;
use teloxide::types::{
InputFile, InputMedia, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo,
UpdateKind,
use teloxide::{
dispatching::UpdateHandler,
prelude::*,
types::{
InputFile, InputMedia, InputMediaAudio, InputMediaDocument, InputMediaPhoto,
InputMediaVideo, UpdateKind,
},
};
use tokio::time::{sleep, Duration};

Expand All @@ -34,7 +38,7 @@ async fn get_album(msg: Message, album: AlbumStorage) -> Option<Vec<Message>> {
.lock()
.unwrap()
.entry(msg.chat.id.to_string())
.or_insert_with(Vec::new) // If there is no entry
.or_default() // If there is no entry
.push(msg.clone());

// Record length
Expand Down Expand Up @@ -101,11 +105,10 @@ async fn main() {
async fn example_handler(bot: Bot, msg: Message, album_mutex: AlbumStorage) -> HandlerResult {
let album = get_album(msg.clone(), album_mutex).await; // Get either all the messages, or
// None, which means that it is not the last message in the album, and we chould return
let album_messages: Vec<Message>; // Uninitialized variable, so that scoping is correct
match album {
Some(album_unwrapped) => album_messages = album_unwrapped,
let album_messages: Vec<Message> = match album {
Some(album_unwrapped) => album_unwrapped,
None => return Ok(()), // If not the last message, return
}
};

// Now we have all the media group messages in the album_messages variable
// And parameter msg is the last message in the album
Expand Down Expand Up @@ -159,10 +162,11 @@ async fn example_handler(bot: Bot, msg: Message, album_mutex: AlbumStorage) -> H

#[cfg(test)]
mod tests {
use super::*;
use teloxide::dptree::deps;
use teloxide_tests::{MockBot, MockMessagePhoto, MockMessageText};

use super::*;

#[tokio::test]
async fn test_get_one_message() {
let mut bot = MockBot::new_with_distribution_function(
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros", "redis-storage", "cbor-serializer"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros", "redis-storage", "cbor-serializer"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
21 changes: 12 additions & 9 deletions examples/calculator_bot/src/handler_tree.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use crate::{get_bot_storage, handlers::*, text, MyDialogue};
use crate::{handlers::StartCommand, State};
use dptree::case;
use std::error::Error;
use teloxide::dispatching::dialogue::GetChatId;
use teloxide::dispatching::UpdateFilterExt;
use teloxide::prelude::*;

use dptree::case;
use teloxide::{
dispatching::{
dialogue::{self, ErasedStorage},
UpdateHandler,
dialogue::{self, ErasedStorage, GetChatId},
UpdateFilterExt, UpdateHandler,
},
prelude::*,
types::Update,
};

use crate::{
get_bot_storage,
handlers::{StartCommand, *},
text, MyDialogue, State,
};

async fn check_if_the_state_is_ok(update: Update) -> bool {
// This function doesn't have anything to do with tests, but i thought i would put it here,
// because i've encountered that if you update the state, and the user is on that
Expand All @@ -32,7 +35,7 @@ async fn check_if_the_state_is_ok(update: Update) -> bool {
.await
.unwrap();
dialogue.update(State::default()).await.unwrap();
return false;
false
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/calculator_bot/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::{text, HandlerResult, MyDialogue, State};
use teloxide::{
dispatching::dialogue::GetChatId,
macros::BotCommands,
prelude::*,
types::{InlineKeyboardButton, InlineKeyboardMarkup},
};

use crate::{text, HandlerResult, MyDialogue, State};

#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase")]
pub enum StartCommand {
Expand Down
7 changes: 4 additions & 3 deletions examples/calculator_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use std::error::Error;

use dotenv::dotenv;
use handler_tree::handler_tree;
use teloxide::dispatching::dialogue::serializer::Cbor;
use teloxide::dispatching::dialogue::{Dialogue, ErasedStorage, RedisStorage, Storage};
use teloxide::prelude::*;
use teloxide::{
dispatching::dialogue::{serializer::Cbor, Dialogue, ErasedStorage, RedisStorage, Storage},
prelude::*,
};

pub type MyDialogue = Dialogue<State, ErasedStorage<State>>;
pub type HandlerResult = Result<(), Box<dyn Error + Send + Sync>>;
Expand Down
4 changes: 2 additions & 2 deletions examples/calculator_bot/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{get_bot_storage, handler_tree::handler_tree, text, State};

use teloxide::dptree::deps;
use teloxide_tests::{MockBot, MockCallbackQuery, MockMessagePhoto, MockMessageText};

use crate::{get_bot_storage, handler_tree::handler_tree, text, State};

#[tokio::test]
async fn test_start() {
let mut bot = MockBot::new(MockMessageText::new().text("/start"), handler_tree());
Expand Down
2 changes: 1 addition & 1 deletion examples/deep_linking_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
10 changes: 5 additions & 5 deletions examples/deep_linking_bot/src/handler_tree.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::handlers::*;
use dptree::case;
use teloxide::dispatching::dialogue::InMemStorage;
use teloxide::dispatching::{dialogue, UpdateFilterExt, UpdateHandler};
use teloxide::prelude::*;
use teloxide::{
dispatching::{dialogue, dialogue::InMemStorage, UpdateFilterExt, UpdateHandler},
prelude::*,
};

use crate::{StartCommand, State};
use crate::{handlers::*, StartCommand, State};

pub fn handler_tree() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
dialogue::enter::<Update, InMemStorage<State>, State, _>()
Expand Down
3 changes: 2 additions & 1 deletion examples/deep_linking_bot/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{add_deep_link, text, HandlerResult, MyDialogue, StartCommand, State};
use teloxide::{prelude::*, types::Me};

use crate::{add_deep_link, text, HandlerResult, MyDialogue, StartCommand, State};

pub async fn start(
bot: Bot,
msg: Message,
Expand Down
6 changes: 3 additions & 3 deletions examples/deep_linking_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pub mod handlers;
pub mod tests;
pub mod text;

use std::error::Error;

use dptree::deps;
use handler_tree::handler_tree;
use std::error::Error;
use teloxide::types::Me;
use teloxide::{dispatching::dialogue::InMemStorage, macros::BotCommands, prelude::*};
use teloxide::{dispatching::dialogue::InMemStorage, macros::BotCommands, prelude::*, types::Me};

pub type MyDialogue = Dialogue<State, InMemStorage<State>>;
pub type HandlerResult = Result<(), Box<dyn Error + Send + Sync>>;
Expand Down
3 changes: 2 additions & 1 deletion examples/deep_linking_bot/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{add_deep_link, handler_tree::handler_tree, text, State};
use teloxide::{dispatching::dialogue::InMemStorage, dptree::deps};
use teloxide_tests::{MockBot, MockMessagePhoto, MockMessageText};

use crate::{add_deep_link, handler_tree::handler_tree, text, State};

#[tokio::test]
async fn test_start() {
// Just a regular start
Expand Down
2 changes: 1 addition & 1 deletion examples/file_download_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"

Expand Down
3 changes: 2 additions & 1 deletion examples/file_download_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ async fn main() {

#[cfg(test)]
mod tests {
use super::*;
use teloxide_tests::{MockBot, MockMessageDocument, MockMessageText};

use super::*;

#[tokio::test]
async fn test_not_a_document() {
let mut bot = MockBot::new(MockMessageText::new().text("Hi!"), handler_tree());
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"

Expand Down
3 changes: 2 additions & 1 deletion examples/hello_world_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ async fn main() {

#[cfg(test)]
mod tests {
use super::*;
use teloxide_tests::{MockBot, MockMessageText};

use super::*;

#[tokio::test]
async fn test_hello_world() {
// This is a message builder. You can check the docs for more info about mocked types
Expand Down
2 changes: 1 addition & 1 deletion examples/phrase_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "94db1757dc96116f4756a586fcbce3ac5ebd0c59", features = ["macros", "redis-storage", "cbor-serializer"] }
teloxide = { git = "https://github.com/teloxide/teloxide.git", rev = "c590976722378a3a02ad5f5dac06b30a4e013395", features = ["macros", "redis-storage", "cbor-serializer"] }
tokio = { version = "1.38", features = ["rt-multi-thread", "macros"] }
dotenv = "0.15.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
3 changes: 1 addition & 2 deletions examples/phrase_bot/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
//! that are used in the bot.
pub mod models;
pub mod schema;
use models::*;

use diesel::prelude::*;
use models::*;

pub fn establish_connection() -> PgConnection {
dotenv::dotenv().ok();
Expand Down
3 changes: 2 additions & 1 deletion examples/phrase_bot/src/db/models.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::schema;
use diesel::prelude::*;
use serde::{Deserialize, Serialize};

use super::schema;

#[derive(Queryable, Selectable)]
#[diesel(table_name = schema::users)]
#[diesel(check_for_backend(diesel::pg::Pg))]
Expand Down
18 changes: 9 additions & 9 deletions examples/phrase_bot/src/handlers/private.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use teloxide::prelude::*;
use teloxide::types::KeyboardRemove;
use teloxide::{macros::BotCommands, payloads::SendMessageSetters};
use teloxide::{
macros::BotCommands, payloads::SendMessageSetters, prelude::*, types::KeyboardRemove,
};

use crate::db::models;
use crate::keyboards::menu_keyboard;
use crate::{db, keyboards, text, HandlerResult, MyDialogue, State};
use crate::{
db, db::models, keyboards, keyboards::menu_keyboard, text, HandlerResult, MyDialogue, State,
};

#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase")]
Expand Down Expand Up @@ -228,13 +228,13 @@ pub async fn added_phrase(

#[cfg(test)]
mod tests {
use crate::{get_bot_storage, handler_tree::handler_tree};

use super::*;
use dptree::deps;
use teloxide::types::ReplyMarkup;
use teloxide_tests::{MockBot, MockMessageDocument, MockMessageText, MockUser};

use super::*;
use crate::{get_bot_storage, handler_tree::handler_tree};

#[tokio::test]
async fn test_start() {
let mut bot = MockBot::new(MockMessageText::new().text("/start"), handler_tree());
Expand Down
3 changes: 2 additions & 1 deletion examples/phrase_bot/src/handlers/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ pub async fn bot_phrase(bot: Bot, msg: Message) -> HandlerResult {

#[cfg(test)]
mod tests {
use crate::{db, handler_tree::handler_tree, text};
use teloxide_tests::{MockBot, MockGroupChat, MockMessageText, MockUser};

use crate::{db, handler_tree::handler_tree, text};

#[tokio::test]
async fn test_phrase() {
let chat = MockGroupChat::new().build();
Expand Down
12 changes: 6 additions & 6 deletions examples/phrase_bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pub mod db;
pub mod handlers;
pub mod resources;
use db::models::Phrase;
use resources::{handler_tree, keyboards, text};

use std::error::Error;

use db::models::Phrase;
use dotenv::dotenv;
use handler_tree::handler_tree;
use handlers::*;
use teloxide::dispatching::dialogue::serializer::Cbor;
use teloxide::dispatching::dialogue::{Dialogue, ErasedStorage, RedisStorage, Storage};
use teloxide::prelude::*;
use resources::{handler_tree, keyboards, text};
use teloxide::{
dispatching::dialogue::{serializer::Cbor, Dialogue, ErasedStorage, RedisStorage, Storage},
prelude::*,
};

pub type MyDialogue = Dialogue<State, ErasedStorage<State>>;
pub type HandlerResult = Result<(), Box<dyn Error + Send + Sync>>;
Expand Down
Loading
Loading