use crate::client::BotClient;
use rustigram_types::keyboard::MenuButton;
use rustigram_types::user::{BotCommand, BotCommandScope, ChatId};
use serde::Serialize;
use std::future::{Future, IntoFuture};
use std::pin::Pin;
#[derive(Serialize)]
struct SetMyCommandsParams {
commands: Vec<BotCommand>,
#[serde(skip_serializing_if = "Option::is_none")]
scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
language_code: Option<String>,
}
pub struct SetMyCommands {
client: BotClient,
params: SetMyCommandsParams,
}
impl SetMyCommands {
pub(crate) fn new(client: BotClient, commands: Vec<BotCommand>) -> Self {
Self {
client,
params: SetMyCommandsParams {
commands,
scope: None,
language_code: None,
},
}
}
pub fn scope(mut self, s: BotCommandScope) -> Self {
self.params.scope = Some(s);
self
}
pub fn language_code(mut self, lc: impl Into<String>) -> Self {
self.params.language_code = Some(lc.into());
self
}
}
impl IntoFuture for SetMyCommands {
type Output = crate::error::Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json("setMyCommands", &self.params).await })
}
}
#[derive(Serialize, Default)]
struct GetMyCommandsParams {
#[serde(skip_serializing_if = "Option::is_none")]
scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
language_code: Option<String>,
}
pub struct GetMyCommands {
client: BotClient,
params: GetMyCommandsParams,
}
impl GetMyCommands {
pub(crate) fn new(client: BotClient) -> Self {
Self {
client,
params: Default::default(),
}
}
pub fn scope(mut self, s: BotCommandScope) -> Self {
self.params.scope = Some(s);
self
}
pub fn language_code(mut self, lc: impl Into<String>) -> Self {
self.params.language_code = Some(lc.into());
self
}
}
impl IntoFuture for GetMyCommands {
type Output = crate::error::Result<Vec<BotCommand>>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json("getMyCommands", &self.params).await })
}
}
#[derive(Serialize, Default)]
struct SetMyNameParams {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
language_code: Option<String>,
}
pub struct SetMyName {
client: BotClient,
params: SetMyNameParams,
}
impl SetMyName {
pub(crate) fn new(client: BotClient) -> Self {
Self {
client,
params: Default::default(),
}
}
pub fn name(mut self, n: impl Into<String>) -> Self {
self.params.name = Some(n.into());
self
}
pub fn language_code(mut self, lc: impl Into<String>) -> Self {
self.params.language_code = Some(lc.into());
self
}
}
impl IntoFuture for SetMyName {
type Output = crate::error::Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json("setMyName", &self.params).await })
}
}
#[derive(Serialize, Default)]
struct SetMyDescriptionParams {
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
language_code: Option<String>,
}
pub struct SetMyDescription {
client: BotClient,
params: SetMyDescriptionParams,
}
impl SetMyDescription {
pub(crate) fn new(client: BotClient) -> Self {
Self {
client,
params: Default::default(),
}
}
pub fn description(mut self, d: impl Into<String>) -> Self {
self.params.description = Some(d.into());
self
}
pub fn language_code(mut self, lc: impl Into<String>) -> Self {
self.params.language_code = Some(lc.into());
self
}
}
impl IntoFuture for SetMyDescription {
type Output = crate::error::Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setMyDescription", &self.params)
.await
})
}
}
#[derive(Serialize, Default)]
struct GetChatMenuButtonParams {
#[serde(skip_serializing_if = "Option::is_none")]
chat_id: Option<ChatId>,
}
pub struct GetChatMenuButton {
client: BotClient,
params: GetChatMenuButtonParams,
}
impl GetChatMenuButton {
pub(crate) fn new(client: BotClient) -> Self {
Self {
client,
params: Default::default(),
}
}
pub fn chat_id(mut self, id: impl Into<ChatId>) -> Self {
self.params.chat_id = Some(id.into());
self
}
}
impl IntoFuture for GetChatMenuButton {
type Output = crate::error::Result<MenuButton>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("getChatMenuButton", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct GetManagedBotTokenParams {
user_id: i64,
}
pub struct GetManagedBotToken {
client: BotClient,
params: GetManagedBotTokenParams,
}
impl GetManagedBotToken {
pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
Self {
client,
params: GetManagedBotTokenParams { user_id },
}
}
}
impl IntoFuture for GetManagedBotToken {
type Output = crate::error::Result<String>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("getManagedBotToken", &self.params)
.await
})
}
}