mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
commit
2bd2035758
13 changed files with 78 additions and 66 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -20,7 +20,7 @@ env:
|
||||||
# - crates/teloxide-core/src/codegen.rs
|
# - crates/teloxide-core/src/codegen.rs
|
||||||
# - rust-toolchain.toml
|
# - rust-toolchain.toml
|
||||||
# - below in the test matrix
|
# - below in the test matrix
|
||||||
rust_nightly: nightly-2024-03-20
|
rust_nightly: nightly-2024-07-03
|
||||||
# When updating this, also update:
|
# When updating this, also update:
|
||||||
# - **/README.md
|
# - **/README.md
|
||||||
# - **/src/lib.rs
|
# - **/src/lib.rs
|
||||||
|
@ -105,7 +105,7 @@ jobs:
|
||||||
toolchain: beta
|
toolchain: beta
|
||||||
features: "--features full"
|
features: "--features full"
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
toolchain: nightly-2024-03-20
|
toolchain: nightly-2024-07-03
|
||||||
features: "--features full nightly"
|
features: "--features full nightly"
|
||||||
- rust: msrv
|
- rust: msrv
|
||||||
toolchain: 1.70.0
|
toolchain: 1.70.0
|
||||||
|
|
|
@ -112,6 +112,9 @@ pre-release-replacements = [
|
||||||
{ file = "CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 },
|
{ file = "CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(dep_docsrs)'] }
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "self_info"
|
name = "self_info"
|
||||||
required-features = ["tokio/macros", "tokio/rt-multi-thread"]
|
required-features = ["tokio/macros", "tokio/rt-multi-thread"]
|
||||||
|
|
|
@ -23,7 +23,7 @@ use xshell::{cmd, Shell};
|
||||||
|
|
||||||
fn ensure_rustfmt(sh: &Shell) {
|
fn ensure_rustfmt(sh: &Shell) {
|
||||||
// FIXME(waffle): find a better way to set toolchain
|
// FIXME(waffle): find a better way to set toolchain
|
||||||
let toolchain = "nightly-2024-03-20";
|
let toolchain = "nightly-2024-07-03";
|
||||||
|
|
||||||
let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default();
|
let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default();
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ fn ensure_rustfmt(sh: &Shell) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reformat(text: String) -> String {
|
pub fn reformat(text: String) -> String {
|
||||||
let toolchain = "nightly-2024-03-20";
|
let toolchain = "nightly-2024-07-03";
|
||||||
|
|
||||||
let sh = Shell::new().unwrap();
|
let sh = Shell::new().unwrap();
|
||||||
ensure_rustfmt(&sh);
|
ensure_rustfmt(&sh);
|
||||||
|
@ -89,7 +89,7 @@ pub fn ensure_files_contents<'a>(
|
||||||
|
|
||||||
err_count += 1;
|
err_count += 1;
|
||||||
|
|
||||||
let display_path = path.strip_prefix(&project_root()).unwrap_or(path);
|
let display_path = path.strip_prefix(project_root()).unwrap_or(path);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n",
|
"\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n",
|
||||||
display_path.display()
|
display_path.display()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::codegen::schema::Type;
|
use crate::codegen::schema::Type;
|
||||||
|
|
||||||
pub enum Convert {
|
pub enum Convert {
|
||||||
|
#[allow(dead_code)]
|
||||||
Id(Type),
|
Id(Type),
|
||||||
Into(Type),
|
Into(Type),
|
||||||
Collect(Type),
|
Collect(Type),
|
||||||
|
|
|
@ -361,6 +361,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat
|
/// - is the owner of the chat
|
||||||
/// - is an administrator in the given chat and has [`can_manage_chat`]
|
/// - is an administrator in the given chat and has [`can_manage_chat`]
|
||||||
/// privilege.
|
/// privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_manage_chat`]: Administrator::can_manage_chat
|
/// [`can_manage_chat`]: Administrator::can_manage_chat
|
||||||
|
@ -379,6 +380,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat (even if the chat is not a channel)
|
/// - is the owner of the chat (even if the chat is not a channel)
|
||||||
/// - is an administrator in the given chat and has [`can_post_messages`]
|
/// - is an administrator in the given chat and has [`can_post_messages`]
|
||||||
/// privilege.
|
/// privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_post_messages`]: Administrator::can_post_messages
|
/// [`can_post_messages`]: Administrator::can_post_messages
|
||||||
|
@ -398,6 +400,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat (even if the chat is not a channel)
|
/// - is the owner of the chat (even if the chat is not a channel)
|
||||||
/// - is an administrator in the given chat and has the
|
/// - is an administrator in the given chat and has the
|
||||||
/// [`can_edit_messages`] privilege.
|
/// [`can_edit_messages`] privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_edit_messages`]: Administrator::can_edit_messages
|
/// [`can_edit_messages`]: Administrator::can_edit_messages
|
||||||
|
@ -416,6 +419,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat
|
/// - is the owner of the chat
|
||||||
/// - is an administrator in the given chat and has the
|
/// - is an administrator in the given chat and has the
|
||||||
/// [`can_delete_messages`] privilege.
|
/// [`can_delete_messages`] privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_delete_messages`]: Administrator::can_delete_messages
|
/// [`can_delete_messages`]: Administrator::can_delete_messages
|
||||||
|
@ -434,6 +438,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat
|
/// - is the owner of the chat
|
||||||
/// - is an administrator in the given chat and has the
|
/// - is an administrator in the given chat and has the
|
||||||
/// [`can_manage_video_chats`] privilege.
|
/// [`can_manage_video_chats`] privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_manage_video_chats`]: Administrator::can_manage_video_chats
|
/// [`can_manage_video_chats`]: Administrator::can_manage_video_chats
|
||||||
|
@ -454,6 +459,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat
|
/// - is the owner of the chat
|
||||||
/// - is an administrator in the given chat and has the
|
/// - is an administrator in the given chat and has the
|
||||||
/// [`can_restrict_members`] privilege.
|
/// [`can_restrict_members`] privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_restrict_members`]: Administrator::can_restrict_members
|
/// [`can_restrict_members`]: Administrator::can_restrict_members
|
||||||
|
@ -477,6 +483,7 @@ impl ChatMemberKind {
|
||||||
/// - is the owner of the chat (even if the chat is not a channel)
|
/// - is the owner of the chat (even if the chat is not a channel)
|
||||||
/// - is an administrator in the given chat and has the
|
/// - is an administrator in the given chat and has the
|
||||||
/// [`can_promote_members`] privilege.
|
/// [`can_promote_members`] privilege.
|
||||||
|
///
|
||||||
/// Returns `false` otherwise.
|
/// Returns `false` otherwise.
|
||||||
///
|
///
|
||||||
/// [`can_promote_members`]: Administrator::can_promote_members
|
/// [`can_promote_members`]: Administrator::can_promote_members
|
||||||
|
|
|
@ -1009,17 +1009,16 @@ mod getters {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn caption(&self) -> Option<&str> {
|
pub fn caption(&self) -> Option<&str> {
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
Common(MessageCommon { media_kind, .. }) => match media_kind {
|
Common(MessageCommon {
|
||||||
MediaKind::Animation(MediaAnimation { caption, .. })
|
media_kind:
|
||||||
| MediaKind::Audio(MediaAudio { caption, .. })
|
MediaKind::Animation(MediaAnimation { caption, .. })
|
||||||
| MediaKind::Document(MediaDocument { caption, .. })
|
| MediaKind::Audio(MediaAudio { caption, .. })
|
||||||
| MediaKind::Photo(MediaPhoto { caption, .. })
|
| MediaKind::Document(MediaDocument { caption, .. })
|
||||||
| MediaKind::Video(MediaVideo { caption, .. })
|
| MediaKind::Photo(MediaPhoto { caption, .. })
|
||||||
| MediaKind::Voice(MediaVoice { caption, .. }) => {
|
| MediaKind::Video(MediaVideo { caption, .. })
|
||||||
caption.as_ref().map(Deref::deref)
|
| MediaKind::Voice(MediaVoice { caption, .. }),
|
||||||
}
|
..
|
||||||
_ => None,
|
}) => caption.as_ref().map(Deref::deref),
|
||||||
},
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,12 @@ name = "postgres"
|
||||||
path = "tests/postgres.rs"
|
path = "tests/postgres.rs"
|
||||||
required-features = ["postgres-storage-nativetls", "cbor-serializer", "bincode-serializer"]
|
required-features = ["postgres-storage-nativetls", "cbor-serializer", "bincode-serializer"]
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unexpected_cfgs = { level = "warn", check-cfg = [
|
||||||
|
'cfg(CI_POSTGRES)',
|
||||||
|
'cfg(CI_REDIS)',
|
||||||
|
] }
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "admin"
|
name = "admin"
|
||||||
required-features = ["macros", "ctrlc_handler"]
|
required-features = ["macros", "ctrlc_handler"]
|
||||||
|
|
|
@ -91,8 +91,7 @@
|
||||||
//! several techniques:
|
//! several techniques:
|
||||||
//!
|
//!
|
||||||
//! - **Branching:** `a.branch(b)` roughly means "try to handle an update with
|
//! - **Branching:** `a.branch(b)` roughly means "try to handle an update with
|
||||||
//! `a`, then, if it
|
//! `a`, then, if it neglects the update, try `b`".
|
||||||
//! neglects the update, try `b`".
|
|
||||||
//! - **Pattern matching:** We also use the [`dptree::case!`] macro
|
//! - **Pattern matching:** We also use the [`dptree::case!`] macro
|
||||||
//! extensively, which acts as a filter on an enumeration: if it is of a
|
//! extensively, which acts as a filter on an enumeration: if it is of a
|
||||||
//! certain variant, it passes the variant's payload down the handler chain;
|
//! certain variant, it passes the variant's payload down the handler chain;
|
||||||
|
|
|
@ -44,9 +44,8 @@ impl<S> PostgresStorage<S> {
|
||||||
/// - database_url: full url to the postgres database, for example
|
/// - database_url: full url to the postgres database, for example
|
||||||
/// `"postgres://postgres:password@localhost/test")`
|
/// `"postgres://postgres:password@localhost/test")`
|
||||||
/// - max_connections: number of connections in creating connection pool. Be
|
/// - max_connections: number of connections in creating connection pool. Be
|
||||||
/// mindful of the connection limits for your database, each
|
/// mindful of the connection limits for your database, each connection
|
||||||
/// connection established with the Postgres creates a new process on the
|
/// established with the Postgres creates a new process on the server side
|
||||||
/// server side
|
|
||||||
/// - serializer: what [`Serializer`] will be used to encode the dialogue
|
/// - serializer: what [`Serializer`] will be used to encode the dialogue
|
||||||
/// data. Available ones are: [`Json`], [`Bincode`], [`Cbor`]
|
/// data. Available ones are: [`Json`], [`Bincode`], [`Cbor`]
|
||||||
///
|
///
|
||||||
|
|
|
@ -89,7 +89,7 @@ where
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let dialogue =
|
let dialogue =
|
||||||
self.serializer.serialize(&dialogue).map_err(RedisStorageError::SerdeError)?;
|
self.serializer.serialize(&dialogue).map_err(RedisStorageError::SerdeError)?;
|
||||||
self.conn.lock().await.set::<_, Vec<u8>, _>(chat_id, dialogue).await?;
|
() = self.conn.lock().await.set::<_, Vec<u8>, _>(chat_id, dialogue).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@ pub trait HandlerExt<Output> {
|
||||||
/// It does so by the following steps:
|
/// It does so by the following steps:
|
||||||
///
|
///
|
||||||
/// 1. If an incoming update has no chat ID ([`GetChatId::chat_id`] returns
|
/// 1. If an incoming update has no chat ID ([`GetChatId::chat_id`] returns
|
||||||
/// `None`), the rest of the chain will not be executed. Otherwise, passes
|
/// `None`), the rest of the chain will not be executed. Otherwise,
|
||||||
/// `Dialogue::new(storage, chat_id)` forwards.
|
/// passes `Dialogue::new(storage, chat_id)` forwards.
|
||||||
/// 2. If [`Dialogue::get_or_default`] on the passed dialogue returns `Ok`,
|
/// 2. If [`Dialogue::get_or_default`] on the passed dialogue returns `Ok`,
|
||||||
/// passes the dialogue state forwards. Otherwise, logs an error and the
|
/// passes the dialogue state forwards. Otherwise, logs an error and the
|
||||||
/// rest of the chain is not executed.
|
/// rest of the chain is not executed.
|
||||||
///
|
///
|
||||||
/// ## Dependency requirements
|
/// ## Dependency requirements
|
||||||
///
|
///
|
||||||
|
|
|
@ -81,22 +81,22 @@ pub use teloxide_macros::BotCommands;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Enum attributes
|
/// # Enum attributes
|
||||||
/// 1. `#[command(rename_rule = "rule")]`
|
/// 1. `#[command(rename_rule = "rule")]` Rename all commands by `rule`.
|
||||||
/// Rename all commands by `rule`. Allowed rules are `lowercase`, `UPPERCASE`,
|
/// Allowed rules are `lowercase`, `UPPERCASE`, `PascalCase`, `camelCase`,
|
||||||
/// `PascalCase`, `camelCase`, `snake_case`, `SCREAMING_SNAKE_CASE`,
|
/// `snake_case`, `SCREAMING_SNAKE_CASE`, `kebab-case`, and
|
||||||
/// `kebab-case`, and `SCREAMING-KEBAB-CASE`.
|
/// `SCREAMING-KEBAB-CASE`.
|
||||||
///
|
///
|
||||||
/// 2. `#[command(prefix = "prefix")]`
|
/// 2. `#[command(prefix = "prefix")]` Change a prefix for all commands (the
|
||||||
/// Change a prefix for all commands (the default is `/`).
|
/// default is `/`).
|
||||||
///
|
///
|
||||||
/// 3. `#[command(description = "description")]` and `/// description`
|
/// 3. `#[command(description = "description")]` and `/// description` Add a
|
||||||
/// Add a summary description of commands before all commands.
|
/// summary description of commands before all commands.
|
||||||
///
|
///
|
||||||
/// 4. `#[command(parse_with = "parser")]`
|
/// 4. `#[command(parse_with = "parser")]` Change the parser of arguments.
|
||||||
/// Change the parser of arguments. Possible values:
|
/// Possible values:
|
||||||
/// - `default` - the same as the unspecified parser. It only puts all text
|
/// - `default` - the same as the unspecified parser. It only puts all
|
||||||
/// after the first space into the first argument, which must implement
|
/// text after the first space into the first argument, which must
|
||||||
/// [`FromStr`].
|
/// implement [`FromStr`].
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -134,9 +134,8 @@ pub use teloxide_macros::BotCommands;
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// 5. `#[command(separator = "sep")]`
|
/// 5. `#[command(separator = "sep")]` Specify separator used by the `split`
|
||||||
/// Specify separator used by the `split` parser. It will be ignored when
|
/// parser. It will be ignored when accompanied by another type of parsers.
|
||||||
/// accompanied by another type of parsers.
|
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -154,8 +153,8 @@ pub use teloxide_macros::BotCommands;
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// 6. `#[command(command_separator = "sep")]`
|
/// 6. `#[command(command_separator = "sep")]` Specify separator between command
|
||||||
/// Specify separator between command and args. Default is a space character.
|
/// and args. Default is a space character.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -181,34 +180,33 @@ pub use teloxide_macros::BotCommands;
|
||||||
/// # Variant attributes
|
/// # Variant attributes
|
||||||
/// All variant attributes override the corresponding `enum` attributes.
|
/// All variant attributes override the corresponding `enum` attributes.
|
||||||
///
|
///
|
||||||
/// 1. `#[command(rename_rule = "rule")]`
|
/// 1. `#[command(rename_rule = "rule")]` Rename one command by a rule. Allowed
|
||||||
/// Rename one command by a rule. Allowed rules are `lowercase`, `UPPERCASE`,
|
/// rules are `lowercase`, `UPPERCASE`, `PascalCase`, `camelCase`,
|
||||||
/// `PascalCase`, `camelCase`, `snake_case`, `SCREAMING_SNAKE_CASE`,
|
/// `snake_case`, `SCREAMING_SNAKE_CASE`, `kebab-case`,
|
||||||
/// `kebab-case`, `SCREAMING-KEBAB-CASE`.
|
/// `SCREAMING-KEBAB-CASE`.
|
||||||
///
|
///
|
||||||
/// 2. `#[command(rename = "name")]`
|
/// 2. `#[command(rename = "name")]` Rename one command to `name` (literal
|
||||||
/// Rename one command to `name` (literal renaming; do not confuse with
|
/// renaming; do not confuse with `rename_rule`).
|
||||||
/// `rename_rule`).
|
|
||||||
///
|
///
|
||||||
/// 3. `#[command(description = "description")]` and `/// description`
|
/// 3. `#[command(description = "description")]` and `/// description` Give
|
||||||
/// Give your command a description. It will be shown in the help message.
|
/// your command a description. It will be shown in the help message.
|
||||||
///
|
///
|
||||||
/// 4. `#[command(parse_with = "parser")]`
|
/// 4. `#[command(parse_with = "parser")]` Parse arguments of one command with
|
||||||
/// Parse arguments of one command with a given parser. `parser` must be a
|
/// a given parser. `parser` must be a function of the signature `fn(String)
|
||||||
/// function of the signature `fn(String) -> Result<Tuple, ParseError>`, where
|
/// -> Result<Tuple, ParseError>`, where `Tuple` corresponds to the
|
||||||
/// `Tuple` corresponds to the variant's arguments.
|
/// variant's arguments.
|
||||||
///
|
///
|
||||||
/// 5. `#[command(hide)]`
|
/// 5. `#[command(hide)]` Hide a command from the help message. It will still
|
||||||
/// Hide a command from the help message. It will still be parsed.
|
/// be parsed.
|
||||||
///
|
///
|
||||||
/// 6. `#[command(alias = "alias")]`
|
/// 6. `#[command(alias = "alias")]` Add an alias to a command. It will be shown
|
||||||
/// Add an alias to a command. It will be shown in the help message.
|
/// in the help message.
|
||||||
///
|
///
|
||||||
/// 7. `#[command(aliases = ["alias1", "alias2"])]`
|
/// 7. `#[command(aliases = ["alias1", "alias2"])]` Add multiple aliases to a
|
||||||
/// Add multiple aliases to a command. They will be shown in the help message.
|
/// command. They will be shown in the help message.
|
||||||
///
|
///
|
||||||
/// 8. `#[command(hide_aliases)]`
|
/// 8. `#[command(hide_aliases)]` Hide all aliases of a command from the help
|
||||||
/// Hide all aliases of a command from the help message.
|
/// message.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2024-03-20"
|
channel = "nightly-2024-07-03"
|
||||||
components = ["rustfmt", "clippy"]
|
components = ["rustfmt", "clippy"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
Loading…
Reference in a new issue