use crate::{
contexts::{
fields::{
self, AnyText, Context, EditedMessage, Forward, MediaMessage,
Message,
},
traits::{Forwardable, Pinnable},
EditedText, Text,
},
internal::Sealed,
types::{
self,
message::{self, inline_markup},
Chat, User,
},
Bot,
};
use std::ops::Deref;
pub struct Command<C> {
pub command: String,
context: C,
}
impl<C> Deref for Command<C> {
type Target = C;
fn deref(&self) -> &Self::Target {
&self.context
}
}
impl<C> Command<C> {
#[allow(clippy::missing_const_for_fn)]
pub(crate) fn new(command: String, context: C) -> Self {
Self { command, context }
}
}
impl<T> Sealed for Command<T> {}
impl<C> Context<C> for Command<Text<C>> {
fn bot(&self) -> &Bot<C> {
&self.context.bot
}
}
impl<C> Message<C> for Command<Text<C>> {
#[must_use]
fn message_id(&self) -> message::Id {
self.context.message_id
}
#[must_use]
fn from(&self) -> Option<&User> {
self.context.from.as_ref()
}
#[must_use]
fn date(&self) -> i64 {
self.context.date
}
#[must_use]
fn chat(&self) -> &Chat {
&self.context.chat
}
}
impl<C> MediaMessage<C> for Command<Text<C>> {
#[must_use]
fn reply_to(&self) -> Option<&types::Message> {
self.context.reply_to.as_ref()
}
#[must_use]
fn author_signature(&self) -> Option<&str> {
self.context.author_signature.as_ref().map(String::as_str)
}
#[must_use]
fn reply_markup(&self) -> Option<&inline_markup::Keyboard> {
self.context.reply_markup.as_ref()
}
}
impl<C> Forward<C> for Command<Text<C>> {
#[must_use]
fn forward(&self) -> Option<&message::Forward> {
self.context.forward()
}
}
impl<C> fields::Text<C> for Command<Text<C>> {
#[must_use]
fn text(&self) -> &message::Text {
&self.context.text
}
}
impl<C> AnyText<C> for Command<Text<C>> {
#[must_use]
fn text(&self) -> &message::Text {
&self.context.text
}
}
impl<'a, C: 'static> Forwardable<'a, C> for Command<Text<C>> {}
impl<'a, C: 'static> Pinnable<'a, C> for Command<Text<C>> {}
impl<C> Context<C> for Command<EditedText<C>> {
fn bot(&self) -> &Bot<C> {
&self.context.bot
}
}
impl<C> Message<C> for Command<EditedText<C>> {
#[must_use]
fn message_id(&self) -> message::Id {
self.context.message_id
}
#[must_use]
fn from(&self) -> Option<&User> {
self.context.from.as_ref()
}
#[must_use]
fn date(&self) -> i64 {
self.context.date
}
#[must_use]
fn chat(&self) -> &Chat {
&self.context.chat
}
}
impl<C> MediaMessage<C> for Command<EditedText<C>> {
#[must_use]
fn reply_to(&self) -> Option<&types::Message> {
self.context.reply_to.as_ref()
}
#[must_use]
fn author_signature(&self) -> Option<&str> {
self.context.author_signature.as_ref().map(String::as_str)
}
#[must_use]
fn reply_markup(&self) -> Option<&inline_markup::Keyboard> {
self.context.reply_markup.as_ref()
}
}
impl<C> EditedMessage<C> for Command<EditedText<C>> {
#[must_use]
fn edit_date(&self) -> i64 {
self.context.edit_date
}
}
impl<C> fields::Text<C> for Command<EditedText<C>> {
#[must_use]
fn text(&self) -> &message::Text {
&self.context.text
}
}
impl<C> AnyText<C> for Command<EditedText<C>> {
#[must_use]
fn text(&self) -> &message::Text {
&self.context.text
}
}
impl<'a, C: 'static> Forwardable<'a, C> for Command<EditedText<C>> {}
impl<'a, C: 'static> Pinnable<'a, C> for Command<EditedText<C>> {}