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