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