Diff
Logged in as anonymous

Differences From Artifact [1e47879074]:

To Artifact [decd6d1c81]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
use crate::utils::{
	Attachment,
	RE_SPECIAL,
};

use std::{
	borrow::Cow,
	collections::HashMap,
	fmt::Debug,
};

use anyhow::{
	Context,
	Result,

};
use tgbot::{
	api::Client,
	types::{
		ChatPeerId,
		InputFile,
		InputFileReader,











|
<

>







1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
use crate::utils::{
	Attachment,
	RE_SPECIAL,
};

use std::{
	borrow::Cow,
	collections::HashMap,
	fmt::Debug,
};

use stacked_errors::{

	Result,
	StackableErr,
};
use tgbot::{
	api::Client,
	types::{
		ChatPeerId,
		InputFile,
		InputFileReader,
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		self.recipients.get(name)
			.with_context(|| format!("Recipient \"{name}\" not found in configuration"))
	}

	/// Send message to specified user
	pub async fn send <S> (&self, to: &ChatPeerId, msg: S) -> Result<Message>
	where S: Into<String> + Debug{
		Ok(self.tg.execute(
			SendMessage::new(*to, msg)
			.with_parse_mode(MarkdownV2)
		).await?)
	}

	/// Send media to specified user
	pub async fn sendgroup (&self, to: &ChatPeerId, media: Vec<Attachment>, msg: &str) -> Result<()> {
		if media.len() > 1 {
			let mut attach = vec![];
			let mut pos = media.len();







|


|







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		self.recipients.get(name)
			.with_context(|| format!("Recipient \"{name}\" not found in configuration"))
	}

	/// Send message to specified user
	pub async fn send <S> (&self, to: &ChatPeerId, msg: S) -> Result<Message>
	where S: Into<String> + Debug{
		self.tg.execute(
			SendMessage::new(*to, msg)
			.with_parse_mode(MarkdownV2)
		).await.stack()
	}

	/// Send media to specified user
	pub async fn sendgroup (&self, to: &ChatPeerId, media: Vec<Attachment>, msg: &str) -> Result<()> {
		if media.len() > 1 {
			let mut attach = vec![];
			let mut pos = media.len();
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
							InputFileReader::from(file.data)
								.with_file_name(file.name)
						),
						caption
					)
				);
			}
			self.tg.execute(SendMediaGroup::new(*to, MediaGroup::new(attach)?)).await?;
		} else {
			self.tg.execute(
				SendDocument::new(
					*to,
					InputFileReader::from(media[0].data.clone())
					.with_file_name(media[0].name.clone())
				).with_caption(msg)
				.with_caption_parse_mode(MarkdownV2)
			).await?;
		}
		Ok(())
	}
}







|








|




96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
							InputFileReader::from(file.data)
								.with_file_name(file.name)
						),
						caption
					)
				);
			}
			self.tg.execute(SendMediaGroup::new(*to, MediaGroup::new(attach).stack()?)).await.stack()?;
		} else {
			self.tg.execute(
				SendDocument::new(
					*to,
					InputFileReader::from(media[0].data.clone())
					.with_file_name(media[0].name.clone())
				).with_caption(msg)
				.with_caption_parse_mode(MarkdownV2)
			).await.stack()?;
		}
		Ok(())
	}
}