0000: 75 73 65 20 63 72 61 74 65 3a 3a 7b 0a 09 63 6f use crate::{..co
0010: 72 65 3a 3a 43 6f 72 65 2c 0a 09 74 67 5f 62 6f re::Core,..tg_bo
0020: 74 3a 3a 7b 0a 09 09 43 61 6c 6c 62 61 63 6b 2c t::{...Callback,
0030: 0a 09 09 4d 79 4d 65 73 73 61 67 65 2c 0a 09 09 ...MyMessage,...
0040: 67 65 74 5f 6b 62 2c 0a 09 7d 2c 0a 7d 3b 0a 0a get_kb,..},.};..
0050: 75 73 65 20 6c 61 7a 79 5f 73 74 61 74 69 63 3a use lazy_static:
0060: 3a 6c 61 7a 79 5f 73 74 61 74 69 63 3b 0a 75 73 :lazy_static;.us
0070: 65 20 72 65 67 65 78 3a 3a 52 65 67 65 78 3b 0a e regex::Regex;.
0080: 75 73 65 20 73 65 64 72 65 67 65 78 3a 3a 52 65 use sedregex::Re
0090: 70 6c 61 63 65 43 6f 6d 6d 61 6e 64 3b 0a 75 73 placeCommand;.us
00a0: 65 20 73 74 61 63 6b 65 64 5f 65 72 72 6f 72 73 e stacked_errors
00b0: 3a 3a 7b 0a 09 52 65 73 75 6c 74 2c 0a 09 53 74 ::{..Result,..St
00c0: 61 63 6b 61 62 6c 65 45 72 72 2c 0a 09 62 61 69 ackableErr,..bai
00d0: 6c 2c 0a 7d 3b 0a 75 73 65 20 74 67 62 6f 74 3a l,.};.use tgbot:
00e0: 3a 74 79 70 65 73 3a 3a 7b 0a 09 43 68 61 74 4d :types::{..ChatM
00f0: 65 6d 62 65 72 2c 0a 09 43 68 61 74 55 73 65 72 ember,..ChatUser
0100: 6e 61 6d 65 2c 0a 09 47 65 74 43 68 61 74 2c 0a name,..GetChat,.
0110: 09 47 65 74 43 68 61 74 41 64 6d 69 6e 69 73 74 .GetChatAdminist
0120: 72 61 74 6f 72 73 2c 0a 09 4d 65 73 73 61 67 65 rators,..Message
0130: 2c 0a 7d 3b 0a 75 73 65 20 75 72 6c 3a 3a 55 72 ,.};.use url::Ur
0140: 6c 3b 0a 0a 6c 61 7a 79 5f 73 74 61 74 69 63 21 l;..lazy_static!
0150: 20 7b 0a 09 73 74 61 74 69 63 20 72 65 66 20 52 {..static ref R
0160: 45 5f 55 53 45 52 4e 41 4d 45 3a 20 52 65 67 65 E_USERNAME: Rege
0170: 78 20 3d 20 52 65 67 65 78 3a 3a 6e 65 77 28 72 x = Regex::new(r
0180: 22 5e 40 28 5b 61 2d 7a 41 2d 5a 5d 5b 61 2d 7a "^@([a-zA-Z][a-z
0190: 41 2d 5a 30 2d 39 5f 5d 2b 29 24 22 29 2e 75 6e A-Z0-9_]+)$").un
01a0: 77 72 61 70 28 29 3b 0a 09 73 74 61 74 69 63 20 wrap();..static
01b0: 72 65 66 20 52 45 5f 49 56 5f 48 41 53 48 3a 20 ref RE_IV_HASH:
01c0: 52 65 67 65 78 20 3d 20 52 65 67 65 78 3a 3a 6e Regex = Regex::n
01d0: 65 77 28 72 22 5e 5b 61 2d 66 30 2d 39 5d 7b 31 ew(r"^[a-f0-9]{1
01e0: 34 7d 24 22 29 2e 75 6e 77 72 61 70 28 29 3b 0a 4}$").unwrap();.
01f0: 7d 0a 0a 2f 2f 2f 20 53 65 6e 64 73 20 61 6e 20 }../// Sends an
0200: 69 6e 66 6f 72 6d 61 74 69 6f 6e 61 6c 20 6d 65 informational me
0210: 73 73 61 67 65 20 74 6f 20 74 68 65 20 6d 65 73 ssage to the mes
0220: 73 61 67 65 27 73 20 63 68 61 74 20 6c 69 6e 6b sage's chat link
0230: 69 6e 67 20 74 6f 20 74 68 65 20 62 6f 74 20 68 ing to the bot h
0240: 65 6c 70 20 63 68 61 6e 6e 65 6c 2e 0a 70 75 62 elp channel..pub
0250: 20 61 73 79 6e 63 20 66 6e 20 73 74 61 72 74 20 async fn start
0260: 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c 20 6d 73 (core: &Core, ms
0270: 67 3a 20 26 4d 65 73 73 61 67 65 29 20 2d 3e 20 g: &Message) ->
0280: 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 63 6f Result<()> {..co
0290: 72 65 2e 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73 re.tg.send(MyMes
02a0: 73 61 67 65 3a 3a 74 65 78 74 5f 74 6f 28 0a 09 sage::text_to(..
02b0: 09 22 57 65 20 61 72 65 20 6f 70 65 6e 5c 5c 2e ."We are open\\.
02c0: 20 50 72 6f 62 61 62 6c 79 5c 5c 2e 20 56 69 73 Probably\\. Vis
02d0: 69 74 20 5b 63 68 61 6e 6e 65 6c 5d 28 68 74 74 it [channel](htt
02e0: 70 73 3a 2f 2f 74 2e 6d 65 2f 72 73 73 74 67 5f ps://t.me/rsstg_
02f0: 62 6f 74 5f 68 65 6c 70 2f 33 29 20 66 6f 72 20 bot_help/3) for
0300: 64 65 74 61 69 6c 73 5c 5c 2e 22 2c 0a 09 09 6d details\\.",...m
0310: 73 67 2e 63 68 61 74 2e 67 65 74 5f 69 64 28 29 sg.chat.get_id()
0320: 0a 09 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b ..)).await.stack
0330: 28 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a 0a ()?;..Ok(()).}..
0340: 2f 2f 2f 20 53 65 6e 64 20 74 68 65 20 73 65 6e /// Send the sen
0350: 64 65 72 27 73 20 73 75 62 73 63 72 69 70 74 69 der's subscripti
0360: 6f 6e 20 6c 69 73 74 20 74 6f 20 74 68 65 20 63 on list to the c
0370: 68 61 74 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 52 65 74 hat..///./// Ret
0380: 72 69 65 76 65 73 20 74 68 65 20 6d 65 73 73 61 rieves the messa
0390: 67 65 20 73 65 6e 64 65 72 27 73 20 75 73 65 72 ge sender's user
03a0: 20 49 44 2c 20 6f 62 74 61 69 6e 73 20 74 68 65 ID, obtains the
03b0: 69 72 20 73 75 62 73 63 72 69 70 74 69 6f 6e 20 ir subscription
03c0: 6c 69 73 74 20 66 72 6f 6d 20 60 63 6f 72 65 60 list from `core`
03d0: 2c 0a 2f 2f 2f 20 61 6e 64 20 73 65 6e 64 73 20 ,./// and sends
03e0: 74 68 65 20 72 65 73 75 6c 74 69 6e 67 20 72 65 the resulting re
03f0: 70 6c 79 20 69 6e 74 6f 20 74 68 65 20 6d 65 73 ply into the mes
0400: 73 61 67 65 20 63 68 61 74 20 75 73 69 6e 67 20 sage chat using
0410: 4d 61 72 6b 64 6f 77 6e 56 32 2e 0a 70 75 62 20 MarkdownV2..pub
0420: 61 73 79 6e 63 20 66 6e 20 6c 69 73 74 20 28 63 async fn list (c
0430: 6f 72 65 3a 20 26 43 6f 72 65 2c 20 6d 73 67 3a ore: &Core, msg:
0440: 20 26 4d 65 73 73 61 67 65 29 20 2d 3e 20 52 65 &Message) -> Re
0450: 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 6c 65 74 20 sult<()> {..let
0460: 73 65 6e 64 65 72 20 3d 20 6d 73 67 2e 73 65 6e sender = msg.sen
0470: 64 65 72 2e 67 65 74 5f 75 73 65 72 5f 69 64 28 der.get_user_id(
0480: 29 0a 09 09 2e 73 74 61 63 6b 5f 65 72 72 28 22 )....stack_err("
0490: 49 67 6e 6f 72 69 6e 67 20 75 6e 72 65 61 6c 20 Ignoring unreal
04a0: 75 73 65 72 73 2e 22 29 3f 3b 0a 09 6c 65 74 20 users.")?;..let
04b0: 72 65 70 6c 79 20 3d 20 63 6f 72 65 2e 6c 69 73 reply = core.lis
04c0: 74 28 73 65 6e 64 65 72 29 2e 61 77 61 69 74 2e t(sender).await.
04d0: 73 74 61 63 6b 28 29 3f 3b 0a 09 63 6f 72 65 2e stack()?;..core.
04e0: 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73 73 61 67 tg.send(MyMessag
04f0: 65 3a 3a 74 65 78 74 5f 74 6f 28 72 65 70 6c 79 e::text_to(reply
0500: 2c 20 6d 73 67 2e 63 68 61 74 2e 67 65 74 5f 69 , msg.chat.get_i
0510: 64 28 29 29 29 2e 61 77 61 69 74 2e 73 74 61 63 d())).await.stac
0520: 6b 28 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a k()?;..Ok(()).}.
0530: 0a 70 75 62 20 61 73 79 6e 63 20 66 6e 20 74 65 .pub async fn te
0540: 73 74 20 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c st (core: &Core,
0550: 20 6d 73 67 3a 20 26 4d 65 73 73 61 67 65 29 20 msg: &Message)
0560: 2d 3e 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a -> Result<()> {.
0570: 09 6c 65 74 20 73 65 6e 64 65 72 3a 20 69 36 34 .let sender: i64
0580: 20 3d 20 6d 73 67 2e 73 65 6e 64 65 72 2e 67 65 = msg.sender.ge
0590: 74 5f 75 73 65 72 5f 69 64 28 29 0a 09 09 2e 73 t_user_id()....s
05a0: 74 61 63 6b 5f 65 72 72 28 22 49 67 6e 6f 72 69 tack_err("Ignori
05b0: 6e 67 20 75 6e 72 65 61 6c 20 75 73 65 72 73 2e ng unreal users.
05c0: 22 29 3f 2e 69 6e 74 6f 28 29 3b 0a 09 6c 65 74 ")?.into();..let
05d0: 20 66 65 65 64 73 20 3d 20 63 6f 72 65 2e 67 65 feeds = core.ge
05e0: 74 5f 66 65 65 64 73 28 73 65 6e 64 65 72 29 2e t_feeds(sender).
05f0: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
0600: 09 6c 65 74 20 6b 62 20 3d 20 67 65 74 5f 6b 62 .let kb = get_kb
0610: 28 26 43 61 6c 6c 62 61 63 6b 3a 3a 6c 69 73 74 (&Callback::list
0620: 28 22 22 2c 20 30 29 2c 20 66 65 65 64 73 29 2e ("", 0), feeds).
0630: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
0640: 09 63 6f 72 65 2e 74 67 2e 73 65 6e 64 28 4d 79 .core.tg.send(My
0650: 4d 65 73 73 61 67 65 3a 3a 68 74 6d 6c 5f 74 6f Message::html_to
0660: 5f 6b 62 28 66 6f 72 6d 61 74 21 28 22 4c 69 73 _kb(format!("Lis
0670: 74 20 6f 66 20 66 65 65 64 73 20 6f 77 6e 65 64 t of feeds owned
0680: 20 62 79 20 7b 3a 3f 7d 3a 22 2c 20 6d 73 67 2e by {:?}:", msg.
0690: 73 65 6e 64 65 72 2e 67 65 74 5f 75 73 65 72 5f sender.get_user_
06a0: 75 73 65 72 6e 61 6d 65 28 29 29 2c 20 6d 73 67 username()), msg
06b0: 2e 63 68 61 74 2e 67 65 74 5f 69 64 28 29 2c 20 .chat.get_id(),
06c0: 6b 62 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b kb)).await.stack
06d0: 28 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a 0a ()?;..Ok(()).}..
06e0: 2f 2f 2f 20 48 61 6e 64 6c 65 20 63 68 61 6e 6e /// Handle chann
06f0: 65 6c 2d 6d 61 6e 61 67 65 6d 65 6e 74 20 63 6f el-management co
0700: 6d 6d 61 6e 64 73 20 74 68 61 74 20 6f 70 65 72 mmands that oper
0710: 61 74 65 20 6f 6e 20 61 20 73 69 6e 67 6c 65 20 ate on a single
0720: 6e 75 6d 65 72 69 63 20 73 6f 75 72 63 65 20 49 numeric source I
0730: 44 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 54 68 69 73 20 D..///./// This
0740: 76 61 6c 69 64 61 74 65 73 20 74 68 61 74 20 65 validates that e
0750: 78 61 63 74 6c 79 20 6f 6e 65 20 6e 75 6d 65 72 xactly one numer
0760: 69 63 20 61 72 67 75 6d 65 6e 74 20 69 73 20 70 ic argument is p
0770: 72 6f 76 69 64 65 64 2c 20 70 65 72 66 6f 72 6d rovided, perform
0780: 73 20 74 68 65 20 72 65 71 75 65 73 74 65 64 0a s the requested.
0790: 2f 2f 2f 20 6f 70 65 72 61 74 69 6f 6e 20 28 63 /// operation (c
07a0: 68 65 63 6b 2c 20 63 6c 65 61 6e 2c 20 65 6e 61 heck, clean, ena
07b0: 62 6c 65 2c 20 64 65 6c 65 74 65 2c 20 64 69 73 ble, delete, dis
07c0: 61 62 6c 65 29 20 61 67 61 69 6e 73 74 20 74 68 able) against th
07d0: 65 20 64 61 74 61 62 61 73 65 20 6f 72 20 63 6f e database or co
07e0: 72 65 2c 0a 2f 2f 2f 20 61 6e 64 20 73 65 6e 64 re,./// and send
07f0: 73 20 74 68 65 20 72 65 73 75 6c 74 69 6e 67 20 s the resulting
0800: 72 65 70 6c 79 20 74 6f 20 74 68 65 20 63 68 61 reply to the cha
0810: 74 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 23 20 50 61 72 t..///./// # Par
0820: 61 6d 65 74 65 72 73 0a 2f 2f 2f 0a 2f 2f 2f 20 ameters.///.///
0830: 2d 20 60 63 6f 72 65 60 3a 20 61 70 70 6c 69 63 - `core`: applic
0840: 61 74 69 6f 6e 20 63 6f 72 65 20 63 6f 6e 74 61 ation core conta
0850: 69 6e 69 6e 67 20 64 61 74 61 62 61 73 65 20 61 ining database a
0860: 6e 64 20 54 65 6c 65 67 72 61 6d 20 63 6c 69 65 nd Telegram clie
0870: 6e 74 73 2e 0a 2f 2f 2f 20 2d 20 60 63 6f 6d 6d nts../// - `comm
0880: 61 6e 64 60 3a 20 63 6f 6d 6d 61 6e 64 20 73 74 and`: command st
0890: 72 69 6e 67 20 28 65 2e 67 2e 20 22 2f 63 68 65 ring (e.g. "/che
08a0: 63 6b 22 2c 20 22 2f 63 6c 65 61 6e 22 2c 20 22 ck", "/clean", "
08b0: 2f 65 6e 61 62 6c 65 22 2c 20 22 2f 64 65 6c 65 /enable", "/dele
08c0: 74 65 22 2c 20 22 2f 64 69 73 61 62 6c 65 22 29 te", "/disable")
08d0: 2e 0a 2f 2f 2f 20 2d 20 60 6d 73 67 60 3a 20 69 ../// - `msg`: i
08e0: 6e 63 6f 6d 69 6e 67 20 54 65 6c 65 67 72 61 6d ncoming Telegram
08f0: 20 6d 65 73 73 61 67 65 20 74 68 61 74 20 74 72 message that tr
0900: 69 67 67 65 72 65 64 20 74 68 65 20 63 6f 6d 6d iggered the comm
0910: 61 6e 64 3b 20 75 73 65 64 20 74 6f 20 64 65 74 and; used to det
0920: 65 72 6d 69 6e 65 20 73 65 6e 64 65 72 20 61 6e ermine sender an
0930: 64 20 63 68 61 74 2e 0a 2f 2f 2f 20 2d 20 60 77 d chat../// - `w
0940: 6f 72 64 73 60 3a 20 63 6f 6d 6d 61 6e 64 20 61 ords`: command a
0950: 72 67 75 6d 65 6e 74 73 3b 20 65 78 70 65 63 74 rguments; expect
0960: 65 64 20 74 6f 20 63 6f 6e 74 61 69 6e 20 65 78 ed to contain ex
0970: 61 63 74 6c 79 20 6f 6e 65 20 65 6c 65 6d 65 6e actly one elemen
0980: 74 20 74 68 61 74 20 70 61 72 73 65 73 20 61 73 t that parses as
0990: 20 61 20 33 32 2d 62 69 74 20 69 6e 74 65 67 65 a 32-bit intege
09a0: 72 2e 0a 70 75 62 20 61 73 79 6e 63 20 66 6e 20 r..pub async fn
09b0: 63 6f 6d 6d 61 6e 64 20 28 63 6f 72 65 3a 20 26 command (core: &
09c0: 43 6f 72 65 2c 20 63 6f 6d 6d 61 6e 64 3a 20 26 Core, command: &
09d0: 73 74 72 2c 20 6d 73 67 3a 20 26 4d 65 73 73 61 str, msg: &Messa
09e0: 67 65 2c 20 77 6f 72 64 73 3a 20 26 5b 53 74 72 ge, words: &[Str
09f0: 69 6e 67 5d 29 20 2d 3e 20 52 65 73 75 6c 74 3c ing]) -> Result<
0a00: 28 29 3e 20 7b 0a 09 6c 65 74 20 6d 75 74 20 63 ()> {..let mut c
0a10: 6f 6e 6e 20 3d 20 63 6f 72 65 2e 64 62 2e 62 65 onn = core.db.be
0a20: 67 69 6e 28 29 2e 61 77 61 69 74 2e 73 74 61 63 gin().await.stac
0a30: 6b 28 29 3f 3b 0a 09 6c 65 74 20 73 65 6e 64 65 k()?;..let sende
0a40: 72 20 3d 20 6d 73 67 2e 73 65 6e 64 65 72 2e 67 r = msg.sender.g
0a50: 65 74 5f 75 73 65 72 5f 69 64 28 29 0a 09 09 2e et_user_id()....
0a60: 73 74 61 63 6b 5f 65 72 72 28 22 49 67 6e 6f 72 stack_err("Ignor
0a70: 69 6e 67 20 75 6e 72 65 61 6c 20 75 73 65 72 73 ing unreal users
0a80: 2e 22 29 3f 3b 0a 09 6c 65 74 20 72 65 70 6c 79 .")?;..let reply
0a90: 20 3d 20 69 66 20 77 6f 72 64 73 2e 6c 65 6e 28 = if words.len(
0aa0: 29 20 3d 3d 20 31 20 7b 0a 09 09 6d 61 74 63 68 ) == 1 {...match
0ab0: 20 77 6f 72 64 73 5b 30 5d 2e 70 61 72 73 65 3a words[0].parse:
0ac0: 3a 3c 69 33 32 3e 28 29 20 7b 0a 09 09 09 45 72 :<i32>() {....Er
0ad0: 72 28 65 72 72 29 20 3d 3e 20 66 6f 72 6d 61 74 r(err) => format
0ae0: 21 28 22 49 20 6e 65 65 64 20 61 20 6e 75 6d 62 !("I need a numb
0af0: 65 72 2e 5c 6e 7b 7d 22 2c 20 26 65 72 72 29 2e er.\n{}", &err).
0b00: 69 6e 74 6f 28 29 2c 0a 09 09 09 4f 6b 28 6e 75 into(),....Ok(nu
0b10: 6d 62 65 72 29 20 3d 3e 20 6d 61 74 63 68 20 63 mber) => match c
0b20: 6f 6d 6d 61 6e 64 20 7b 0a 09 09 09 09 22 2f 63 ommand {....."/c
0b30: 68 65 63 6b 22 20 3d 3e 20 63 6f 72 65 2e 63 68 heck" => core.ch
0b40: 65 63 6b 28 6e 75 6d 62 65 72 2c 20 66 61 6c 73 eck(number, fals
0b50: 65 2c 20 4e 6f 6e 65 29 2e 61 77 61 69 74 0a 09 e, None).await..
0b60: 09 09 09 09 2e 63 6f 6e 74 65 78 74 28 22 43 68 .....context("Ch
0b70: 61 6e 6e 65 6c 20 63 68 65 63 6b 20 66 61 69 6c annel check fail
0b80: 65 64 2e 22 29 3f 2e 69 6e 74 6f 28 29 2c 0a 09 ed.")?.into(),..
0b90: 09 09 09 22 2f 63 6c 65 61 6e 22 20 3d 3e 20 63 ..."/clean" => c
0ba0: 6f 6e 6e 2e 63 6c 65 61 6e 28 6e 75 6d 62 65 72 onn.clean(number
0bb0: 2c 20 73 65 6e 64 65 72 29 2e 61 77 61 69 74 2e , sender).await.
0bc0: 73 74 61 63 6b 28 29 3f 2c 0a 09 09 09 09 22 2f stack()?,....."/
0bd0: 65 6e 61 62 6c 65 22 20 3d 3e 20 63 6f 6e 6e 2e enable" => conn.
0be0: 65 6e 61 62 6c 65 28 6e 75 6d 62 65 72 2c 20 73 enable(number, s
0bf0: 65 6e 64 65 72 29 2e 61 77 61 69 74 2e 73 74 61 ender).await.sta
0c00: 63 6b 28 29 3f 2e 69 6e 74 6f 28 29 2c 0a 09 09 ck()?.into(),...
0c10: 09 09 22 2f 64 65 6c 65 74 65 22 20 3d 3e 20 7b .."/delete" => {
0c20: 0a 09 09 09 09 09 6c 65 74 20 72 65 73 20 3d 20 ......let res =
0c30: 63 6f 6e 6e 2e 64 65 6c 65 74 65 28 6e 75 6d 62 conn.delete(numb
0c40: 65 72 2c 20 73 65 6e 64 65 72 29 2e 61 77 61 69 er, sender).awai
0c50: 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 09 09 t.stack()?;.....
0c60: 09 63 6f 72 65 2e 72 6d 5f 66 65 65 64 28 73 65 .core.rm_feed(se
0c70: 6e 64 65 72 2e 69 6e 74 6f 28 29 2c 20 26 6e 75 nder.into(), &nu
0c80: 6d 62 65 72 29 2e 61 77 61 69 74 2e 73 74 61 63 mber).await.stac
0c90: 6b 28 29 3f 3b 0a 09 09 09 09 09 72 65 73 0a 09 k()?;......res..
0ca0: 09 09 09 7d 0a 09 09 09 09 22 2f 64 69 73 61 62 ...}....."/disab
0cb0: 6c 65 22 20 3d 3e 20 63 6f 6e 6e 2e 64 69 73 61 le" => conn.disa
0cc0: 62 6c 65 28 6e 75 6d 62 65 72 2c 20 73 65 6e 64 ble(number, send
0cd0: 65 72 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 er).await.stack(
0ce0: 29 3f 2e 69 6e 74 6f 28 29 2c 0a 09 09 09 09 5f )?.into(),....._
0cf0: 20 3d 3e 20 62 61 69 6c 21 28 22 43 6f 6d 6d 61 => bail!("Comma
0d00: 6e 64 20 7b 63 6f 6d 6d 61 6e 64 7d 20 7b 77 6f nd {command} {wo
0d10: 72 64 73 3a 3f 7d 20 6e 6f 74 20 68 61 6e 64 6c rds:?} not handl
0d20: 65 64 2e 22 29 2c 0a 09 09 09 7d 2c 0a 09 09 7d ed."),....},...}
0d30: 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 22 54 68 ..} else {..."Th
0d40: 69 73 20 63 6f 6d 6d 61 6e 64 20 6e 65 65 64 73 is command needs
0d50: 20 65 78 61 63 74 6c 79 20 6f 6e 65 20 6e 75 6d exactly one num
0d60: 62 65 72 2e 22 2e 69 6e 74 6f 28 29 0a 09 7d 3b ber.".into()..};
0d70: 0a 09 63 6f 72 65 2e 74 67 2e 73 65 6e 64 28 4d ..core.tg.send(M
0d80: 79 4d 65 73 73 61 67 65 3a 3a 68 74 6d 6c 5f 74 yMessage::html_t
0d90: 6f 28 72 65 70 6c 79 2c 20 6d 73 67 2e 63 68 61 o(reply, msg.cha
0da0: 74 2e 67 65 74 5f 69 64 28 29 29 29 2e 61 77 61 t.get_id())).awa
0db0: 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 4f 6b it.stack()?;..Ok
0dc0: 28 28 29 29 0a 7d 0a 0a 2f 2f 2f 20 56 61 6c 69 (()).}../// Vali
0dd0: 64 61 74 65 20 63 6f 6d 6d 61 6e 64 20 61 72 67 date command arg
0de0: 75 6d 65 6e 74 73 2c 20 63 68 65 63 6b 20 70 65 uments, check pe
0df0: 72 6d 69 73 73 69 6f 6e 73 20 61 6e 64 20 75 70 rmissions and up
0e00: 64 61 74 65 20 6f 72 20 61 64 64 20 61 20 63 68 date or add a ch
0e10: 61 6e 6e 65 6c 20 66 65 65 64 20 63 6f 6e 66 69 annel feed confi
0e20: 67 75 72 61 74 69 6f 6e 20 69 6e 20 74 68 65 20 guration in the
0e30: 64 61 74 61 62 61 73 65 2e 0a 2f 2f 2f 0a 2f 2f database..///.//
0e40: 2f 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 / This function
0e50: 70 61 72 73 65 73 20 61 6e 64 20 76 61 6c 69 64 parses and valid
0e60: 61 74 65 73 20 70 61 72 61 6d 65 74 65 72 73 20 ates parameters
0e70: 73 75 70 70 6c 69 65 64 20 62 79 20 61 20 75 73 supplied by a us
0e80: 65 72 20 63 6f 6d 6d 61 6e 64 20 28 65 69 74 68 er command (eith
0e90: 65 72 20 22 2f 75 70 64 61 74 65 20 3c 69 64 3e er "/update <id>
0ea0: 20 2e 2e 2e 22 20 6f 72 20 22 2f 61 64 64 20 2e ..." or "/add .
0eb0: 2e 2e 22 29 2c 0a 2f 2f 2f 20 76 65 72 69 66 69 .."),./// verifi
0ec0: 65 73 20 74 68 65 20 63 68 61 6e 6e 65 6c 20 75 es the channel u
0ed0: 73 65 72 6e 61 6d 65 20 61 6e 64 20 66 65 65 64 sername and feed
0ee0: 20 55 52 4c 2c 20 6f 70 74 69 6f 6e 61 6c 6c 79 URL, optionally
0ef0: 20 76 61 6c 69 64 61 74 65 73 20 61 6e 20 49 56 validates an IV
0f00: 20 68 61 73 68 20 61 6e 64 20 61 20 72 65 70 6c hash and a repl
0f10: 61 63 65 6d 65 6e 74 20 72 65 67 65 78 70 2c 0a acement regexp,.
0f20: 2f 2f 2f 20 65 6e 73 75 72 65 73 20 62 6f 74 68 /// ensures both
0f30: 20 74 68 65 20 62 6f 74 20 61 6e 64 20 74 68 65 the bot and the
0f40: 20 63 6f 6d 6d 61 6e 64 20 73 65 6e 64 65 72 20 command sender
0f50: 61 72 65 20 61 64 6d 69 6e 69 73 74 72 61 74 6f are administrato
0f60: 72 73 20 6f 66 20 74 68 65 20 74 61 72 67 65 74 rs of the target
0f70: 20 63 68 61 6e 6e 65 6c 2c 20 61 6e 64 20 70 65 channel, and pe
0f80: 72 66 6f 72 6d 73 20 74 68 65 20 64 61 74 61 62 rforms the datab
0f90: 61 73 65 20 75 70 64 61 74 65 2e 0a 2f 2f 2f 0a ase update..///.
0fa0: 2f 2f 2f 20 23 20 50 61 72 61 6d 65 74 65 72 73 /// # Parameters
0fb0: 0a 2f 2f 2f 0a 2f 2f 2f 20 2d 20 60 63 6f 6d 6d .///./// - `comm
0fc0: 61 6e 64 60 20 e2 80 94 20 74 68 65 20 69 6e 76 and` — the inv
0fd0: 6f 6b 65 64 20 63 6f 6d 6d 61 6e 64 2c 20 65 78 oked command, ex
0fe0: 70 65 63 74 65 64 20 74 6f 20 62 65 20 65 69 74 pected to be eit
0ff0: 68 65 72 20 60 22 2f 75 70 64 61 74 65 22 60 20 her `"/update"`
1000: 28 66 6f 6c 6c 6f 77 65 64 20 62 79 20 61 20 6e (followed by a n
1010: 75 6d 65 72 69 63 20 73 6f 75 72 63 65 20 69 64 umeric source id
1020: 29 20 6f 72 20 60 22 2f 61 64 64 22 60 2e 0a 2f ) or `"/add"`../
1030: 2f 2f 20 2d 20 60 6d 73 67 60 20 e2 80 94 20 74 // - `msg` — t
1040: 68 65 20 69 6e 63 6f 6d 69 6e 67 20 54 65 6c 65 he incoming Tele
1050: 67 72 61 6d 20 6d 65 73 73 61 67 65 3b 20 75 73 gram message; us
1060: 65 64 20 74 6f 20 64 65 72 69 76 65 20 74 68 65 ed to derive the
1070: 20 63 6f 6d 6d 61 6e 64 20 73 65 6e 64 65 72 20 command sender
1080: 61 6e 64 20 74 61 72 67 65 74 20 63 68 61 74 20 and target chat
1090: 69 64 20 66 6f 72 20 74 68 65 20 72 65 70 6c 79 id for the reply
10a0: 2e 0a 2f 2f 2f 20 2d 20 60 77 6f 72 64 73 60 20 ../// - `words`
10b0: e2 80 94 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 — the command
10c0: 61 72 67 75 6d 65 6e 74 73 3a 20 66 6f 72 20 60 arguments: for `
10d0: 22 2f 61 64 64 22 60 20 65 78 70 65 63 74 65 64 "/add"` expected
10e0: 20 60 63 68 61 6e 6e 65 6c 20 75 72 6c 20 5b 69 `channel url [i
10f0: 76 5f 68 61 73 68 7c 27 2d 27 5d 20 5b 75 72 6c v_hash|'-'] [url
1100: 5f 72 65 7c 27 2d 27 5d 60 3b 20 66 6f 72 20 60 _re|'-']`; for `
1110: 22 2f 75 70 64 61 74 65 22 60 0a 2f 2f 2f 20 20 "/update"`.///
1120: 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 the first eleme
1130: 6e 74 20 6d 75 73 74 20 62 65 20 61 20 6e 75 6d nt must be a num
1140: 65 72 69 63 20 60 73 6f 75 72 63 65 5f 69 64 60 eric `source_id`
1150: 20 66 6f 6c 6c 6f 77 65 64 20 62 79 20 74 68 65 followed by the
1160: 20 73 61 6d 65 20 70 61 72 61 6d 65 74 65 72 73 same parameters
1170: 2e 0a 70 75 62 20 61 73 79 6e 63 20 66 6e 20 75 ..pub async fn u
1180: 70 64 61 74 65 20 28 63 6f 72 65 3a 20 26 43 6f pdate (core: &Co
1190: 72 65 2c 20 63 6f 6d 6d 61 6e 64 3a 20 26 73 74 re, command: &st
11a0: 72 2c 20 6d 73 67 3a 20 26 4d 65 73 73 61 67 65 r, msg: &Message
11b0: 2c 20 77 6f 72 64 73 3a 20 26 5b 53 74 72 69 6e , words: &[Strin
11c0: 67 5d 29 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 g]) -> Result<()
11d0: 3e 20 7b 0a 09 6c 65 74 20 73 65 6e 64 65 72 20 > {..let sender
11e0: 3d 20 6d 73 67 2e 73 65 6e 64 65 72 2e 67 65 74 = msg.sender.get
11f0: 5f 75 73 65 72 5f 69 64 28 29 0a 09 09 2e 73 74 _user_id()....st
1200: 61 63 6b 5f 65 72 72 28 22 49 67 6e 6f 72 69 6e ack_err("Ignorin
1210: 67 20 75 6e 72 65 61 6c 20 75 73 65 72 73 2e 22 g unreal users."
1220: 29 3f 3b 0a 09 6c 65 74 20 6d 75 74 20 73 6f 75 )?;..let mut sou
1230: 72 63 65 5f 69 64 3a 20 4f 70 74 69 6f 6e 3c 69 rce_id: Option<i
1240: 33 32 3e 20 3d 20 4e 6f 6e 65 3b 0a 09 6c 65 74 32> = None;..let
1250: 20 61 74 5f 6c 65 61 73 74 20 3d 20 22 52 65 71 at_least = "Req
1260: 75 69 72 65 73 20 61 74 20 6c 65 61 73 74 20 33 uires at least 3
1270: 20 70 61 72 61 6d 65 74 65 72 73 2e 22 3b 0a 09 parameters.";..
1280: 6c 65 74 20 6d 75 74 20 69 5f 77 6f 72 64 73 20 let mut i_words
1290: 3d 20 77 6f 72 64 73 2e 69 74 65 72 28 29 3b 0a = words.iter();.
12a0: 09 6d 61 74 63 68 20 63 6f 6d 6d 61 6e 64 20 7b .match command {
12b0: 0a 09 09 22 2f 75 70 64 61 74 65 22 20 3d 3e 20 ..."/update" =>
12c0: 7b 0a 09 09 09 6c 65 74 20 6e 65 78 74 5f 77 6f {....let next_wo
12d0: 72 64 20 3d 20 69 5f 77 6f 72 64 73 2e 6e 65 78 rd = i_words.nex
12e0: 74 28 29 2e 63 6f 6e 74 65 78 74 28 61 74 5f 6c t().context(at_l
12f0: 65 61 73 74 29 3f 3b 0a 09 09 09 73 6f 75 72 63 east)?;....sourc
1300: 65 5f 69 64 20 3d 20 53 6f 6d 65 28 6e 65 78 74 e_id = Some(next
1310: 5f 77 6f 72 64 2e 70 61 72 73 65 3a 3a 3c 69 33 _word.parse::<i3
1320: 32 3e 28 29 0a 09 09 09 09 2e 63 6f 6e 74 65 78 2>()......contex
1330: 74 28 66 6f 72 6d 61 74 21 28 22 49 20 6e 65 65 t(format!("I nee
1340: 64 20 61 20 6e 75 6d 62 65 72 2c 20 62 75 74 20 d a number, but
1350: 67 6f 74 20 7b 6e 65 78 74 5f 77 6f 72 64 7d 2e got {next_word}.
1360: 22 29 29 3f 29 3b 0a 09 09 7d 2c 0a 09 09 22 2f "))?);...},..."/
1370: 61 64 64 22 20 3d 3e 20 7b 7d 2c 0a 09 09 5f 20 add" => {},..._
1380: 3d 3e 20 62 61 69 6c 21 28 22 50 61 73 73 69 6e => bail!("Passin
1390: 67 20 7b 63 6f 6d 6d 61 6e 64 7d 20 69 73 20 6e g {command} is n
13a0: 6f 74 20 70 6f 73 73 69 62 6c 65 20 68 65 72 65 ot possible here
13b0: 2e 22 29 2c 0a 09 7d 3b 0a 09 6c 65 74 20 28 63 ."),..};..let (c
13c0: 68 61 6e 6e 65 6c 2c 20 75 72 6c 2c 20 69 76 5f hannel, url, iv_
13d0: 68 61 73 68 2c 20 75 72 6c 5f 72 65 29 20 3d 20 hash, url_re) =
13e0: 28 0a 09 09 69 5f 77 6f 72 64 73 2e 6e 65 78 74 (...i_words.next
13f0: 28 29 2e 63 6f 6e 74 65 78 74 28 61 74 5f 6c 65 ().context(at_le
1400: 61 73 74 29 3f 2c 0a 09 09 69 5f 77 6f 72 64 73 ast)?,...i_words
1410: 2e 6e 65 78 74 28 29 2e 63 6f 6e 74 65 78 74 28 .next().context(
1420: 61 74 5f 6c 65 61 73 74 29 3f 2c 0a 09 09 69 5f at_least)?,...i_
1430: 77 6f 72 64 73 2e 6e 65 78 74 28 29 2c 0a 09 09 words.next(),...
1440: 69 5f 77 6f 72 64 73 2e 6e 65 78 74 28 29 29 3b i_words.next());
1450: 0a 09 69 66 20 21 20 52 45 5f 55 53 45 52 4e 41 ..if ! RE_USERNA
1460: 4d 45 2e 69 73 5f 6d 61 74 63 68 28 63 68 61 6e ME.is_match(chan
1470: 6e 65 6c 29 20 7b 0a 09 09 62 61 69 6c 21 28 22 nel) {...bail!("
1480: 55 73 65 72 6e 61 6d 65 73 20 73 68 6f 75 6c 64 Usernames should
1490: 20 62 65 20 73 6f 6d 65 74 68 69 6e 67 20 6c 69 be something li
14a0: 6b 65 20 5c 22 40 5c 5c 5b 61 5c 5c 2d 7a 41 5c ke \"@\\[a\\-zA\
14b0: 5c 2d 5a 5d 5c 5c 5b 61 5c 5c 2d 7a 41 5c 5c 2d \-Z]\\[a\\-zA\\-
14c0: 5a 30 5c 5c 2d 39 5c 5c 5f 5d 2b 5c 22 2c 20 61 Z0\\-9\\_]+\", a
14d0: 72 65 6e 27 74 20 74 68 65 79 3f 5c 6e 4e 6f 74 ren't they?\nNot
14e0: 20 7b 63 68 61 6e 6e 65 6c 3a 3f 7d 22 29 3b 0a {channel:?}");.
14f0: 09 7d 3b 0a 09 7b 0a 09 09 6c 65 74 20 70 61 72 .};..{...let par
1500: 73 65 64 5f 75 72 6c 20 3d 20 55 72 6c 3a 3a 70 sed_url = Url::p
1510: 61 72 73 65 28 75 72 6c 29 0a 09 09 09 2e 73 74 arse(url).....st
1520: 61 63 6b 5f 65 72 72 28 22 45 78 70 65 63 74 69 ack_err("Expecti
1530: 6e 67 20 61 20 76 61 6c 69 64 20 6c 69 6e 6b 20 ng a valid link
1540: 74 6f 20 41 54 4f 4d 2f 52 53 53 20 66 65 65 64 to ATOM/RSS feed
1550: 2e 22 29 3f 3b 0a 09 09 6d 61 74 63 68 20 70 61 .")?;...match pa
1560: 72 73 65 64 5f 75 72 6c 2e 73 63 68 65 6d 65 28 rsed_url.scheme(
1570: 29 20 7b 0a 09 09 09 22 68 74 74 70 22 20 7c 20 ) {...."http" |
1580: 22 68 74 74 70 73 22 20 3d 3e 20 7b 7d 2c 0a 09 "https" => {},..
1590: 09 09 73 63 68 65 6d 65 20 3d 3e 20 7b 0a 09 09 ..scheme => {...
15a0: 09 09 62 61 69 6c 21 28 22 55 6e 73 75 70 70 6f ..bail!("Unsuppo
15b0: 72 74 65 64 20 55 52 4c 20 73 63 68 65 6d 65 3a rted URL scheme:
15c0: 20 7b 73 63 68 65 6d 65 7d 22 29 3b 0a 09 09 09 {scheme}");....
15d0: 7d 2c 0a 09 09 7d 3b 0a 09 7d 0a 09 6c 65 74 20 },...};..}..let
15e0: 69 76 5f 68 61 73 68 20 3d 20 6d 61 74 63 68 20 iv_hash = match
15f0: 69 76 5f 68 61 73 68 20 7b 0a 09 09 53 6f 6d 65 iv_hash {...Some
1600: 28 68 61 73 68 29 20 3d 3e 20 7b 0a 09 09 09 6d (hash) => {....m
1610: 61 74 63 68 20 68 61 73 68 2e 61 73 5f 72 65 66 atch hash.as_ref
1620: 28 29 20 7b 0a 09 09 09 09 22 2d 22 20 3d 3e 20 () {....."-" =>
1630: 4e 6f 6e 65 2c 0a 09 09 09 09 74 68 69 6e 67 20 None,.....thing
1640: 3d 3e 20 7b 0a 09 09 09 09 09 69 66 20 21 20 52 => {......if ! R
1650: 45 5f 49 56 5f 48 41 53 48 2e 69 73 5f 6d 61 74 E_IV_HASH.is_mat
1660: 63 68 28 74 68 69 6e 67 29 20 7b 0a 09 09 09 09 ch(thing) {.....
1670: 09 09 62 61 69 6c 21 28 22 49 56 20 68 61 73 68 ..bail!("IV hash
1680: 20 73 68 6f 75 6c 64 20 62 65 20 31 34 20 68 65 should be 14 he
1690: 78 20 64 69 67 69 74 73 2e 5c 6e 4e 6f 74 20 7b x digits.\nNot {
16a0: 74 68 69 6e 67 3a 3f 7d 22 29 3b 0a 09 09 09 09 thing:?}");.....
16b0: 09 7d 3b 0a 09 09 09 09 09 53 6f 6d 65 28 74 68 .};......Some(th
16c0: 69 6e 67 29 0a 09 09 09 09 7d 2c 0a 09 09 09 7d ing).....},....}
16d0: 0a 09 09 7d 2c 0a 09 09 4e 6f 6e 65 20 3d 3e 20 ...},...None =>
16e0: 4e 6f 6e 65 2c 0a 09 7d 3b 0a 09 6c 65 74 20 75 None,..};..let u
16f0: 72 6c 5f 72 65 20 3d 20 6d 61 74 63 68 20 75 72 rl_re = match ur
1700: 6c 5f 72 65 20 7b 0a 09 09 53 6f 6d 65 28 72 65 l_re {...Some(re
1710: 29 20 3d 3e 20 7b 0a 09 09 09 6d 61 74 63 68 20 ) => {....match
1720: 72 65 2e 61 73 5f 72 65 66 28 29 20 7b 0a 09 09 re.as_ref() {...
1730: 09 09 22 2d 22 20 3d 3e 20 4e 6f 6e 65 2c 0a 09 .."-" => None,..
1740: 09 09 09 74 68 69 6e 67 20 3d 3e 20 7b 0a 09 09 ...thing => {...
1750: 09 09 09 6c 65 74 20 5f 75 72 6c 5f 72 65 78 20 ...let _url_rex
1760: 3d 20 52 65 70 6c 61 63 65 43 6f 6d 6d 61 6e 64 = ReplaceCommand
1770: 3a 3a 6e 65 77 28 74 68 69 6e 67 29 2e 63 6f 6e ::new(thing).con
1780: 74 65 78 74 28 22 52 65 67 65 78 70 20 70 61 72 text("Regexp par
1790: 73 69 6e 67 20 65 72 72 6f 72 3a 22 29 3f 3b 0a sing error:")?;.
17a0: 09 09 09 09 09 53 6f 6d 65 28 74 68 69 6e 67 29 .....Some(thing)
17b0: 0a 09 09 09 09 7d 0a 09 09 09 7d 0a 09 09 7d 2c .....}....}...},
17c0: 0a 09 09 4e 6f 6e 65 20 3d 3e 20 4e 6f 6e 65 2c ...None => None,
17d0: 0a 09 7d 3b 0a 09 6c 65 74 20 63 68 61 74 5f 69 ..};..let chat_i
17e0: 64 20 3d 20 43 68 61 74 55 73 65 72 6e 61 6d 65 d = ChatUsername
17f0: 3a 3a 66 72 6f 6d 28 63 68 61 6e 6e 65 6c 2e 61 ::from(channel.a
1800: 73 5f 72 65 66 28 29 29 3b 0a 09 6c 65 74 20 63 s_ref());..let c
1810: 68 61 6e 6e 65 6c 5f 69 64 20 3d 20 63 6f 72 65 hannel_id = core
1820: 2e 74 67 2e 63 6c 69 65 6e 74 2e 65 78 65 63 75 .tg.client.execu
1830: 74 65 28 47 65 74 43 68 61 74 3a 3a 6e 65 77 28 te(GetChat::new(
1840: 63 68 61 74 5f 69 64 2e 63 6c 6f 6e 65 28 29 29 chat_id.clone())
1850: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 5f 65 72 ).await.stack_er
1860: 72 28 22 67 65 74 74 69 6e 67 20 47 65 74 43 68 r("getting GetCh
1870: 61 74 22 29 3f 2e 69 64 3b 0a 09 6c 65 74 20 63 at")?.id;..let c
1880: 68 61 6e 5f 61 64 6d 20 3d 20 63 6f 72 65 2e 74 han_adm = core.t
1890: 67 2e 63 6c 69 65 6e 74 2e 65 78 65 63 75 74 65 g.client.execute
18a0: 28 47 65 74 43 68 61 74 41 64 6d 69 6e 69 73 74 (GetChatAdminist
18b0: 72 61 74 6f 72 73 3a 3a 6e 65 77 28 63 68 61 74 rators::new(chat
18c0: 5f 69 64 29 29 2e 61 77 61 69 74 0a 09 09 2e 63 _id)).await....c
18d0: 6f 6e 74 65 78 74 28 22 53 6f 72 72 79 2c 20 49 ontext("Sorry, I
18e0: 20 68 61 76 65 20 6e 6f 20 61 63 63 65 73 73 20 have no access
18f0: 74 6f 20 74 68 61 74 20 63 68 61 74 2e 22 29 3f to that chat.")?
1900: 3b 0a 09 6c 65 74 20 28 6d 75 74 20 6d 65 2c 20 ;..let (mut me,
1910: 6d 75 74 20 75 73 65 72 29 20 3d 20 28 66 61 6c mut user) = (fal
1920: 73 65 2c 20 66 61 6c 73 65 29 3b 0a 09 66 6f 72 se, false);..for
1930: 20 61 64 6d 69 6e 20 69 6e 20 63 68 61 6e 5f 61 admin in chan_a
1940: 64 6d 20 7b 0a 09 09 6c 65 74 20 6d 65 6d 62 65 dm {...let membe
1950: 72 5f 69 64 20 3d 20 6d 61 74 63 68 20 61 64 6d r_id = match adm
1960: 69 6e 20 7b 0a 09 09 09 43 68 61 74 4d 65 6d 62 in {....ChatMemb
1970: 65 72 3a 3a 43 72 65 61 74 6f 72 28 6d 65 6d 62 er::Creator(memb
1980: 65 72 29 20 3d 3e 20 6d 65 6d 62 65 72 2e 75 73 er) => member.us
1990: 65 72 2e 69 64 2c 0a 09 09 09 43 68 61 74 4d 65 er.id,....ChatMe
19a0: 6d 62 65 72 3a 3a 41 64 6d 69 6e 69 73 74 72 61 mber::Administra
19b0: 74 6f 72 28 6d 65 6d 62 65 72 29 20 3d 3e 20 6d tor(member) => m
19c0: 65 6d 62 65 72 2e 75 73 65 72 2e 69 64 2c 0a 09 ember.user.id,..
19d0: 09 09 43 68 61 74 4d 65 6d 62 65 72 3a 3a 4c 65 ..ChatMember::Le
19e0: 66 74 28 5f 29 0a 09 09 09 7c 20 43 68 61 74 4d ft(_)....| ChatM
19f0: 65 6d 62 65 72 3a 3a 4b 69 63 6b 65 64 28 5f 29 ember::Kicked(_)
1a00: 0a 09 09 09 7c 20 43 68 61 74 4d 65 6d 62 65 72 ....| ChatMember
1a10: 3a 3a 4d 65 6d 62 65 72 7b 2e 2e 7d 0a 09 09 09 ::Member{..}....
1a20: 7c 20 43 68 61 74 4d 65 6d 62 65 72 3a 3a 52 65 | ChatMember::Re
1a30: 73 74 72 69 63 74 65 64 28 5f 29 20 3d 3e 20 63 stricted(_) => c
1a40: 6f 6e 74 69 6e 75 65 2c 0a 09 09 7d 3b 0a 09 09 ontinue,...};...
1a50: 69 66 20 6d 65 6d 62 65 72 5f 69 64 20 3d 3d 20 if member_id ==
1a60: 63 6f 72 65 2e 74 67 2e 6d 65 2e 69 64 20 7b 0a core.tg.me.id {.
1a70: 09 09 09 6d 65 20 3d 20 74 72 75 65 3b 0a 09 09 ...me = true;...
1a80: 7d 0a 09 09 69 66 20 6d 65 6d 62 65 72 5f 69 64 }...if member_id
1a90: 20 3d 3d 20 73 65 6e 64 65 72 20 7b 0a 09 09 09 == sender {....
1aa0: 75 73 65 72 20 3d 20 74 72 75 65 3b 0a 09 09 7d user = true;...}
1ab0: 0a 09 7d 3b 0a 09 69 66 20 21 20 6d 65 20 20 20 ..};..if ! me
1ac0: 7b 20 62 61 69 6c 21 28 22 49 20 6e 65 65 64 20 { bail!("I need
1ad0: 74 6f 20 62 65 20 61 64 6d 69 6e 20 6f 6e 20 74 to be admin on t
1ae0: 68 61 74 20 63 68 61 6e 6e 65 6c 2e 22 29 3b 20 hat channel.");
1af0: 7d 3b 0a 09 69 66 20 21 20 75 73 65 72 20 7b 20 };..if ! user {
1b00: 62 61 69 6c 21 28 22 59 6f 75 20 73 68 6f 75 6c bail!("You shoul
1b10: 64 20 62 65 20 61 64 6d 69 6e 20 6f 6e 20 74 68 d be admin on th
1b20: 61 74 20 63 68 61 6e 6e 65 6c 2e 22 29 3b 20 7d at channel."); }
1b30: 3b 0a 09 6c 65 74 20 6d 75 74 20 63 6f 6e 6e 20 ;..let mut conn
1b40: 3d 20 63 6f 72 65 2e 64 62 2e 62 65 67 69 6e 28 = core.db.begin(
1b50: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
1b60: 3b 0a 09 6c 65 74 20 75 70 64 61 74 65 20 3d 20 ;..let update =
1b70: 63 6f 6e 6e 2e 75 70 64 61 74 65 28 73 6f 75 72 conn.update(sour
1b80: 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65 6c 2c 20 ce_id, channel,
1b90: 63 68 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c channel_id, url,
1ba0: 20 69 76 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65 iv_hash, url_re
1bb0: 2c 20 73 65 6e 64 65 72 29 2e 61 77 61 69 74 2e , sender).await.
1bc0: 73 74 61 63 6b 28 29 3f 3b 0a 09 63 6f 72 65 2e stack()?;..core.
1bd0: 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73 73 61 67 tg.send(MyMessag
1be0: 65 3a 3a 68 74 6d 6c 5f 74 6f 28 75 70 64 61 74 e::html_to(updat
1bf0: 65 2c 20 6d 73 67 2e 63 68 61 74 2e 67 65 74 5f e, msg.chat.get_
1c00: 69 64 28 29 29 29 2e 61 77 61 69 74 2e 73 74 61 id())).await.sta
1c10: 63 6b 28 29 3f 3b 0a 09 69 66 20 63 6f 6d 6d 61 ck()?;..if comma
1c20: 6e 64 20 3d 3d 20 22 2f 61 64 64 22 20 7b 0a 09 nd == "/add" {..
1c30: 09 69 66 20 6c 65 74 20 53 6f 6d 65 28 6e 65 77 .if let Some(new
1c40: 5f 72 65 63 6f 72 64 29 20 3d 20 63 6f 6e 6e 2e _record) = conn.
1c50: 67 65 74 5f 6f 6e 65 5f 6e 61 6d 65 28 73 65 6e get_one_name(sen
1c60: 64 65 72 2c 20 63 68 61 6e 6e 65 6c 29 2e 61 77 der, channel).aw
1c70: 61 69 74 2e 73 74 61 63 6b 28 29 3f 20 7b 0a 09 ait.stack()? {..
1c80: 09 09 63 6f 72 65 2e 61 64 64 5f 66 65 65 64 28 ..core.add_feed(
1c90: 73 65 6e 64 65 72 2e 69 6e 74 6f 28 29 2c 20 6e sender.into(), n
1ca0: 65 77 5f 72 65 63 6f 72 64 2e 73 6f 75 72 63 65 ew_record.source
1cb0: 5f 69 64 2c 20 6e 65 77 5f 72 65 63 6f 72 64 2e _id, new_record.
1cc0: 63 68 61 6e 6e 65 6c 29 2e 61 77 61 69 74 2e 73 channel).await.s
1cd0: 74 61 63 6b 28 29 3f 3b 0a 09 09 7d 20 65 6c 73 tack()?;...} els
1ce0: 65 20 7b 0a 09 09 09 62 61 69 6c 21 28 22 46 61 e {....bail!("Fa
1cf0: 69 6c 65 64 20 74 6f 20 72 65 61 64 20 64 61 74 iled to read dat
1d00: 61 20 6f 6e 20 66 72 65 73 68 6c 79 20 69 6e 73 a on freshly ins
1d10: 65 72 74 65 64 20 73 6f 75 72 63 65 2e 22 29 3b erted source.");
1d20: 0a 09 09 7d 0a 09 7d 3b 0a 09 4f 6b 28 28 29 29 ...}..};..Ok(())
1d30: 0a 7d 0a .}.