Hex Artifact Content
Logged in as anonymous

Artifact adc7f1bfb3c9511e308a94571cf3c9cdbf733c06d9b88b3c36e2ecfea92dfe90:


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 61 6c 6c 62  :types::{..Callb
00f0: 61 63 6b 51 75 65 72 79 2c 0a 09 43 68 61 74 2c  ackQuery,..Chat,
0100: 0a 09 43 68 61 74 4d 65 6d 62 65 72 2c 0a 09 43  ..ChatMember,..C
0110: 68 61 74 55 73 65 72 6e 61 6d 65 2c 0a 09 47 65  hatUsername,..Ge
0120: 74 43 68 61 74 2c 0a 09 47 65 74 43 68 61 74 41  tChat,..GetChatA
0130: 64 6d 69 6e 69 73 74 72 61 74 6f 72 73 2c 0a 09  dministrators,..
0140: 4d 61 79 62 65 49 6e 61 63 63 65 73 73 69 62 6c  MaybeInaccessibl
0150: 65 4d 65 73 73 61 67 65 2c 0a 09 4d 65 73 73 61  eMessage,..Messa
0160: 67 65 2c 0a 7d 3b 0a 75 73 65 20 75 72 6c 3a 3a  ge,.};.use url::
0170: 55 72 6c 3b 0a 0a 6c 61 7a 79 5f 73 74 61 74 69  Url;..lazy_stati
0180: 63 21 20 7b 0a 09 73 74 61 74 69 63 20 72 65 66  c! {..static ref
0190: 20 52 45 5f 55 53 45 52 4e 41 4d 45 3a 20 52 65   RE_USERNAME: Re
01a0: 67 65 78 20 3d 20 52 65 67 65 78 3a 3a 6e 65 77  gex = Regex::new
01b0: 28 72 22 5e 40 28 5b 61 2d 7a 41 2d 5a 5d 5b 61  (r"^@([a-zA-Z][a
01c0: 2d 7a 41 2d 5a 30 2d 39 5f 5d 2b 29 24 22 29 2e  -zA-Z0-9_]+)$").
01d0: 75 6e 77 72 61 70 28 29 3b 0a 09 73 74 61 74 69  unwrap();..stati
01e0: 63 20 72 65 66 20 52 45 5f 49 56 5f 48 41 53 48  c ref RE_IV_HASH
01f0: 3a 20 52 65 67 65 78 20 3d 20 52 65 67 65 78 3a  : Regex = Regex:
0200: 3a 6e 65 77 28 72 22 5e 5b 61 2d 66 30 2d 39 5d  :new(r"^[a-f0-9]
0210: 7b 31 34 7d 24 22 29 2e 75 6e 77 72 61 70 28 29  {14}$").unwrap()
0220: 3b 0a 7d 0a 0a 2f 2f 2f 20 53 65 6e 64 73 20 61  ;.}../// Sends a
0230: 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 61 6c 20  n informational 
0240: 6d 65 73 73 61 67 65 20 74 6f 20 74 68 65 20 6d  message to the m
0250: 65 73 73 61 67 65 27 73 20 63 68 61 74 20 6c 69  essage's chat li
0260: 6e 6b 69 6e 67 20 74 6f 20 74 68 65 20 62 6f 74  nking to the bot
0270: 20 68 65 6c 70 20 63 68 61 6e 6e 65 6c 2e 0a 70   help channel..p
0280: 75 62 20 61 73 79 6e 63 20 66 6e 20 73 74 61 72  ub async fn star
0290: 74 20 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c 20  t (core: &Core, 
02a0: 6d 73 67 3a 20 26 4d 65 73 73 61 67 65 29 20 2d  msg: &Message) -
02b0: 3e 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09  > Result<()> {..
02c0: 63 6f 72 65 2e 74 67 2e 73 65 6e 64 28 4d 79 4d  core.tg.send(MyM
02d0: 65 73 73 61 67 65 3a 3a 68 74 6d 6c 5f 74 6f 28  essage::html_to(
02e0: 0a 09 09 22 57 65 20 61 72 65 20 6f 70 65 6e 2e  ..."We are open.
02f0: 20 50 72 6f 62 61 62 6c 79 2e 20 56 69 73 69 74   Probably. Visit
0300: 20 3c 61 20 68 72 65 66 3d 5c 22 68 74 74 70 73   <a href=\"https
0310: 3a 2f 2f 74 2e 6d 65 2f 72 73 73 74 67 5f 62 6f  ://t.me/rsstg_bo
0320: 74 5f 68 65 6c 70 2f 33 5c 22 3e 63 68 61 6e 6e  t_help/3\">chann
0330: 65 6c 3c 2f 61 3e 29 20 66 6f 72 20 64 65 74 61  el</a>) for deta
0340: 69 6c 73 2e 22 2c 0a 09 09 6d 73 67 2e 63 68 61  ils.",...msg.cha
0350: 74 2e 67 65 74 5f 69 64 28 29 0a 09 29 29 2e 61  t.get_id()..)).a
0360: 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09  wait.stack()?;..
0370: 4f 6b 28 28 29 29 0a 7d 0a 0a 2f 2f 2f 20 53 65  Ok(()).}../// Se
0380: 6e 64 20 74 68 65 20 73 65 6e 64 65 72 27 73 20  nd the sender's 
0390: 73 75 62 73 63 72 69 70 74 69 6f 6e 20 6c 69 73  subscription lis
03a0: 74 20 74 6f 20 74 68 65 20 63 68 61 74 2e 0a 2f  t to the chat../
03b0: 2f 2f 0a 2f 2f 2f 20 52 65 74 72 69 65 76 65 73  //./// Retrieves
03c0: 20 74 68 65 20 6d 65 73 73 61 67 65 20 73 65 6e   the message sen
03d0: 64 65 72 27 73 20 75 73 65 72 20 49 44 2c 20 6f  der's user ID, o
03e0: 62 74 61 69 6e 73 20 74 68 65 69 72 20 73 75 62  btains their sub
03f0: 73 63 72 69 70 74 69 6f 6e 20 6c 69 73 74 20 66  scription list f
0400: 72 6f 6d 20 60 63 6f 72 65 60 2c 0a 2f 2f 2f 20  rom `core`,./// 
0410: 61 6e 64 20 73 65 6e 64 73 20 74 68 65 20 72 65  and sends the re
0420: 73 75 6c 74 69 6e 67 20 72 65 70 6c 79 20 69 6e  sulting reply in
0430: 74 6f 20 74 68 65 20 6d 65 73 73 61 67 65 20 63  to the message c
0440: 68 61 74 20 75 73 69 6e 67 20 4d 61 72 6b 64 6f  hat using Markdo
0450: 77 6e 56 32 2e 0a 70 75 62 20 61 73 79 6e 63 20  wnV2..pub async 
0460: 66 6e 20 6c 69 73 74 20 28 63 6f 72 65 3a 20 26  fn list (core: &
0470: 43 6f 72 65 2c 20 6d 73 67 3a 20 26 4d 65 73 73  Core, msg: &Mess
0480: 61 67 65 29 20 2d 3e 20 52 65 73 75 6c 74 3c 28  age) -> Result<(
0490: 29 3e 20 7b 0a 09 6c 65 74 20 73 65 6e 64 65 72  )> {..let sender
04a0: 20 3d 20 6d 73 67 2e 73 65 6e 64 65 72 2e 67 65   = msg.sender.ge
04b0: 74 5f 75 73 65 72 5f 69 64 28 29 0a 09 09 2e 73  t_user_id()....s
04c0: 74 61 63 6b 5f 65 72 72 28 22 49 67 6e 6f 72 69  tack_err("Ignori
04d0: 6e 67 20 75 6e 72 65 61 6c 20 75 73 65 72 73 2e  ng unreal users.
04e0: 22 29 3f 3b 0a 09 6c 65 74 20 72 65 70 6c 79 20  ")?;..let reply 
04f0: 3d 20 63 6f 72 65 2e 6c 69 73 74 28 73 65 6e 64  = core.list(send
0500: 65 72 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28  er).await.stack(
0510: 29 3f 3b 0a 09 63 6f 72 65 2e 74 67 2e 73 65 6e  )?;..core.tg.sen
0520: 64 28 4d 79 4d 65 73 73 61 67 65 3a 3a 68 74 6d  d(MyMessage::htm
0530: 6c 5f 74 6f 28 72 65 70 6c 79 2c 20 6d 73 67 2e  l_to(reply, msg.
0540: 63 68 61 74 2e 67 65 74 5f 69 64 28 29 29 29 2e  chat.get_id())).
0550: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a  await.stack()?;.
0560: 09 4f 6b 28 28 29 29 0a 7d 0a 0a 70 75 62 20 61  .Ok(()).}..pub a
0570: 73 79 6e 63 20 66 6e 20 74 65 73 74 20 28 63 6f  sync fn test (co
0580: 72 65 3a 20 26 43 6f 72 65 2c 20 6d 73 67 3a 20  re: &Core, msg: 
0590: 26 4d 65 73 73 61 67 65 29 20 2d 3e 20 52 65 73  &Message) -> Res
05a0: 75 6c 74 3c 28 29 3e 20 7b 0a 09 6c 65 74 20 73  ult<()> {..let s
05b0: 65 6e 64 65 72 3a 20 69 36 34 20 3d 20 6d 73 67  ender: i64 = msg
05c0: 2e 73 65 6e 64 65 72 2e 67 65 74 5f 75 73 65 72  .sender.get_user
05d0: 5f 69 64 28 29 0a 09 09 2e 73 74 61 63 6b 5f 65  _id()....stack_e
05e0: 72 72 28 22 49 67 6e 6f 72 69 6e 67 20 75 6e 72  rr("Ignoring unr
05f0: 65 61 6c 20 75 73 65 72 73 2e 22 29 3f 2e 69 6e  eal users.")?.in
0600: 74 6f 28 29 3b 0a 09 6c 65 74 20 66 65 65 64 73  to();..let feeds
0610: 20 3d 20 63 6f 72 65 2e 67 65 74 5f 66 65 65 64   = core.get_feed
0620: 73 28 73 65 6e 64 65 72 29 2e 61 77 61 69 74 2e  s(sender).await.
0630: 73 74 61 63 6b 28 29 3f 3b 0a 09 6c 65 74 20 6b  stack()?;..let k
0640: 62 20 3d 20 67 65 74 5f 6b 62 28 26 43 61 6c 6c  b = get_kb(&Call
0650: 62 61 63 6b 3a 3a 6d 65 6e 75 28 29 2c 20 26 66  back::menu(), &f
0660: 65 65 64 73 29 2e 61 77 61 69 74 2e 73 74 61 63  eeds).await.stac
0670: 6b 28 29 3f 3b 0a 09 63 6f 72 65 2e 74 67 2e 73  k()?;..core.tg.s
0680: 65 6e 64 28 4d 79 4d 65 73 73 61 67 65 3a 3a 68  end(MyMessage::h
0690: 74 6d 6c 5f 74 6f 5f 6b 62 28 22 4d 61 69 6e 20  tml_to_kb("Main 
06a0: 6d 65 6e 75 3a 22 2c 20 6d 73 67 2e 63 68 61 74  menu:", msg.chat
06b0: 2e 67 65 74 5f 69 64 28 29 2c 20 6b 62 29 29 2e  .get_id(), kb)).
06c0: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a  await.stack()?;.
06d0: 09 4f 6b 28 28 29 29 0a 7d 0a 0a 2f 2f 2f 20 48  .Ok(()).}../// H
06e0: 61 6e 64 6c 65 20 63 68 61 6e 6e 65 6c 2d 6d 61  andle channel-ma
06f0: 6e 61 67 65 6d 65 6e 74 20 63 6f 6d 6d 61 6e 64  nagement command
0700: 73 20 74 68 61 74 20 6f 70 65 72 61 74 65 20 6f  s that operate o
0710: 6e 20 61 20 73 69 6e 67 6c 65 20 6e 75 6d 65 72  n a single numer
0720: 69 63 20 73 6f 75 72 63 65 20 49 44 2e 0a 2f 2f  ic source ID..//
0730: 2f 0a 2f 2f 2f 20 54 68 69 73 20 76 61 6c 69 64  /./// This valid
0740: 61 74 65 73 20 74 68 61 74 20 65 78 61 63 74 6c  ates that exactl
0750: 79 20 6f 6e 65 20 6e 75 6d 65 72 69 63 20 61 72  y one numeric ar
0760: 67 75 6d 65 6e 74 20 69 73 20 70 72 6f 76 69 64  gument is provid
0770: 65 64 2c 20 70 65 72 66 6f 72 6d 73 20 74 68 65  ed, performs the
0780: 20 72 65 71 75 65 73 74 65 64 0a 2f 2f 2f 20 6f   requested./// o
0790: 70 65 72 61 74 69 6f 6e 20 28 63 68 65 63 6b 2c  peration (check,
07a0: 20 63 6c 65 61 6e 2c 20 65 6e 61 62 6c 65 2c 20   clean, enable, 
07b0: 64 65 6c 65 74 65 2c 20 64 69 73 61 62 6c 65 29  delete, disable)
07c0: 20 61 67 61 69 6e 73 74 20 74 68 65 20 64 61 74   against the dat
07d0: 61 62 61 73 65 20 6f 72 20 63 6f 72 65 2c 0a 2f  abase or core,./
07e0: 2f 2f 20 61 6e 64 20 73 65 6e 64 73 20 74 68 65  // and sends the
07f0: 20 72 65 73 75 6c 74 69 6e 67 20 72 65 70 6c 79   resulting reply
0800: 20 74 6f 20 74 68 65 20 63 68 61 74 2e 0a 2f 2f   to the chat..//
0810: 2f 0a 2f 2f 2f 20 23 20 50 61 72 61 6d 65 74 65  /./// # Paramete
0820: 72 73 0a 2f 2f 2f 0a 2f 2f 2f 20 2d 20 60 63 6f  rs.///./// - `co
0830: 72 65 60 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e  re`: application
0840: 20 63 6f 72 65 20 63 6f 6e 74 61 69 6e 69 6e 67   core containing
0850: 20 64 61 74 61 62 61 73 65 20 61 6e 64 20 54 65   database and Te
0860: 6c 65 67 72 61 6d 20 63 6c 69 65 6e 74 73 2e 0a  legram clients..
0870: 2f 2f 2f 20 2d 20 60 63 6f 6d 6d 61 6e 64 60 3a  /// - `command`:
0880: 20 63 6f 6d 6d 61 6e 64 20 73 74 72 69 6e 67 20   command string 
0890: 28 65 2e 67 2e 20 22 2f 63 68 65 63 6b 22 2c 20  (e.g. "/check", 
08a0: 22 2f 63 6c 65 61 6e 22 2c 20 22 2f 65 6e 61 62  "/clean", "/enab
08b0: 6c 65 22 2c 20 22 2f 64 65 6c 65 74 65 22 2c 20  le", "/delete", 
08c0: 22 2f 64 69 73 61 62 6c 65 22 29 2e 0a 2f 2f 2f  "/disable")..///
08d0: 20 2d 20 60 6d 73 67 60 3a 20 69 6e 63 6f 6d 69   - `msg`: incomi
08e0: 6e 67 20 54 65 6c 65 67 72 61 6d 20 6d 65 73 73  ng Telegram mess
08f0: 61 67 65 20 74 68 61 74 20 74 72 69 67 67 65 72  age that trigger
0900: 65 64 20 74 68 65 20 63 6f 6d 6d 61 6e 64 3b 20  ed the command; 
0910: 75 73 65 64 20 74 6f 20 64 65 74 65 72 6d 69 6e  used to determin
0920: 65 20 73 65 6e 64 65 72 20 61 6e 64 20 63 68 61  e sender and cha
0930: 74 2e 0a 2f 2f 2f 20 2d 20 60 77 6f 72 64 73 60  t../// - `words`
0940: 3a 20 63 6f 6d 6d 61 6e 64 20 61 72 67 75 6d 65  : command argume
0950: 6e 74 73 3b 20 65 78 70 65 63 74 65 64 20 74 6f  nts; expected to
0960: 20 63 6f 6e 74 61 69 6e 20 65 78 61 63 74 6c 79   contain exactly
0970: 20 6f 6e 65 20 65 6c 65 6d 65 6e 74 20 74 68 61   one element tha
0980: 74 20 70 61 72 73 65 73 20 61 73 20 61 20 33 32  t parses as a 32
0990: 2d 62 69 74 20 69 6e 74 65 67 65 72 2e 0a 70 75  -bit integer..pu
09a0: 62 20 61 73 79 6e 63 20 66 6e 20 63 6f 6d 6d 61  b async fn comma
09b0: 6e 64 20 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c  nd (core: &Core,
09c0: 20 63 6f 6d 6d 61 6e 64 3a 20 26 73 74 72 2c 20   command: &str, 
09d0: 6d 73 67 3a 20 26 4d 65 73 73 61 67 65 2c 20 77  msg: &Message, w
09e0: 6f 72 64 73 3a 20 26 5b 53 74 72 69 6e 67 5d 29  ords: &[String])
09f0: 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b   -> Result<()> {
0a00: 0a 09 6c 65 74 20 6d 75 74 20 63 6f 6e 6e 20 3d  ..let mut conn =
0a10: 20 63 6f 72 65 2e 64 62 2e 62 65 67 69 6e 28 29   core.db.begin()
0a20: 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b  .await.stack()?;
0a30: 0a 09 6c 65 74 20 73 65 6e 64 65 72 20 3d 20 6d  ..let sender = m
0a40: 73 67 2e 73 65 6e 64 65 72 2e 67 65 74 5f 75 73  sg.sender.get_us
0a50: 65 72 5f 69 64 28 29 0a 09 09 2e 73 74 61 63 6b  er_id()....stack
0a60: 5f 65 72 72 28 22 49 67 6e 6f 72 69 6e 67 20 75  _err("Ignoring u
0a70: 6e 72 65 61 6c 20 75 73 65 72 73 2e 22 29 3f 3b  nreal users.")?;
0a80: 0a 09 6c 65 74 20 72 65 70 6c 79 20 3d 20 69 66  ..let reply = if
0a90: 20 77 6f 72 64 73 2e 6c 65 6e 28 29 20 3d 3d 20   words.len() == 
0aa0: 31 20 7b 0a 09 09 6d 61 74 63 68 20 77 6f 72 64  1 {...match word
0ab0: 73 5b 30 5d 2e 70 61 72 73 65 3a 3a 3c 69 33 32  s[0].parse::<i32
0ac0: 3e 28 29 20 7b 0a 09 09 09 45 72 72 28 65 72 72  >() {....Err(err
0ad0: 29 20 3d 3e 20 66 6f 72 6d 61 74 21 28 22 49 20  ) => format!("I 
0ae0: 6e 65 65 64 20 61 20 6e 75 6d 62 65 72 2e 5c 6e  need a number.\n
0af0: 7b 7d 22 2c 20 26 65 72 72 29 2e 69 6e 74 6f 28  {}", &err).into(
0b00: 29 2c 0a 09 09 09 4f 6b 28 6e 75 6d 62 65 72 29  ),....Ok(number)
0b10: 20 3d 3e 20 6d 61 74 63 68 20 63 6f 6d 6d 61 6e   => match comman
0b20: 64 20 7b 0a 09 09 09 09 22 2f 63 68 65 63 6b 22  d {....."/check"
0b30: 20 3d 3e 20 63 6f 72 65 2e 63 68 65 63 6b 28 6e   => core.check(n
0b40: 75 6d 62 65 72 2c 20 66 61 6c 73 65 2c 20 4e 6f  umber, false, No
0b50: 6e 65 29 2e 61 77 61 69 74 0a 09 09 09 09 09 2e  ne).await.......
0b60: 63 6f 6e 74 65 78 74 28 22 43 68 61 6e 6e 65 6c  context("Channel
0b70: 20 63 68 65 63 6b 20 66 61 69 6c 65 64 2e 22 29   check failed.")
0b80: 3f 2e 69 6e 74 6f 28 29 2c 0a 09 09 09 09 22 2f  ?.into(),....."/
0b90: 63 6c 65 61 6e 22 20 3d 3e 20 63 6f 6e 6e 2e 63  clean" => conn.c
0ba0: 6c 65 61 6e 28 6e 75 6d 62 65 72 2c 20 73 65 6e  lean(number, sen
0bb0: 64 65 72 29 2e 61 77 61 69 74 2e 73 74 61 63 6b  der).await.stack
0bc0: 28 29 3f 2c 0a 09 09 09 09 22 2f 65 6e 61 62 6c  ()?,....."/enabl
0bd0: 65 22 20 3d 3e 20 63 6f 6e 6e 2e 65 6e 61 62 6c  e" => conn.enabl
0be0: 65 28 6e 75 6d 62 65 72 2c 20 73 65 6e 64 65 72  e(number, sender
0bf0: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f  ).await.stack()?
0c00: 2e 69 6e 74 6f 28 29 2c 0a 09 09 09 09 22 2f 64  .into(),....."/d
0c10: 65 6c 65 74 65 22 20 3d 3e 20 7b 0a 09 09 09 09  elete" => {.....
0c20: 09 6c 65 74 20 72 65 73 20 3d 20 63 6f 6e 6e 2e  .let res = conn.
0c30: 64 65 6c 65 74 65 28 6e 75 6d 62 65 72 2c 20 73  delete(number, s
0c40: 65 6e 64 65 72 29 2e 61 77 61 69 74 2e 73 74 61  ender).await.sta
0c50: 63 6b 28 29 3f 3b 0a 09 09 09 09 09 63 6f 72 65  ck()?;......core
0c60: 2e 72 6d 5f 66 65 65 64 28 73 65 6e 64 65 72 2e  .rm_feed(sender.
0c70: 69 6e 74 6f 28 29 2c 20 26 6e 75 6d 62 65 72 29  into(), &number)
0c80: 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b  .await.stack()?;
0c90: 0a 09 09 09 09 09 72 65 73 0a 09 09 09 09 7d 0a  ......res.....}.
0ca0: 09 09 09 09 22 2f 64 69 73 61 62 6c 65 22 20 3d  ...."/disable" =
0cb0: 3e 20 63 6f 6e 6e 2e 64 69 73 61 62 6c 65 28 6e  > conn.disable(n
0cc0: 75 6d 62 65 72 2c 20 73 65 6e 64 65 72 29 2e 61  umber, sender).a
0cd0: 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 2e 69 6e  wait.stack()?.in
0ce0: 74 6f 28 29 2c 0a 09 09 09 09 5f 20 3d 3e 20 62  to(),....._ => b
0cf0: 61 69 6c 21 28 22 43 6f 6d 6d 61 6e 64 20 7b 63  ail!("Command {c
0d00: 6f 6d 6d 61 6e 64 7d 20 7b 77 6f 72 64 73 3a 3f  ommand} {words:?
0d10: 7d 20 6e 6f 74 20 68 61 6e 64 6c 65 64 2e 22 29  } not handled.")
0d20: 2c 0a 09 09 09 7d 2c 0a 09 09 7d 0a 09 7d 20 65  ,....},...}..} e
0d30: 6c 73 65 20 7b 0a 09 09 22 54 68 69 73 20 63 6f  lse {..."This co
0d40: 6d 6d 61 6e 64 20 6e 65 65 64 73 20 65 78 61 63  mmand needs exac
0d50: 74 6c 79 20 6f 6e 65 20 6e 75 6d 62 65 72 2e 22  tly one number."
0d60: 2e 69 6e 74 6f 28 29 0a 09 7d 3b 0a 09 63 6f 72  .into()..};..cor
0d70: 65 2e 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73 73  e.tg.send(MyMess
0d80: 61 67 65 3a 3a 68 74 6d 6c 5f 74 6f 28 72 65 70  age::html_to(rep
0d90: 6c 79 2c 20 6d 73 67 2e 63 68 61 74 2e 67 65 74  ly, msg.chat.get
0da0: 5f 69 64 28 29 29 29 2e 61 77 61 69 74 2e 73 74  _id())).await.st
0db0: 61 63 6b 28 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a  ack()?;..Ok(()).
0dc0: 7d 0a 0a 2f 2f 2f 20 56 61 6c 69 64 61 74 65 20  }../// Validate 
0dd0: 63 6f 6d 6d 61 6e 64 20 61 72 67 75 6d 65 6e 74  command argument
0de0: 73 2c 20 63 68 65 63 6b 20 70 65 72 6d 69 73 73  s, check permiss
0df0: 69 6f 6e 73 20 61 6e 64 20 75 70 64 61 74 65 20  ions and update 
0e00: 6f 72 20 61 64 64 20 61 20 63 68 61 6e 6e 65 6c  or add a channel
0e10: 20 66 65 65 64 20 63 6f 6e 66 69 67 75 72 61 74   feed configurat
0e20: 69 6f 6e 20 69 6e 20 74 68 65 20 64 61 74 61 62  ion in the datab
0e30: 61 73 65 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 54 68 69  ase..///./// Thi
0e40: 73 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 73 65  s function parse
0e50: 73 20 61 6e 64 20 76 61 6c 69 64 61 74 65 73 20  s and validates 
0e60: 70 61 72 61 6d 65 74 65 72 73 20 73 75 70 70 6c  parameters suppl
0e70: 69 65 64 20 62 79 20 61 20 75 73 65 72 20 63 6f  ied by a user co
0e80: 6d 6d 61 6e 64 20 28 65 69 74 68 65 72 20 22 2f  mmand (either "/
0e90: 75 70 64 61 74 65 20 3c 69 64 3e 20 2e 2e 2e 22  update <id> ..."
0ea0: 20 6f 72 20 22 2f 61 64 64 20 2e 2e 2e 22 29 2c   or "/add ..."),
0eb0: 0a 2f 2f 2f 20 76 65 72 69 66 69 65 73 20 74 68  ./// verifies th
0ec0: 65 20 63 68 61 6e 6e 65 6c 20 75 73 65 72 6e 61  e channel userna
0ed0: 6d 65 20 61 6e 64 20 66 65 65 64 20 55 52 4c 2c  me and feed URL,
0ee0: 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 76 61 6c 69   optionally vali
0ef0: 64 61 74 65 73 20 61 6e 20 49 56 20 68 61 73 68  dates an IV hash
0f00: 20 61 6e 64 20 61 20 72 65 70 6c 61 63 65 6d 65   and a replaceme
0f10: 6e 74 20 72 65 67 65 78 70 2c 0a 2f 2f 2f 20 65  nt regexp,./// e
0f20: 6e 73 75 72 65 73 20 62 6f 74 68 20 74 68 65 20  nsures both the 
0f30: 62 6f 74 20 61 6e 64 20 74 68 65 20 63 6f 6d 6d  bot and the comm
0f40: 61 6e 64 20 73 65 6e 64 65 72 20 61 72 65 20 61  and sender are a
0f50: 64 6d 69 6e 69 73 74 72 61 74 6f 72 73 20 6f 66  dministrators of
0f60: 20 74 68 65 20 74 61 72 67 65 74 20 63 68 61 6e   the target chan
0f70: 6e 65 6c 2c 20 61 6e 64 20 70 65 72 66 6f 72 6d  nel, and perform
0f80: 73 20 74 68 65 20 64 61 74 61 62 61 73 65 20 75  s the database u
0f90: 70 64 61 74 65 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 23  pdate..///./// #
0fa0: 20 50 61 72 61 6d 65 74 65 72 73 0a 2f 2f 2f 0a   Parameters.///.
0fb0: 2f 2f 2f 20 2d 20 60 63 6f 6d 6d 61 6e 64 60 20  /// - `command` 
0fc0: e2 80 94 20 74 68 65 20 69 6e 76 6f 6b 65 64 20  — the invoked 
0fd0: 63 6f 6d 6d 61 6e 64 2c 20 65 78 70 65 63 74 65  command, expecte
0fe0: 64 20 74 6f 20 62 65 20 65 69 74 68 65 72 20 60  d to be either `
0ff0: 22 2f 75 70 64 61 74 65 22 60 20 28 66 6f 6c 6c  "/update"` (foll
1000: 6f 77 65 64 20 62 79 20 61 20 6e 75 6d 65 72 69  owed by a numeri
1010: 63 20 73 6f 75 72 63 65 20 69 64 29 20 6f 72 20  c source id) or 
1020: 60 22 2f 61 64 64 22 60 2e 0a 2f 2f 2f 20 2d 20  `"/add"`../// - 
1030: 60 6d 73 67 60 20 e2 80 94 20 74 68 65 20 69 6e  `msg` — the in
1040: 63 6f 6d 69 6e 67 20 54 65 6c 65 67 72 61 6d 20  coming Telegram 
1050: 6d 65 73 73 61 67 65 3b 20 75 73 65 64 20 74 6f  message; used to
1060: 20 64 65 72 69 76 65 20 74 68 65 20 63 6f 6d 6d   derive the comm
1070: 61 6e 64 20 73 65 6e 64 65 72 20 61 6e 64 20 74  and sender and t
1080: 61 72 67 65 74 20 63 68 61 74 20 69 64 20 66 6f  arget chat id fo
1090: 72 20 74 68 65 20 72 65 70 6c 79 2e 0a 2f 2f 2f  r the reply..///
10a0: 20 2d 20 60 77 6f 72 64 73 60 20 e2 80 94 20 74   - `words` — t
10b0: 68 65 20 63 6f 6d 6d 61 6e 64 20 61 72 67 75 6d  he command argum
10c0: 65 6e 74 73 3a 20 66 6f 72 20 60 22 2f 61 64 64  ents: for `"/add
10d0: 22 60 20 65 78 70 65 63 74 65 64 20 60 63 68 61  "` expected `cha
10e0: 6e 6e 65 6c 20 75 72 6c 20 5b 69 76 5f 68 61 73  nnel url [iv_has
10f0: 68 7c 27 2d 27 5d 20 5b 75 72 6c 5f 72 65 7c 27  h|'-'] [url_re|'
1100: 2d 27 5d 60 3b 20 66 6f 72 20 60 22 2f 75 70 64  -']`; for `"/upd
1110: 61 74 65 22 60 0a 2f 2f 2f 20 20 20 74 68 65 20  ate"`.///   the 
1120: 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6d 75  first element mu
1130: 73 74 20 62 65 20 61 20 6e 75 6d 65 72 69 63 20  st be a numeric 
1140: 60 73 6f 75 72 63 65 5f 69 64 60 20 66 6f 6c 6c  `source_id` foll
1150: 6f 77 65 64 20 62 79 20 74 68 65 20 73 61 6d 65  owed by the same
1160: 20 70 61 72 61 6d 65 74 65 72 73 2e 0a 70 75 62   parameters..pub
1170: 20 61 73 79 6e 63 20 66 6e 20 75 70 64 61 74 65   async fn update
1180: 20 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c 20 63   (core: &Core, c
1190: 6f 6d 6d 61 6e 64 3a 20 26 73 74 72 2c 20 6d 73  ommand: &str, ms
11a0: 67 3a 20 26 4d 65 73 73 61 67 65 2c 20 77 6f 72  g: &Message, wor
11b0: 64 73 3a 20 26 5b 53 74 72 69 6e 67 5d 29 20 2d  ds: &[String]) -
11c0: 3e 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09  > Result<()> {..
11d0: 6c 65 74 20 73 65 6e 64 65 72 20 3d 20 6d 73 67  let sender = msg
11e0: 2e 73 65 6e 64 65 72 2e 67 65 74 5f 75 73 65 72  .sender.get_user
11f0: 5f 69 64 28 29 0a 09 09 2e 73 74 61 63 6b 5f 65  _id()....stack_e
1200: 72 72 28 22 49 67 6e 6f 72 69 6e 67 20 75 6e 72  rr("Ignoring unr
1210: 65 61 6c 20 75 73 65 72 73 2e 22 29 3f 3b 0a 09  eal users.")?;..
1220: 6c 65 74 20 6d 75 74 20 73 6f 75 72 63 65 5f 69  let mut source_i
1230: 64 3a 20 4f 70 74 69 6f 6e 3c 69 33 32 3e 20 3d  d: Option<i32> =
1240: 20 4e 6f 6e 65 3b 0a 09 6c 65 74 20 61 74 5f 6c   None;..let at_l
1250: 65 61 73 74 20 3d 20 22 52 65 71 75 69 72 65 73  east = "Requires
1260: 20 61 74 20 6c 65 61 73 74 20 33 20 70 61 72 61   at least 3 para
1270: 6d 65 74 65 72 73 2e 22 3b 0a 09 6c 65 74 20 6d  meters.";..let m
1280: 75 74 20 69 5f 77 6f 72 64 73 20 3d 20 77 6f 72  ut i_words = wor
1290: 64 73 2e 69 74 65 72 28 29 3b 0a 09 6d 61 74 63  ds.iter();..matc
12a0: 68 20 63 6f 6d 6d 61 6e 64 20 7b 0a 09 09 22 2f  h command {..."/
12b0: 75 70 64 61 74 65 22 20 3d 3e 20 7b 0a 09 09 09  update" => {....
12c0: 6c 65 74 20 6e 65 78 74 5f 77 6f 72 64 20 3d 20  let next_word = 
12d0: 69 5f 77 6f 72 64 73 2e 6e 65 78 74 28 29 2e 63  i_words.next().c
12e0: 6f 6e 74 65 78 74 28 61 74 5f 6c 65 61 73 74 29  ontext(at_least)
12f0: 3f 3b 0a 09 09 09 73 6f 75 72 63 65 5f 69 64 20  ?;....source_id 
1300: 3d 20 53 6f 6d 65 28 6e 65 78 74 5f 77 6f 72 64  = Some(next_word
1310: 2e 70 61 72 73 65 3a 3a 3c 69 33 32 3e 28 29 0a  .parse::<i32>().
1320: 09 09 09 09 2e 63 6f 6e 74 65 78 74 28 66 6f 72  .....context(for
1330: 6d 61 74 21 28 22 49 20 6e 65 65 64 20 61 20 6e  mat!("I need a n
1340: 75 6d 62 65 72 2c 20 62 75 74 20 67 6f 74 20 7b  umber, but got {
1350: 6e 65 78 74 5f 77 6f 72 64 7d 2e 22 29 29 3f 29  next_word}."))?)
1360: 3b 0a 09 09 7d 2c 0a 09 09 22 2f 61 64 64 22 20  ;...},..."/add" 
1370: 3d 3e 20 7b 7d 2c 0a 09 09 5f 20 3d 3e 20 62 61  => {},..._ => ba
1380: 69 6c 21 28 22 50 61 73 73 69 6e 67 20 7b 63 6f  il!("Passing {co
1390: 6d 6d 61 6e 64 7d 20 69 73 20 6e 6f 74 20 70 6f  mmand} is not po
13a0: 73 73 69 62 6c 65 20 68 65 72 65 2e 22 29 2c 0a  ssible here."),.
13b0: 09 7d 3b 0a 09 6c 65 74 20 28 63 68 61 6e 6e 65  .};..let (channe
13c0: 6c 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c  l, url, iv_hash,
13d0: 20 75 72 6c 5f 72 65 29 20 3d 20 28 0a 09 09 69   url_re) = (...i
13e0: 5f 77 6f 72 64 73 2e 6e 65 78 74 28 29 2e 63 6f  _words.next().co
13f0: 6e 74 65 78 74 28 61 74 5f 6c 65 61 73 74 29 3f  ntext(at_least)?
1400: 2c 0a 09 09 69 5f 77 6f 72 64 73 2e 6e 65 78 74  ,...i_words.next
1410: 28 29 2e 63 6f 6e 74 65 78 74 28 61 74 5f 6c 65  ().context(at_le
1420: 61 73 74 29 3f 2c 0a 09 09 69 5f 77 6f 72 64 73  ast)?,...i_words
1430: 2e 6e 65 78 74 28 29 2c 0a 09 09 69 5f 77 6f 72  .next(),...i_wor
1440: 64 73 2e 6e 65 78 74 28 29 29 3b 0a 09 69 66 20  ds.next());..if 
1450: 21 20 52 45 5f 55 53 45 52 4e 41 4d 45 2e 69 73  ! RE_USERNAME.is
1460: 5f 6d 61 74 63 68 28 63 68 61 6e 6e 65 6c 29 20  _match(channel) 
1470: 7b 0a 09 09 62 61 69 6c 21 28 22 55 73 65 72 6e  {...bail!("Usern
1480: 61 6d 65 73 20 73 68 6f 75 6c 64 20 62 65 20 73  ames should be s
1490: 6f 6d 65 74 68 69 6e 67 20 6c 69 6b 65 20 5c 22  omething like \"
14a0: 40 5c 5c 5b 61 5c 5c 2d 7a 41 5c 5c 2d 5a 5d 5c  @\\[a\\-zA\\-Z]\
14b0: 5c 5b 61 5c 5c 2d 7a 41 5c 5c 2d 5a 30 5c 5c 2d  \[a\\-zA\\-Z0\\-
14c0: 39 5c 5c 5f 5d 2b 5c 22 2c 20 61 72 65 6e 27 74  9\\_]+\", aren't
14d0: 20 74 68 65 79 3f 5c 6e 4e 6f 74 20 7b 63 68 61   they?\nNot {cha
14e0: 6e 6e 65 6c 3a 3f 7d 22 29 3b 0a 09 7d 3b 0a 09  nnel:?}");..};..
14f0: 7b 0a 09 09 6c 65 74 20 70 61 72 73 65 64 5f 75  {...let parsed_u
1500: 72 6c 20 3d 20 55 72 6c 3a 3a 70 61 72 73 65 28  rl = Url::parse(
1510: 75 72 6c 29 0a 09 09 09 2e 73 74 61 63 6b 5f 65  url).....stack_e
1520: 72 72 28 22 45 78 70 65 63 74 69 6e 67 20 61 20  rr("Expecting a 
1530: 76 61 6c 69 64 20 6c 69 6e 6b 20 74 6f 20 41 54  valid link to AT
1540: 4f 4d 2f 52 53 53 20 66 65 65 64 2e 22 29 3f 3b  OM/RSS feed.")?;
1550: 0a 09 09 6d 61 74 63 68 20 70 61 72 73 65 64 5f  ...match parsed_
1560: 75 72 6c 2e 73 63 68 65 6d 65 28 29 20 7b 0a 09  url.scheme() {..
1570: 09 09 22 68 74 74 70 22 20 7c 20 22 68 74 74 70  .."http" | "http
1580: 73 22 20 3d 3e 20 7b 7d 2c 0a 09 09 09 73 63 68  s" => {},....sch
1590: 65 6d 65 20 3d 3e 20 7b 0a 09 09 09 09 62 61 69  eme => {.....bai
15a0: 6c 21 28 22 55 6e 73 75 70 70 6f 72 74 65 64 20  l!("Unsupported 
15b0: 55 52 4c 20 73 63 68 65 6d 65 3a 20 7b 73 63 68  URL scheme: {sch
15c0: 65 6d 65 7d 22 29 3b 0a 09 09 09 7d 2c 0a 09 09  eme}");....},...
15d0: 7d 3b 0a 09 7d 0a 09 6c 65 74 20 69 76 5f 68 61  };..}..let iv_ha
15e0: 73 68 20 3d 20 6d 61 74 63 68 20 69 76 5f 68 61  sh = match iv_ha
15f0: 73 68 20 7b 0a 09 09 53 6f 6d 65 28 68 61 73 68  sh {...Some(hash
1600: 29 20 3d 3e 20 7b 0a 09 09 09 6d 61 74 63 68 20  ) => {....match 
1610: 68 61 73 68 2e 61 73 5f 72 65 66 28 29 20 7b 0a  hash.as_ref() {.
1620: 09 09 09 09 22 2d 22 20 3d 3e 20 4e 6f 6e 65 2c  ...."-" => None,
1630: 0a 09 09 09 09 74 68 69 6e 67 20 3d 3e 20 7b 0a  .....thing => {.
1640: 09 09 09 09 09 69 66 20 21 20 52 45 5f 49 56 5f  .....if ! RE_IV_
1650: 48 41 53 48 2e 69 73 5f 6d 61 74 63 68 28 74 68  HASH.is_match(th
1660: 69 6e 67 29 20 7b 0a 09 09 09 09 09 09 62 61 69  ing) {.......bai
1670: 6c 21 28 22 49 56 20 68 61 73 68 20 73 68 6f 75  l!("IV hash shou
1680: 6c 64 20 62 65 20 31 34 20 68 65 78 20 64 69 67  ld be 14 hex dig
1690: 69 74 73 2e 5c 6e 4e 6f 74 20 7b 74 68 69 6e 67  its.\nNot {thing
16a0: 3a 3f 7d 22 29 3b 0a 09 09 09 09 09 7d 3b 0a 09  :?}");......};..
16b0: 09 09 09 09 53 6f 6d 65 28 74 68 69 6e 67 29 0a  ....Some(thing).
16c0: 09 09 09 09 7d 2c 0a 09 09 09 7d 0a 09 09 7d 2c  ....},....}...},
16d0: 0a 09 09 4e 6f 6e 65 20 3d 3e 20 4e 6f 6e 65 2c  ...None => None,
16e0: 0a 09 7d 3b 0a 09 6c 65 74 20 75 72 6c 5f 72 65  ..};..let url_re
16f0: 20 3d 20 6d 61 74 63 68 20 75 72 6c 5f 72 65 20   = match url_re 
1700: 7b 0a 09 09 53 6f 6d 65 28 72 65 29 20 3d 3e 20  {...Some(re) => 
1710: 7b 0a 09 09 09 6d 61 74 63 68 20 72 65 2e 61 73  {....match re.as
1720: 5f 72 65 66 28 29 20 7b 0a 09 09 09 09 22 2d 22  _ref() {....."-"
1730: 20 3d 3e 20 4e 6f 6e 65 2c 0a 09 09 09 09 74 68   => None,.....th
1740: 69 6e 67 20 3d 3e 20 7b 0a 09 09 09 09 09 6c 65  ing => {......le
1750: 74 20 5f 75 72 6c 5f 72 65 78 20 3d 20 52 65 70  t _url_rex = Rep
1760: 6c 61 63 65 43 6f 6d 6d 61 6e 64 3a 3a 6e 65 77  laceCommand::new
1770: 28 74 68 69 6e 67 29 2e 63 6f 6e 74 65 78 74 28  (thing).context(
1780: 22 52 65 67 65 78 70 20 70 61 72 73 69 6e 67 20  "Regexp parsing 
1790: 65 72 72 6f 72 3a 22 29 3f 3b 0a 09 09 09 09 09  error:")?;......
17a0: 53 6f 6d 65 28 74 68 69 6e 67 29 0a 09 09 09 09  Some(thing).....
17b0: 7d 0a 09 09 09 7d 0a 09 09 7d 2c 0a 09 09 4e 6f  }....}...},...No
17c0: 6e 65 20 3d 3e 20 4e 6f 6e 65 2c 0a 09 7d 3b 0a  ne => None,..};.
17d0: 09 6c 65 74 20 63 68 61 74 5f 69 64 20 3d 20 43  .let chat_id = C
17e0: 68 61 74 55 73 65 72 6e 61 6d 65 3a 3a 66 72 6f  hatUsername::fro
17f0: 6d 28 63 68 61 6e 6e 65 6c 2e 61 73 5f 72 65 66  m(channel.as_ref
1800: 28 29 29 3b 0a 09 6c 65 74 20 63 68 61 6e 6e 65  ());..let channe
1810: 6c 5f 69 64 20 3d 20 63 6f 72 65 2e 74 67 2e 63  l_id = core.tg.c
1820: 6c 69 65 6e 74 2e 65 78 65 63 75 74 65 28 47 65  lient.execute(Ge
1830: 74 43 68 61 74 3a 3a 6e 65 77 28 63 68 61 74 5f  tChat::new(chat_
1840: 69 64 2e 63 6c 6f 6e 65 28 29 29 29 2e 61 77 61  id.clone())).awa
1850: 69 74 2e 73 74 61 63 6b 5f 65 72 72 28 22 67 65  it.stack_err("ge
1860: 74 74 69 6e 67 20 47 65 74 43 68 61 74 22 29 3f  tting GetChat")?
1870: 2e 69 64 3b 0a 09 6c 65 74 20 63 68 61 6e 5f 61  .id;..let chan_a
1880: 64 6d 20 3d 20 63 6f 72 65 2e 74 67 2e 63 6c 69  dm = core.tg.cli
1890: 65 6e 74 2e 65 78 65 63 75 74 65 28 47 65 74 43  ent.execute(GetC
18a0: 68 61 74 41 64 6d 69 6e 69 73 74 72 61 74 6f 72  hatAdministrator
18b0: 73 3a 3a 6e 65 77 28 63 68 61 74 5f 69 64 29 29  s::new(chat_id))
18c0: 2e 61 77 61 69 74 0a 09 09 2e 63 6f 6e 74 65 78  .await....contex
18d0: 74 28 22 53 6f 72 72 79 2c 20 49 20 68 61 76 65  t("Sorry, I have
18e0: 20 6e 6f 20 61 63 63 65 73 73 20 74 6f 20 74 68   no access to th
18f0: 61 74 20 63 68 61 74 2e 22 29 3f 3b 0a 09 6c 65  at chat.")?;..le
1900: 74 20 28 6d 75 74 20 6d 65 2c 20 6d 75 74 20 75  t (mut me, mut u
1910: 73 65 72 29 20 3d 20 28 66 61 6c 73 65 2c 20 66  ser) = (false, f
1920: 61 6c 73 65 29 3b 0a 09 66 6f 72 20 61 64 6d 69  alse);..for admi
1930: 6e 20 69 6e 20 63 68 61 6e 5f 61 64 6d 20 7b 0a  n in chan_adm {.
1940: 09 09 6c 65 74 20 6d 65 6d 62 65 72 5f 69 64 20  ..let member_id 
1950: 3d 20 6d 61 74 63 68 20 61 64 6d 69 6e 20 7b 0a  = match admin {.
1960: 09 09 09 43 68 61 74 4d 65 6d 62 65 72 3a 3a 43  ...ChatMember::C
1970: 72 65 61 74 6f 72 28 6d 65 6d 62 65 72 29 20 3d  reator(member) =
1980: 3e 20 6d 65 6d 62 65 72 2e 75 73 65 72 2e 69 64  > member.user.id
1990: 2c 0a 09 09 09 43 68 61 74 4d 65 6d 62 65 72 3a  ,....ChatMember:
19a0: 3a 41 64 6d 69 6e 69 73 74 72 61 74 6f 72 28 6d  :Administrator(m
19b0: 65 6d 62 65 72 29 20 3d 3e 20 6d 65 6d 62 65 72  ember) => member
19c0: 2e 75 73 65 72 2e 69 64 2c 0a 09 09 09 43 68 61  .user.id,....Cha
19d0: 74 4d 65 6d 62 65 72 3a 3a 4c 65 66 74 28 5f 29  tMember::Left(_)
19e0: 0a 09 09 09 7c 20 43 68 61 74 4d 65 6d 62 65 72  ....| ChatMember
19f0: 3a 3a 4b 69 63 6b 65 64 28 5f 29 0a 09 09 09 7c  ::Kicked(_)....|
1a00: 20 43 68 61 74 4d 65 6d 62 65 72 3a 3a 4d 65 6d   ChatMember::Mem
1a10: 62 65 72 7b 2e 2e 7d 0a 09 09 09 7c 20 43 68 61  ber{..}....| Cha
1a20: 74 4d 65 6d 62 65 72 3a 3a 52 65 73 74 72 69 63  tMember::Restric
1a30: 74 65 64 28 5f 29 20 3d 3e 20 63 6f 6e 74 69 6e  ted(_) => contin
1a40: 75 65 2c 0a 09 09 7d 3b 0a 09 09 69 66 20 6d 65  ue,...};...if me
1a50: 6d 62 65 72 5f 69 64 20 3d 3d 20 63 6f 72 65 2e  mber_id == core.
1a60: 74 67 2e 6d 65 2e 69 64 20 7b 0a 09 09 09 6d 65  tg.me.id {....me
1a70: 20 3d 20 74 72 75 65 3b 0a 09 09 7d 0a 09 09 69   = true;...}...i
1a80: 66 20 6d 65 6d 62 65 72 5f 69 64 20 3d 3d 20 73  f member_id == s
1a90: 65 6e 64 65 72 20 7b 0a 09 09 09 75 73 65 72 20  ender {....user 
1aa0: 3d 20 74 72 75 65 3b 0a 09 09 7d 0a 09 7d 3b 0a  = true;...}..};.
1ab0: 09 69 66 20 21 20 6d 65 20 20 20 7b 20 62 61 69  .if ! me   { bai
1ac0: 6c 21 28 22 49 20 6e 65 65 64 20 74 6f 20 62 65  l!("I need to be
1ad0: 20 61 64 6d 69 6e 20 6f 6e 20 74 68 61 74 20 63   admin on that c
1ae0: 68 61 6e 6e 65 6c 2e 22 29 3b 20 7d 3b 0a 09 69  hannel."); };..i
1af0: 66 20 21 20 75 73 65 72 20 7b 20 62 61 69 6c 21  f ! user { bail!
1b00: 28 22 59 6f 75 20 73 68 6f 75 6c 64 20 62 65 20  ("You should be 
1b10: 61 64 6d 69 6e 20 6f 6e 20 74 68 61 74 20 63 68  admin on that ch
1b20: 61 6e 6e 65 6c 2e 22 29 3b 20 7d 3b 0a 09 6c 65  annel."); };..le
1b30: 74 20 6d 75 74 20 63 6f 6e 6e 20 3d 20 63 6f 72  t mut conn = cor
1b40: 65 2e 64 62 2e 62 65 67 69 6e 28 29 2e 61 77 61  e.db.begin().awa
1b50: 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 6c 65  it.stack()?;..le
1b60: 74 20 75 70 64 61 74 65 20 3d 20 63 6f 6e 6e 2e  t update = conn.
1b70: 75 70 64 61 74 65 28 73 6f 75 72 63 65 5f 69 64  update(source_id
1b80: 2c 20 63 68 61 6e 6e 65 6c 2c 20 63 68 61 6e 6e  , channel, chann
1b90: 65 6c 5f 69 64 2c 20 75 72 6c 2c 20 69 76 5f 68  el_id, url, iv_h
1ba0: 61 73 68 2c 20 75 72 6c 5f 72 65 2c 20 73 65 6e  ash, url_re, sen
1bb0: 64 65 72 29 2e 61 77 61 69 74 2e 73 74 61 63 6b  der).await.stack
1bc0: 28 29 3f 3b 0a 09 63 6f 72 65 2e 74 67 2e 73 65  ()?;..core.tg.se
1bd0: 6e 64 28 4d 79 4d 65 73 73 61 67 65 3a 3a 68 74  nd(MyMessage::ht
1be0: 6d 6c 5f 74 6f 28 75 70 64 61 74 65 2c 20 6d 73  ml_to(update, ms
1bf0: 67 2e 63 68 61 74 2e 67 65 74 5f 69 64 28 29 29  g.chat.get_id())
1c00: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f  ).await.stack()?
1c10: 3b 0a 09 69 66 20 63 6f 6d 6d 61 6e 64 20 3d 3d  ;..if command ==
1c20: 20 22 2f 61 64 64 22 20 7b 0a 09 09 69 66 20 6c   "/add" {...if l
1c30: 65 74 20 53 6f 6d 65 28 6e 65 77 5f 72 65 63 6f  et Some(new_reco
1c40: 72 64 29 20 3d 20 63 6f 6e 6e 2e 67 65 74 5f 6f  rd) = conn.get_o
1c50: 6e 65 5f 6e 61 6d 65 28 73 65 6e 64 65 72 2c 20  ne_name(sender, 
1c60: 63 68 61 6e 6e 65 6c 29 2e 61 77 61 69 74 2e 73  channel).await.s
1c70: 74 61 63 6b 28 29 3f 20 7b 0a 09 09 09 63 6f 72  tack()? {....cor
1c80: 65 2e 61 64 64 5f 66 65 65 64 28 73 65 6e 64 65  e.add_feed(sende
1c90: 72 2e 69 6e 74 6f 28 29 2c 20 6e 65 77 5f 72 65  r.into(), new_re
1ca0: 63 6f 72 64 2e 73 6f 75 72 63 65 5f 69 64 2c 20  cord.source_id, 
1cb0: 6e 65 77 5f 72 65 63 6f 72 64 2e 63 68 61 6e 6e  new_record.chann
1cc0: 65 6c 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28  el).await.stack(
1cd0: 29 3f 3b 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09  )?;...} else {..
1ce0: 09 09 62 61 69 6c 21 28 22 46 61 69 6c 65 64 20  ..bail!("Failed 
1cf0: 74 6f 20 72 65 61 64 20 64 61 74 61 20 6f 6e 20  to read data on 
1d00: 66 72 65 73 68 6c 79 20 69 6e 73 65 72 74 65 64  freshly inserted
1d10: 20 73 6f 75 72 63 65 2e 22 29 3b 0a 09 09 7d 0a   source.");...}.
1d20: 09 7d 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a 0a 70  .};..Ok(()).}..p
1d30: 75 62 20 61 73 79 6e 63 20 66 6e 20 61 6e 73 77  ub async fn answ
1d40: 65 72 5f 63 62 20 28 63 6f 72 65 3a 20 26 43 6f  er_cb (core: &Co
1d50: 72 65 2c 20 71 75 65 72 79 3a 20 26 43 61 6c 6c  re, query: &Call
1d60: 62 61 63 6b 51 75 65 72 79 2c 20 63 62 3a 20 26  backQuery, cb: &
1d70: 73 74 72 29 20 2d 3e 20 52 65 73 75 6c 74 3c 28  str) -> Result<(
1d80: 29 3e 20 7b 0a 09 6c 65 74 20 63 62 3a 20 43 61  )> {..let cb: Ca
1d90: 6c 6c 62 61 63 6b 20 3d 20 74 6f 6d 6c 3a 3a 66  llback = toml::f
1da0: 72 6f 6d 5f 73 74 72 28 63 62 29 2e 73 74 61 63  rom_str(cb).stac
1db0: 6b 28 29 3f 3b 0a 09 6c 65 74 20 73 65 6e 64 65  k()?;..let sende
1dc0: 72 20 3d 20 26 71 75 65 72 79 2e 66 72 6f 6d 3b  r = &query.from;
1dd0: 0a 09 2f 2f 6c 65 74 20 6d 75 74 20 63 6f 6e 6e  ..//let mut conn
1de0: 20 3d 20 63 6f 72 65 2e 64 62 2e 62 65 67 69 6e   = core.db.begin
1df0: 28 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29  ().await.stack()
1e00: 3f 3b 0a 09 6c 65 74 20 74 65 78 74 20 3d 20 22  ?;..let text = "
1e10: 53 61 6d 70 6c 65 22 2e 74 6f 5f 6f 77 6e 65 64  Sample".to_owned
1e20: 28 29 3b 0a 09 69 66 20 6c 65 74 20 53 6f 6d 65  ();..if let Some
1e30: 28 6d 73 67 29 20 3d 20 26 71 75 65 72 79 2e 6d  (msg) = &query.m
1e40: 65 73 73 61 67 65 20 7b 0a 09 09 6d 61 74 63 68  essage {...match
1e50: 20 6d 73 67 20 7b 0a 09 09 09 4d 61 79 62 65 49   msg {....MaybeI
1e60: 6e 61 63 63 65 73 73 69 62 6c 65 4d 65 73 73 61  naccessibleMessa
1e70: 67 65 3a 3a 4d 65 73 73 61 67 65 28 6d 65 73 73  ge::Message(mess
1e80: 61 67 65 29 20 3d 3e 20 7b 0a 09 09 09 09 69 66  age) => {.....if
1e90: 20 6c 65 74 20 53 6f 6d 65 28 6f 77 6e 65 72 29   let Some(owner)
1ea0: 20 3d 20 6d 65 73 73 61 67 65 2e 73 65 6e 64 65   = message.sende
1eb0: 72 2e 67 65 74 5f 75 73 65 72 28 29 0a 09 09 09  r.get_user()....
1ec0: 09 09 26 26 20 73 65 6e 64 65 72 20 3d 3d 20 6f  ..&& sender == o
1ed0: 77 6e 65 72 0a 09 09 09 09 7b 0a 09 09 09 09 09  wner.....{......
1ee0: 6c 65 74 20 66 65 65 64 73 20 3d 20 63 6f 72 65  let feeds = core
1ef0: 2e 67 65 74 5f 66 65 65 64 73 28 6f 77 6e 65 72  .get_feeds(owner
1f00: 2e 69 64 2e 69 6e 74 6f 28 29 29 2e 61 77 61 69  .id.into()).awai
1f10: 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 09 09  t.stack()?;.....
1f20: 09 63 6f 72 65 2e 74 67 2e 75 70 64 61 74 65 5f  .core.tg.update_
1f30: 6d 65 73 73 61 67 65 28 6d 65 73 73 61 67 65 2e  message(message.
1f40: 63 68 61 74 2e 67 65 74 5f 69 64 28 29 2e 69 6e  chat.get_id().in
1f50: 74 6f 28 29 2c 20 6d 65 73 73 61 67 65 2e 69 64  to(), message.id
1f60: 2c 20 74 65 78 74 2c 20 26 66 65 65 64 73 2c 20  , text, &feeds, 
1f70: 63 62 29 2e 61 77 61 69 74 3f 3b 0a 09 09 09 09  cb).await?;.....
1f80: 7d 20 65 6c 73 65 20 7b 0a 09 09 09 09 09 63 6f  } else {......co
1f90: 72 65 2e 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73  re.tg.send(MyMes
1fa0: 73 61 67 65 3a 3a 68 74 6d 6c 28 66 6f 72 6d 61  sage::html(forma
1fb0: 74 21 28 22 43 61 6e 27 74 20 69 64 65 6e 74 69  t!("Can't identi
1fc0: 66 79 20 72 65 71 75 65 73 74 20 73 65 6e 64 65  fy request sende
1fd0: 72 3a 3c 62 72 3e 3c 70 72 65 3e 7b 3a 3f 7d 3c  r:<br><pre>{:?}<
1fe0: 2f 70 72 65 3e 22 2c 20 6d 65 73 73 61 67 65 29  /pre>", message)
1ff0: 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29  )).await.stack()
2000: 3f 3b 0a 09 09 09 09 7d 0a 09 09 09 7d 2c 0a 09  ?;.....}....},..
2010: 09 09 4d 61 79 62 65 49 6e 61 63 63 65 73 73 69  ..MaybeInaccessi
2020: 62 6c 65 4d 65 73 73 61 67 65 3a 3a 49 6e 61 63  bleMessage::Inac
2030: 63 65 73 73 69 62 6c 65 4d 65 73 73 61 67 65 28  cessibleMessage(
2040: 6d 65 73 73 61 67 65 29 20 3d 3e 20 7b 0a 09 09  message) => {...
2050: 09 09 6c 65 74 20 73 65 6e 64 65 72 3a 20 69 36  ..let sender: i6
2060: 34 20 3d 20 73 65 6e 64 65 72 2e 69 64 2e 69 6e  4 = sender.id.in
2070: 74 6f 28 29 3b 0a 09 09 09 09 69 66 20 6c 65 74  to();.....if let
2080: 20 43 68 61 74 3a 3a 50 72 69 76 61 74 65 28 70   Chat::Private(p
2090: 72 69 76 5f 63 68 61 74 29 20 3d 20 26 6d 65 73  riv_chat) = &mes
20a0: 73 61 67 65 2e 63 68 61 74 0a 09 09 09 09 09 26  sage.chat......&
20b0: 26 20 70 72 69 76 5f 63 68 61 74 2e 69 64 20 3d  & priv_chat.id =
20c0: 3d 20 73 65 6e 64 65 72 0a 09 09 09 09 7b 0a 09  = sender.....{..
20d0: 09 09 09 09 6c 65 74 20 66 65 65 64 73 20 3d 20  ....let feeds = 
20e0: 63 6f 72 65 2e 67 65 74 5f 66 65 65 64 73 28 70  core.get_feeds(p
20f0: 72 69 76 5f 63 68 61 74 2e 69 64 2e 69 6e 74 6f  riv_chat.id.into
2100: 28 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28  ()).await.stack(
2110: 29 3f 3b 0a 09 09 09 09 09 63 6f 72 65 2e 74 67  )?;......core.tg
2120: 2e 75 70 64 61 74 65 5f 6d 65 73 73 61 67 65 28  .update_message(
2130: 6d 65 73 73 61 67 65 2e 63 68 61 74 2e 67 65 74  message.chat.get
2140: 5f 69 64 28 29 2e 69 6e 74 6f 28 29 2c 20 6d 65  _id().into(), me
2150: 73 73 61 67 65 2e 6d 65 73 73 61 67 65 5f 69 64  ssage.message_id
2160: 2c 20 74 65 78 74 2c 20 26 66 65 65 64 73 2c 20  , text, &feeds, 
2170: 63 62 29 2e 61 77 61 69 74 3f 3b 0a 09 09 09 09  cb).await?;.....
2180: 7d 20 65 6c 73 65 20 7b 0a 09 09 09 09 09 63 6f  } else {......co
2190: 72 65 2e 74 67 2e 73 65 6e 64 28 4d 79 4d 65 73  re.tg.send(MyMes
21a0: 73 61 67 65 3a 3a 68 74 6d 6c 28 66 6f 72 6d 61  sage::html(forma
21b0: 74 21 28 22 43 61 6e 27 74 20 69 64 65 6e 74 69  t!("Can't identi
21c0: 66 79 20 72 65 71 75 65 73 74 20 73 65 6e 64 65  fy request sende
21d0: 72 3a 3c 62 72 3e 3c 70 72 65 3e 7b 3a 3f 7d 3c  r:<br><pre>{:?}<
21e0: 2f 70 72 65 3e 22 2c 20 6d 65 73 73 61 67 65 29  /pre>", message)
21f0: 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29  )).await.stack()
2200: 3f 3b 0a 09 09 09 09 7d 0a 09 09 09 7d 2c 0a 09  ?;.....}....},..
2210: 09 7d 3b 0a 09 7d 3b 0a 09 4f 6b 28 28 29 29 0a  .};..};..Ok(()).
2220: 7d 0a                                            }.