mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Merge pull request #8 from Mr-Andersen/dev
Added dummy types into core/types/not_implemented_types.rs; Added Mes…
This commit is contained in:
commit
d8c70b9fc6
11 changed files with 126 additions and 30 deletions
|
@ -32,16 +32,14 @@ impl FormBuilder {
|
|||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Self {
|
||||
form: value.map_or_else(
|
||||
|| self.form,
|
||||
|value| {
|
||||
self.form.text(
|
||||
name.to_owned(),
|
||||
serde_json::to_string(value).expect("serde_json::to_string failed"),
|
||||
)
|
||||
},
|
||||
),
|
||||
match value {
|
||||
None => Self { form: self.form },
|
||||
Some(value) => Self {
|
||||
form: self.form.text(
|
||||
name.to_owned(),
|
||||
serde_json::to_string(value).expect("serde_json::to_string failed"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ impl Request for GetMe {
|
|||
type ReturnValue = User;
|
||||
|
||||
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
||||
Box::new(async {
|
||||
Box::new(async move {
|
||||
request(&self.info.client, &self.info.token, "getMe", None).await
|
||||
})
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ pub type RequestFuture<T> = Box<dyn Future<Output = T>>;
|
|||
|
||||
// todo: better name?
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct RequestInfo {
|
||||
pub(crate) client: Client,
|
||||
pub(crate) token: String,
|
||||
pub struct RequestInfo {
|
||||
pub client: Client,
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel (in
|
||||
|
|
|
@ -37,7 +37,7 @@ impl Request for SendMessage {
|
|||
|
||||
|
||||
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
||||
Box::new(async {
|
||||
Box::new(async move {
|
||||
let params = FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("text", &self.text)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct Document {
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
use serde::Deserialize;
|
||||
// use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{Chat, Document, Invoice, SuccessfulPayment, User};
|
||||
use crate::core::types::{
|
||||
Animation, Audio, Chat, Contact,
|
||||
Document, Game, Invoice, InlineKeyboardMarkup,
|
||||
PhotoSize, MessageEntity, Location, PassportData, Poll,
|
||||
Sticker, SuccessfulPayment,
|
||||
User, Video, VideoNote, Venue, Voice,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct Message {
|
||||
|
@ -26,7 +32,7 @@ pub struct Message {
|
|||
pub animation: Option<Animation>,
|
||||
pub game: Option<Game>,
|
||||
pub photo: Option<Vec<PhotoSize>>,
|
||||
pub sticker: Option<Stickers>,
|
||||
pub sticker: Option<Sticker>,
|
||||
pub video: Option<Video>,
|
||||
pub voice: Option<Voice>,
|
||||
pub video_note: Option<VideoNote>,
|
||||
|
|
36
src/core/types/message_entity.rs
Normal file
36
src/core/types/message_entity.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::core::types::User;
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||
pub struct MessageEntity {
|
||||
#[serde(flatten)]
|
||||
pub kind: MessageEntityKind,
|
||||
pub offset: usize,
|
||||
pub length: usize,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "type")]
|
||||
pub enum MessageEntityKind {
|
||||
Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber,
|
||||
Bold, Italic, Code, Pre,
|
||||
TextLink { url: String },
|
||||
TextMention { user: User }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_kind() {
|
||||
use serde_json::from_str;
|
||||
|
||||
assert_eq!(
|
||||
MessageEntity {
|
||||
kind: MessageEntityKind::TextLink { url: "ya.ru".into() },
|
||||
offset: 1,
|
||||
length: 2
|
||||
},
|
||||
from_str::<MessageEntity>(
|
||||
r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#
|
||||
).unwrap()
|
||||
);
|
||||
}
|
|
@ -1,10 +1,27 @@
|
|||
mod not_implemented_types;
|
||||
use self::not_implemented_types::*;
|
||||
|
||||
|
||||
pub use self::{
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery,
|
||||
chat::Chat, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, document::Document,
|
||||
invoice::Invoice, label_price::LabeledPrice, message::Message, order_info::OrderInfo,
|
||||
pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice,
|
||||
shipping_address::ShippingAddress, shipping_option::ShippingOption,
|
||||
shipping_query::ShippingQuery, successful_payment::SuccessfulPayment, user::User,
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
||||
answer_shipping_query::AnswerShippingQuery,
|
||||
chat::Chat,
|
||||
chat_permissions::ChatPermissions,
|
||||
chat_photo::ChatPhoto,
|
||||
document::Document,
|
||||
invoice::Invoice,
|
||||
label_price::LabeledPrice,
|
||||
message::Message,
|
||||
message_entity::MessageEntity,
|
||||
order_info::OrderInfo,
|
||||
pre_checkout_query::PreCheckoutQuery,
|
||||
send_invoice::SendInvoice,
|
||||
shipping_address::ShippingAddress,
|
||||
shipping_option::ShippingOption,
|
||||
shipping_query::ShippingQuery,
|
||||
sticker::Sticker,
|
||||
successful_payment::SuccessfulPayment,
|
||||
user::User,
|
||||
};
|
||||
|
||||
mod answer_pre_checkout_query;
|
||||
|
@ -16,11 +33,13 @@ mod document;
|
|||
mod invoice;
|
||||
mod label_price;
|
||||
mod message;
|
||||
mod message_entity;
|
||||
mod order_info;
|
||||
mod pre_checkout_query;
|
||||
mod send_invoice;
|
||||
mod shipping_address;
|
||||
mod shipping_option;
|
||||
mod shipping_query;
|
||||
mod sticker;
|
||||
mod successful_payment;
|
||||
mod user;
|
||||
|
|
41
src/core/types/not_implemented_types.rs
Normal file
41
src/core/types/not_implemented_types.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Location;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct InlineKeyboardMarkup;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct PassportData;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Poll;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Animation;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Audio;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Game;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Contact;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Video;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct VideoNote;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Venue;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct Voice;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
|
||||
pub struct MaskPosition;
|
|
@ -1,6 +1,4 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::LabeledPrice;
|
||||
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct SendInvoice {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(async_await)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_more;
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in a new issue