Artifact
9d833eecb471341a521a9a9032dd3f1f0a7853832db9bfd4ff4b4a36f2cfb379:
0000: 2f 2f 21 20 54 68 69 73 20 69 73 20 74 65 6c 65 //! This is tele
0010: 67 72 61 6d 20 62 6f 74 20 74 6f 20 66 65 74 63 gram bot to fetc
0020: 68 20 52 53 53 2f 41 54 4f 4d 20 66 65 65 64 73 h RSS/ATOM feeds
0030: 20 61 6e 64 20 70 6f 73 74 20 72 65 73 75 6c 74 and post result
0040: 73 20 6f 6e 20 70 75 62 6c 69 63 0a 2f 2f 21 20 s on public.//!
0050: 63 68 61 6e 6e 65 6c 73 0a 0a 23 21 5b 77 61 72 channels..#![war
0060: 6e 28 6d 69 73 73 69 6e 67 5f 64 6f 63 73 29 5d n(missing_docs)]
0070: 0a 0a 6d 6f 64 20 63 6f 6d 6d 61 6e 64 3b 0a 6d ..mod command;.m
0080: 6f 64 20 63 6f 72 65 3b 0a 6d 6f 64 20 73 71 6c od core;.mod sql
0090: 3b 0a 6d 6f 64 20 74 67 5f 62 6f 74 3b 0a 0a 75 ;.mod tg_bot;..u
00a0: 73 65 20 61 73 79 6e 63 5f 63 6f 6d 70 61 74 3a se async_compat:
00b0: 3a 43 6f 6d 70 61 74 3b 0a 75 73 65 20 73 74 61 :Compat;.use sta
00c0: 63 6b 65 64 5f 65 72 72 6f 72 73 3a 3a 7b 0a 09 cked_errors::{..
00d0: 52 65 73 75 6c 74 2c 0a 09 53 74 61 63 6b 61 62 Result,..Stackab
00e0: 6c 65 45 72 72 2c 0a 7d 3b 0a 75 73 65 20 74 67 leErr,.};.use tg
00f0: 62 6f 74 3a 3a 68 61 6e 64 6c 65 72 3a 3a 4c 6f bot::handler::Lo
0100: 6e 67 50 6f 6c 6c 3b 0a 0a 66 6e 20 6d 61 69 6e ngPoll;..fn main
0110: 20 28 29 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 () -> Result<()
0120: 3e 20 7b 0a 09 73 6d 6f 6c 3a 3a 62 6c 6f 63 6b > {..smol::block
0130: 5f 6f 6e 28 43 6f 6d 70 61 74 3a 3a 6e 65 77 28 _on(Compat::new(
0140: 61 73 79 6e 63 20 7b 0a 09 09 61 73 79 6e 63 5f async {...async_
0150: 6d 61 69 6e 28 29 2e 61 77 61 69 74 2e 75 6e 77 main().await.unw
0160: 72 61 70 28 29 3b 0a 09 7d 29 29 3b 0a 0a 09 4f rap();..}));...O
0170: 6b 28 28 29 29 0a 7d 0a 0a 2f 2f 2f 20 49 6e 69 k(()).}../// Ini
0180: 74 69 61 6c 69 73 65 73 20 63 6f 6e 66 69 67 75 tialises configu
0190: 72 61 74 69 6f 6e 20 61 6e 64 20 74 68 65 20 62 ration and the b
01a0: 6f 74 20 63 6f 72 65 2c 20 74 68 65 6e 20 72 75 ot core, then ru
01b0: 6e 73 20 74 68 65 20 54 65 6c 65 67 72 61 6d 20 ns the Telegram
01c0: 6c 6f 6e 67 2d 70 6f 6c 6c 20 6c 6f 6f 70 2e 0a long-poll loop..
01d0: 2f 2f 2f 0a 2f 2f 2f 20 54 68 69 73 20 66 75 6e ///./// This fun
01e0: 63 74 69 6f 6e 20 6c 6f 61 64 73 20 63 6f 6e 66 ction loads conf
01f0: 69 67 75 72 61 74 69 6f 6e 20 28 77 69 74 68 20 iguration (with
0200: 61 20 64 65 66 61 75 6c 74 20 41 50 49 20 67 61 a default API ga
0210: 74 65 77 61 79 29 2c 20 63 6f 6e 73 74 72 75 63 teway), construc
0220: 74 73 20 74 68 65 20 61 70 70 6c 69 63 61 74 69 ts the applicati
0230: 6f 6e 0a 2f 2f 2f 20 63 6f 72 65 2c 20 61 6e 64 on./// core, and
0240: 20 73 74 61 72 74 73 20 74 68 65 20 6c 6f 6e 67 starts the long
0250: 2d 70 6f 6c 6c 69 6e 67 20 6c 6f 6f 70 20 74 68 -polling loop th
0260: 61 74 20 68 61 6e 64 6c 65 73 20 69 6e 63 6f 6d at handles incom
0270: 69 6e 67 20 54 65 6c 65 67 72 61 6d 20 75 70 64 ing Telegram upd
0280: 61 74 65 73 2e 0a 61 73 79 6e 63 20 66 6e 20 61 ates..async fn a
0290: 73 79 6e 63 5f 6d 61 69 6e 20 28 29 20 2d 3e 20 sync_main () ->
02a0: 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 6c 65 Result<()> {..le
02b0: 74 20 73 65 74 74 69 6e 67 73 20 3d 20 63 6f 6e t settings = con
02c0: 66 69 67 3a 3a 43 6f 6e 66 69 67 3a 3a 62 75 69 fig::Config::bui
02d0: 6c 64 65 72 28 29 0a 09 09 2e 73 65 74 5f 64 65 lder()....set_de
02e0: 66 61 75 6c 74 28 22 61 70 69 5f 67 61 74 65 77 fault("api_gatew
02f0: 61 79 22 2c 20 22 68 74 74 70 73 3a 2f 2f 61 70 ay", "https://ap
0300: 69 2e 74 65 6c 65 67 72 61 6d 2e 6f 72 67 22 29 i.telegram.org")
0310: 2e 73 74 61 63 6b 28 29 3f 0a 09 09 2e 61 64 64 .stack()?....add
0320: 5f 73 6f 75 72 63 65 28 63 6f 6e 66 69 67 3a 3a _source(config::
0330: 46 69 6c 65 3a 3a 77 69 74 68 5f 6e 61 6d 65 28 File::with_name(
0340: 22 72 73 73 74 67 22 29 29 0a 09 09 2e 62 75 69 "rsstg"))....bui
0350: 6c 64 28 29 0a 09 09 2e 73 74 61 63 6b 28 29 3f ld()....stack()?
0360: 3b 0a 0a 09 6c 65 74 20 63 6f 72 65 20 3d 20 63 ;...let core = c
0370: 6f 72 65 3a 3a 43 6f 72 65 3a 3a 6e 65 77 28 73 ore::Core::new(s
0380: 65 74 74 69 6e 67 73 29 2e 61 77 61 69 74 2e 73 ettings).await.s
0390: 74 61 63 6b 28 29 3f 3b 0a 0a 09 4c 6f 6e 67 50 tack()?;...LongP
03a0: 6f 6c 6c 3a 3a 6e 65 77 28 63 6f 72 65 2e 74 67 oll::new(core.tg
03b0: 2e 63 6c 69 65 6e 74 2e 63 6c 6f 6e 65 28 29 2c .client.clone(),
03c0: 20 63 6f 72 65 29 2e 72 75 6e 28 29 2e 61 77 61 core).run().awa
03d0: 69 74 3b 0a 0a 09 4f 6b 28 28 29 29 0a 7d 0a it;...Ok(()).}.