Lines of
src/main.rs
from check-in 4632d20d39
that are changed by the sequence of edits moving toward
check-in e3339014b4:
1: mod command;
2: mod core;
3:
4: use config;
5: use futures::StreamExt;
6: use tokio;
7: use telegram_bot;
8:
9: #[macro_use]
10: extern crate lazy_static;
11:
12: use anyhow::Result;
13:
14: #[tokio::main]
15: async fn main() -> Result<()> {
16: let mut settings = config::Config::default();
17: settings.merge(config::File::with_name("rsstg"))?;
18:
19: let core = core::Core::new(settings).await?;
20:
21: let mut stream = core.stream();
22: stream.allowed_updates(&[telegram_bot::AllowedUpdate::Message]);
23: let mut reply_to: Option<telegram_bot::UserId>;
24:
25: loop {
26: reply_to = None;
27: match stream.next().await {
28: Some(update) => {
29: if let Err(err) = handle(update?, &core, &mut reply_to).await {
30: core.send(&format!("🛑 {:?}", err), reply_to, None)?;
31: };
32: },
33: None => {
34: core.send(&format!("🛑 None error."), None, None)?;
35: }
36: };
37: }
4632d20d39 2021-11-13 38:
4632d20d39 2021-11-13 39: //Ok(())
40: }
41:
42: async fn handle(update: telegram_bot::Update, core: &core::Core, mut _reply_to: &Option<telegram_bot::UserId>) -> Result<()> {
43: match update.kind {
44: telegram_bot::UpdateKind::Message(message) => {
45: match message.kind {
46: telegram_bot::MessageKind::Text { ref data, .. } => {
47: let sender = message.from.id;
48: let words: Vec<&str> = data.split_whitespace().collect();
49: match match words[0] {
50: "/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
51: "/start" => command::start(core, sender).await,
52: "/list" => command::list(core, sender).await,
53: "/add" | "/update" => command::update(core, sender, words).await,
54: _ => Ok(()),
55: } {
56: Err(err) => core.send(&format!("🛑 {:?}", err), Some(sender), None)?,
57: Ok(()) => {},
58: };
59: },
60: _ => {
61: },
62: };
63: },
64: _ => {},
65: };
66:
67: Ok(())
68: }