Conversion updates for Number/URL input elements (#169)

* Conversion updates for Number/URL input elements

* Clippy fixes
This commit is contained in:
Abdulla Abdurakhmanov 2023-02-04 16:19:40 +01:00 committed by GitHub
parent df15229e7b
commit 197664e50a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 30 deletions

View file

@ -156,7 +156,7 @@ impl<H: 'static + Send + Sync + Connect + Clone> SlackEventsAxumListener<H> {
(err_environment.error_handler)(
Box::new(SlackClientError::SystemError(
SlackClientSystemError::new()
.with_message(format!("OAuth cancelled system error: {}", err)),
.with_message(format!("OAuth cancelled system error: {err}")),
)),
err_environment.client.clone(),
err_environment.user_state.clone(),

View file

@ -1,5 +1,6 @@
use crate::signature_verifier::*;
use crate::{AnyStdResult, SlackApiToken};
use base64::prelude::*;
use bytes::Buf;
use futures_util::TryFutureExt;
use http::request::Parts;
@ -56,7 +57,7 @@ impl HyperExtensions {
) -> hyper::http::request::Builder {
let header_value = format!(
"Basic {}",
base64::encode(format!("{}:{}", username, password))
BASE64_STANDARD.encode(format!("{username}:{password}"))
);
request_builder.header(hyper::header::AUTHORIZATION, header_value)
}

View file

@ -406,8 +406,7 @@ where
.client_listener
.on_error(Box::new(SlackClientError::SocketModeProtocolError(
SlackClientSocketModeProtocolError::new(format!(
"Unexpected binary received from Slack: {:?}",
body
"Unexpected binary received from Slack: {body:?}"
)),
)))
.await;
@ -444,8 +443,7 @@ where
.client_listener
.on_error(Box::new(SlackClientError::SocketModeProtocolError(
SlackClientSocketModeProtocolError::new(format!(
"Slack WSS error: {:?}",
err
"Slack WSS error: {err:?}"
)),
)))
.await;

View file

@ -78,7 +78,7 @@
//! Examples available on: [github](https://github.com/abdolence/slack-morphism-rust/tree/master/examples).
//!
#![allow(clippy::new_without_default)]
#![allow(clippy::new_without_default, clippy::needless_lifetimes)]
pub use client::*;
pub use scroller::*;

View file

@ -38,7 +38,7 @@ where
<TZ as chrono::offset::TimeZone>::Offset: std::fmt::Display,
{
let link_part = link
.map(|value| format!("^{}", value))
.map(|value| format!("^{value}"))
.unwrap_or_else(|| "".into());
let fallback = date.to_rfc2822();
format!(

View file

@ -610,26 +610,6 @@ pub struct SlackBlockPlainTextInputElement {
pub max_length: Option<u64>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockNumberInputElement {
pub action_id: SlackActionId,
pub is_decimal_allowed: bool,
pub focus_on_load: Option<bool>,
pub placeholder: Option<SlackBlockPlainTextOnly>,
pub initial_value: Option<String>,
pub min_value: Option<String>,
pub max_value: Option<String>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockUrlInputElement {
pub action_id: SlackActionId,
pub placeholder: Option<SlackBlockPlainTextOnly>,
pub initial_value: Option<String>,
}
impl From<SlackBlockPlainTextInputElement> for SlackSectionBlockElement {
fn from(element: SlackBlockPlainTextInputElement) -> Self {
SlackSectionBlockElement::PlainTextInput(element)
@ -648,6 +628,62 @@ impl From<SlackBlockPlainTextInputElement> for SlackActionBlockElement {
}
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockNumberInputElement {
pub action_id: SlackActionId,
pub is_decimal_allowed: bool,
pub focus_on_load: Option<bool>,
pub placeholder: Option<SlackBlockPlainTextOnly>,
pub initial_value: Option<String>,
pub min_value: Option<String>,
pub max_value: Option<String>,
}
impl From<SlackBlockNumberInputElement> for SlackSectionBlockElement {
fn from(element: SlackBlockNumberInputElement) -> Self {
SlackSectionBlockElement::NumberInput(element)
}
}
impl From<SlackBlockNumberInputElement> for SlackInputBlockElement {
fn from(element: SlackBlockNumberInputElement) -> Self {
SlackInputBlockElement::NumberInput(element)
}
}
impl From<SlackBlockNumberInputElement> for SlackActionBlockElement {
fn from(element: SlackBlockNumberInputElement) -> Self {
SlackActionBlockElement::NumberInput(element)
}
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockUrlInputElement {
pub action_id: SlackActionId,
pub placeholder: Option<SlackBlockPlainTextOnly>,
pub initial_value: Option<String>,
}
impl From<SlackBlockUrlInputElement> for SlackSectionBlockElement {
fn from(element: SlackBlockUrlInputElement) -> Self {
SlackSectionBlockElement::UrlInput(element)
}
}
impl From<SlackBlockUrlInputElement> for SlackInputBlockElement {
fn from(element: SlackBlockUrlInputElement) -> Self {
SlackInputBlockElement::UrlInput(element)
}
}
impl From<SlackBlockUrlInputElement> for SlackActionBlockElement {
fn from(element: SlackBlockUrlInputElement) -> Self {
SlackActionBlockElement::UrlInput(element)
}
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockRadioButtonsElement {

View file

@ -32,7 +32,7 @@ impl Serialize for SlackIconImages {
} else {
let mut res_map = serializer.serialize_map(Some(self.resolutions.len()))?;
for (res, link) in &self.resolutions {
let key: String = format!("{}{}", SLACK_ICON_JSON_PREFIX, res);
let key: String = format!("{SLACK_ICON_JSON_PREFIX}{res}");
res_map.serialize_entry(&key, link)?;
}
res_map.end()

View file

@ -24,7 +24,7 @@ impl SlackEventSignatureVerifier {
}
fn sign<'a, 'b>(&'a self, body: &'b str, ts: &'b str) -> String {
let data_to_sign = format!("v0:{}:{}", ts, body);
let data_to_sign = format!("v0:{ts}:{body}");
format!(
"v0={}",
hex::encode(hmac::sign(&self.key, data_to_sign.as_bytes()))