Annotation For src/tg_bot.rs
Logged in as anonymous

Origin for each line in src/tg_bot.rs from check-in 9c4f09193a:

9c4f09193a 2026-01-09    1: use stacked_errors::{
9c4f09193a 2026-01-09    2: 	Result,
9c4f09193a 2026-01-09    3: 	StackableErr,
9c4f09193a 2026-01-09    4: };
9c4f09193a 2026-01-09    5: use tgbot::{
9c4f09193a 2026-01-09    6: 	api::Client,
9c4f09193a 2026-01-09    7: 	types::{
9c4f09193a 2026-01-09    8: 		Bot,
9c4f09193a 2026-01-09    9: 		ChatPeerId,
9c4f09193a 2026-01-09   10: 		GetBot,
9c4f09193a 2026-01-09   11: 		Message,
9c4f09193a 2026-01-09   12: 		ParseMode,
9c4f09193a 2026-01-09   13: 		SendMessage,
9c4f09193a 2026-01-09   14: 	},
9c4f09193a 2026-01-09   15: };
9c4f09193a 2026-01-09   16: 
9c4f09193a 2026-01-09   17: #[derive(Clone)]
9c4f09193a 2026-01-09   18: pub struct Tg {
9c4f09193a 2026-01-09   19: 	pub me: Bot,
9c4f09193a 2026-01-09   20: 	pub owner: ChatPeerId,
9c4f09193a 2026-01-09   21: 	pub client: Client,
9c4f09193a 2026-01-09   22: }
9c4f09193a 2026-01-09   23: 
9c4f09193a 2026-01-09   24: impl Tg {
9c4f09193a 2026-01-09   25: 	pub async fn new (settings: &config::Config) -> Result<Tg> {
9c4f09193a 2026-01-09   26: 		let api_key = settings.get_string("api_key").stack()?;
9c4f09193a 2026-01-09   27: 
9c4f09193a 2026-01-09   28: 		let owner = ChatPeerId::from(settings.get_int("owner").stack()?);
9c4f09193a 2026-01-09   29: 		let client = Client::new(&api_key).stack()?
9c4f09193a 2026-01-09   30: 			.with_host(settings.get_string("api_gateway").stack()?)
9c4f09193a 2026-01-09   31: 			.with_max_retries(0);
9c4f09193a 2026-01-09   32: 		let me = client.execute(GetBot).await.stack()?;
9c4f09193a 2026-01-09   33: 		Ok(Tg {
9c4f09193a 2026-01-09   34: 			me,
9c4f09193a 2026-01-09   35: 			owner,
9c4f09193a 2026-01-09   36: 			client,
9c4f09193a 2026-01-09   37: 		})
9c4f09193a 2026-01-09   38: 	}
9c4f09193a 2026-01-09   39: 
9c4f09193a 2026-01-09   40: 	pub async fn send <S>(&self, msg: S, target: Option<ChatPeerId>, mode: Option<ParseMode>) -> Result<Message>
9c4f09193a 2026-01-09   41: 	where S: Into<String> {
9c4f09193a 2026-01-09   42: 		let msg = msg.into();
9c4f09193a 2026-01-09   43: 
9c4f09193a 2026-01-09   44: 		let mode = mode.unwrap_or(ParseMode::Html);
9c4f09193a 2026-01-09   45: 		let target = target.unwrap_or(self.owner);
9c4f09193a 2026-01-09   46: 		self.client.execute(
9c4f09193a 2026-01-09   47: 			SendMessage::new(target, msg)
9c4f09193a 2026-01-09   48: 				.with_parse_mode(mode)
9c4f09193a 2026-01-09   49: 		).await.stack()
9c4f09193a 2026-01-09   50: 	}
9c4f09193a 2026-01-09   51: 
9c4f09193a 2026-01-09   52: 	pub fn with_owner (&self, owner: i64) -> Tg {
9c4f09193a 2026-01-09   53: 		Tg {
9c4f09193a 2026-01-09   54: 			owner: ChatPeerId::from(owner),
9c4f09193a 2026-01-09   55: 			..self.clone()
9c4f09193a 2026-01-09   56: 		}
9c4f09193a 2026-01-09   57: 	}
9c4f09193a 2026-01-09   58: }