mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Merge branch 'dev' into requests_rewrite
This commit is contained in:
commit
81f8ef2575
9 changed files with 117 additions and 24 deletions
71
.github/workflows/ci.yml
vendored
Normal file
71
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
on: [push]
|
||||
|
||||
name: Continuous integration
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: stable/beta build
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'stable' || matrix.rust == 'beta'
|
||||
with:
|
||||
command: build
|
||||
args: --verbose --features ""
|
||||
|
||||
- name: nightly build
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'nightly'
|
||||
with:
|
||||
command: build
|
||||
args: --verbose --all-features
|
||||
|
||||
- name: stable/beta test
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'stable' || matrix.rust == 'beta'
|
||||
with:
|
||||
command: test
|
||||
args: --verbose --features ""
|
||||
|
||||
- name: nightly test
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'nightly'
|
||||
with:
|
||||
command: test
|
||||
args: --verbose --all-features
|
||||
|
||||
- name: fmt
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
- name: stable/beta clippy
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'stable' || matrix.rust == 'beta'
|
||||
with:
|
||||
command: clippy
|
||||
args: --all-targets --features "" -- -D warnings
|
||||
|
||||
- name: nightly clippy
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.rust == 'nightly'
|
||||
with:
|
||||
command: clippy
|
||||
args: --all-targets --all-features -- -D warnings
|
10
.travis.yml
10
.travis.yml
|
@ -1,10 +0,0 @@
|
|||
language: Rust
|
||||
|
||||
|
||||
env:
|
||||
- RUST_BACKTRACE=1
|
||||
|
||||
script:
|
||||
- rustup override set nightly
|
||||
- cargo build --all --verbose
|
||||
- cargo test --all
|
BIN
hw.doc
BIN
hw.doc
Binary file not shown.
|
@ -1,4 +1,6 @@
|
|||
use std::{convert::Infallible, future::Future, pin::Pin};
|
||||
#[cfg(not(feature = "never-type"))]
|
||||
use std::convert::Infallible;
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
|
@ -15,7 +17,7 @@ pub trait ErrorPolicy<E> {
|
|||
/// ## Example
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() {
|
||||
/// # async fn main_() {
|
||||
/// use telebofr::dispatching::dispatchers::filter::error_policy::{
|
||||
/// ErrorPolicy, Ignore,
|
||||
/// };
|
||||
|
@ -45,7 +47,7 @@ where
|
|||
/// ## Examples
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() {
|
||||
/// # async fn main_() {
|
||||
/// use std::convert::{TryInto, Infallible};
|
||||
///
|
||||
/// use telebofr::dispatching::dispatchers::filter::error_policy::{
|
||||
|
@ -89,10 +91,10 @@ impl ErrorPolicy<!> for IgnoreSafe {
|
|||
where
|
||||
!: 'async_trait,
|
||||
{
|
||||
never
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "never-type"))]
|
||||
#[allow(unreachable_code)]
|
||||
#[async_trait]
|
||||
impl ErrorPolicy<Infallible> for IgnoreSafe {
|
||||
|
@ -108,7 +110,7 @@ impl ErrorPolicy<Infallible> for IgnoreSafe {
|
|||
/// ## Example
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() {
|
||||
/// # async fn main_() {
|
||||
/// use telebofr::dispatching::dispatchers::filter::error_policy::ErrorPolicy;
|
||||
///
|
||||
/// let closure = |e: i32| async move { eprintln!("Error code{}", e) };
|
||||
|
|
|
@ -7,7 +7,10 @@ use crate::{
|
|||
dispatchers::filter::error_policy::ErrorPolicy, filters::Filter,
|
||||
handler::Handler, updater::Updater, Dispatcher,
|
||||
},
|
||||
types::{CallbackQuery, ChosenInlineResult, Message, Update, UpdateKind},
|
||||
types::{
|
||||
CallbackQuery, ChosenInlineResult, InlineQuery, Message, Update,
|
||||
UpdateKind,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod error_policy;
|
||||
|
@ -70,7 +73,7 @@ type FiltersAndHandlers<'a, T, E> = Vec<FilterAndHandler<'a, T, E>>;
|
|||
///
|
||||
/// // create dispatching which handlers can't fail
|
||||
/// // with error policy that just ignores all errors (that can't ever happen)
|
||||
/// let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async { () })
|
||||
/// let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async {})
|
||||
/// // Add 'handler' that will handle all messages sent to the bot
|
||||
/// .message_handler(true, |mes: Message| {
|
||||
/// async move { println!("New message: {:?}", mes) }
|
||||
|
@ -91,7 +94,7 @@ pub struct FilterDispatcher<'a, E, Ep> {
|
|||
edited_message_handlers: FiltersAndHandlers<'a, Message, E>,
|
||||
channel_post_handlers: FiltersAndHandlers<'a, Message, E>,
|
||||
edited_channel_post_handlers: FiltersAndHandlers<'a, Message, E>,
|
||||
inline_query_handlers: FiltersAndHandlers<'a, (), E>,
|
||||
inline_query_handlers: FiltersAndHandlers<'a, InlineQuery, E>,
|
||||
chosen_inline_result_handlers:
|
||||
FiltersAndHandlers<'a, ChosenInlineResult, E>,
|
||||
callback_query_handlers: FiltersAndHandlers<'a, CallbackQuery, E>,
|
||||
|
@ -162,8 +165,8 @@ where
|
|||
|
||||
pub fn inline_query_handler<F, H>(mut self, filter: F, handler: H) -> Self
|
||||
where
|
||||
F: Filter<()> + 'a,
|
||||
H: Handler<'a, (), E> + 'a,
|
||||
F: Filter<InlineQuery> + 'a,
|
||||
H: Handler<'a, InlineQuery, E> + 'a,
|
||||
{
|
||||
self.inline_query_handlers
|
||||
.push(FilterAndHandler::new(filter, handler));
|
||||
|
@ -256,6 +259,7 @@ where
|
|||
.await;
|
||||
}
|
||||
|
||||
#[allow(clippy::ptr_arg)] // TODO: proper fix
|
||||
async fn handle<T>(
|
||||
&self,
|
||||
update: T,
|
||||
|
|
|
@ -61,11 +61,14 @@ mod tests {
|
|||
"text 2".to_string(),
|
||||
"url 2".to_string(),
|
||||
);
|
||||
|
||||
let markup = InlineKeyboardMarkup::new()
|
||||
.append_row(vec![button1.clone(), button2.clone()]);
|
||||
|
||||
let expected = InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![vec![button1, button2]],
|
||||
};
|
||||
|
||||
assert_eq!(markup, expected);
|
||||
}
|
||||
|
||||
|
@ -79,12 +82,15 @@ mod tests {
|
|||
"text 2".to_string(),
|
||||
"url 2".to_string(),
|
||||
);
|
||||
|
||||
let markup = InlineKeyboardMarkup::new()
|
||||
.append_row(vec![button1.clone()])
|
||||
.append_to_row(button2.clone(), 0);
|
||||
|
||||
let expected = InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![vec![button1, button2]],
|
||||
};
|
||||
|
||||
assert_eq!(markup, expected);
|
||||
}
|
||||
|
||||
|
@ -98,12 +104,15 @@ mod tests {
|
|||
"text 2".to_string(),
|
||||
"url 2".to_string(),
|
||||
);
|
||||
|
||||
let markup = InlineKeyboardMarkup::new()
|
||||
.append_row(vec![button1.clone()])
|
||||
.append_to_row(button2.clone(), 1);
|
||||
|
||||
let expected = InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![vec![button1], vec![button2]],
|
||||
};
|
||||
|
||||
assert_eq!(markup, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::types::{Location, User};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub struct InlineQuery {
|
||||
/// Unique identifier for this query
|
||||
pub id: String,
|
||||
|
|
|
@ -8,6 +8,24 @@ pub enum InputFile {
|
|||
}
|
||||
|
||||
impl InputFile {
|
||||
pub fn file(path: PathBuf) -> Self {
|
||||
Self::File(path)
|
||||
}
|
||||
|
||||
pub fn url<T>(url: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
Self::Url(url.into())
|
||||
}
|
||||
|
||||
pub fn file_id<T>(file_id: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
Self::FileId(file_id.into())
|
||||
}
|
||||
|
||||
pub fn as_file(&self) -> Option<&PathBuf> {
|
||||
match self {
|
||||
Self::File(path) => Some(path),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use crate::types::{CallbackQuery, ChosenInlineResult, Message};
|
||||
use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message};
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Clone)]
|
||||
pub struct Update {
|
||||
|
@ -17,8 +17,7 @@ pub enum UpdateKind {
|
|||
EditedMessage(Message),
|
||||
ChannelPost(Message),
|
||||
EditedChannelPost(Message),
|
||||
InlineQuery(()),
|
||||
// TODO
|
||||
InlineQuery(InlineQuery),
|
||||
ChosenInlineResult(ChosenInlineResult),
|
||||
CallbackQuery(CallbackQuery),
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue