tbot/contexts/macros/
edited_message.rs

1macro_rules! edited_message {
2    (
3        struct $name:ident {
4            #[doc = $media_doc:literal] $media:ident: $media_type:ty,
5            $(#[doc = $field_doc:literal] $field:ident: $type:ty,)*
6        } -> EventLoop::$handler:ident
7
8        fn new(
9            $($param:ident: $param_type:ty,)*
10        ) -> Self {
11            Self {
12                $($new_field:ident: $value:expr,)*
13            }
14        }
15    ) => {
16        message_base! {
17            struct $name {
18                /// The replied message.
19                reply_to: Option<crate::types::Message>,
20                /// The author's signature, if enabled for the channel.
21                author_signature: Option<String>,
22                /// The last time when the message was edited.
23                edit_date: i64,
24                /// The inline keyboard attached to the message.
25                reply_markup: Option<crate::types::message::inline_markup::Keyboard>,
26                /// The bot via which the message was sent.
27                via_bot: Option<crate::types::User>,
28                #[doc = $media_doc]
29                $media: $media_type,
30                $(#[doc = $field_doc] $field: $type,)*
31            } -> EventLoop::$handler
32
33            fn new(
34                edit_date: i64,
35                $media: $media_type,
36                $($param: $param_type,)*
37            ) -> Self {
38                infer reply_to;
39                infer author_signature;
40                infer reply_markup;
41                infer via_bot;
42
43                Self {
44                    edit_date: edit_date,
45                    $media: $media,
46                    $($new_field: $value,)*
47                }
48            }
49        }
50
51        impl super::methods::Forwardable for $name {}
52        impl super::methods::Pinnable for $name {}
53
54        impl crate::contexts::fields::MediaMessage for $name {
55            #[must_use]
56            fn reply_to(&self) -> Option<&crate::types::Message> {
57                self.reply_to.as_ref()
58            }
59
60            #[must_use]
61            fn author_signature(&self) -> Option<&str> {
62                self.author_signature.as_ref().map(String::as_str)
63            }
64
65            #[must_use]
66            fn reply_markup(
67                &self
68            ) -> Option<&crate::types::message::inline_markup::Keyboard> {
69                self.reply_markup.as_ref()
70            }
71
72            #[must_use]
73            fn via_bot(&self) -> Option<&crate::types::User> {
74                self.via_bot.as_ref()
75            }
76        }
77
78        impl crate::contexts::fields::EditedMessage for $name {
79            #[must_use]
80            fn edit_date(&self) -> i64 {
81                self.edit_date
82            }
83        }
84    };
85}