Hex Artifact Content
Logged in as anonymous

Artifact f6a06b1c48501ae0454e86de464d082ce30e033de735028767f923b3ae9158fa:


0000: 75 73 65 20 63 72 61 74 65 3a 3a 63 6f 72 65 3a  use crate::core:
0010: 3a 43 6f 72 65 3b 0a 0a 75 73 65 20 6c 61 7a 79  :Core;..use lazy
0020: 5f 73 74 61 74 69 63 3a 3a 6c 61 7a 79 5f 73 74  _static::lazy_st
0030: 61 74 69 63 3b 0a 75 73 65 20 72 65 67 65 78 3a  atic;.use regex:
0040: 3a 52 65 67 65 78 3b 0a 75 73 65 20 73 65 64 72  :Regex;.use sedr
0050: 65 67 65 78 3a 3a 52 65 70 6c 61 63 65 43 6f 6d  egex::ReplaceCom
0060: 6d 61 6e 64 3b 0a 75 73 65 20 73 74 61 63 6b 65  mand;.use stacke
0070: 64 5f 65 72 72 6f 72 73 3a 3a 7b 0a 09 52 65 73  d_errors::{..Res
0080: 75 6c 74 2c 0a 09 53 74 61 63 6b 61 62 6c 65 45  ult,..StackableE
0090: 72 72 2c 0a 09 62 61 69 6c 2c 0a 7d 3b 0a 75 73  rr,..bail,.};.us
00a0: 65 20 74 67 62 6f 74 3a 3a 74 79 70 65 73 3a 3a  e tgbot::types::
00b0: 7b 0a 09 43 68 61 74 4d 65 6d 62 65 72 2c 0a 09  {..ChatMember,..
00c0: 43 68 61 74 55 73 65 72 6e 61 6d 65 2c 0a 09 47  ChatUsername,..G
00d0: 65 74 43 68 61 74 2c 0a 09 47 65 74 43 68 61 74  etChat,..GetChat
00e0: 41 64 6d 69 6e 69 73 74 72 61 74 6f 72 73 2c 0a  Administrators,.
00f0: 09 4d 65 73 73 61 67 65 2c 0a 09 50 61 72 73 65  .Message,..Parse
0100: 4d 6f 64 65 3a 3a 4d 61 72 6b 64 6f 77 6e 56 32  Mode::MarkdownV2
0110: 2c 0a 7d 3b 0a 75 73 65 20 75 72 6c 3a 3a 55 72  ,.};.use url::Ur
0120: 6c 3b 0a 0a 6c 61 7a 79 5f 73 74 61 74 69 63 21  l;..lazy_static!
0130: 20 7b 0a 09 73 74 61 74 69 63 20 72 65 66 20 52   {..static ref R
0140: 45 5f 55 53 45 52 4e 41 4d 45 3a 20 52 65 67 65  E_USERNAME: Rege
0150: 78 20 3d 20 52 65 67 65 78 3a 3a 6e 65 77 28 72  x = Regex::new(r
0160: 22 5e 40 28 5b 61 2d 7a 41 2d 5a 5d 5b 61 2d 7a  "^@([a-zA-Z][a-z
0170: 41 2d 5a 30 2d 39 5f 5d 2b 29 24 22 29 2e 75 6e  A-Z0-9_]+)$").un
0180: 77 72 61 70 28 29 3b 0a 09 73 74 61 74 69 63 20  wrap();..static 
0190: 72 65 66 20 52 45 5f 49 56 5f 48 41 53 48 3a 20  ref RE_IV_HASH: 
01a0: 52 65 67 65 78 20 3d 20 52 65 67 65 78 3a 3a 6e  Regex = Regex::n
01b0: 65 77 28 72 22 5e 5b 61 2d 66 30 2d 39 5d 7b 31  ew(r"^[a-f0-9]{1
01c0: 34 7d 24 22 29 2e 75 6e 77 72 61 70 28 29 3b 0a  4}$").unwrap();.
01d0: 7d 0a 0a 2f 2f 2f 20 53 65 6e 64 73 20 61 6e 20  }../// Sends an 
01e0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 61 6c 20 6d 65  informational me
01f0: 73 73 61 67 65 20 74 6f 20 74 68 65 20 6d 65 73  ssage to the mes
0200: 73 61 67 65 27 73 20 63 68 61 74 20 6c 69 6e 6b  sage's chat link
0210: 69 6e 67 20 74 6f 20 74 68 65 20 62 6f 74 20 68  ing to the bot h
0220: 65 6c 70 20 63 68 61 6e 6e 65 6c 2e 0a 70 75 62  elp channel..pub
0230: 20 61 73 79 6e 63 20 66 6e 20 73 74 61 72 74 20   async fn start 
0240: 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c 20 6d 73  (core: &Core, ms
0250: 67 3a 20 26 4d 65 73 73 61 67 65 29 20 2d 3e 20  g: &Message) -> 
0260: 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 63 6f  Result<()> {..co
0270: 72 65 2e 74 67 2e 73 65 6e 64 28 22 57 65 20 61  re.tg.send("We a
0280: 72 65 20 6f 70 65 6e 5c 5c 2e 20 50 72 6f 62 61  re open\\. Proba
0290: 62 6c 79 5c 5c 2e 20 56 69 73 69 74 20 5b 63 68  bly\\. Visit [ch
02a0: 61 6e 6e 65 6c 5d 28 68 74 74 70 73 3a 2f 2f 74  annel](https://t
02b0: 2e 6d 65 2f 72 73 73 74 67 5f 62 6f 74 5f 68 65  .me/rsstg_bot_he
02c0: 6c 70 2f 33 29 20 66 6f 72 20 64 65 74 61 69 6c  lp/3) for detail
02d0: 73 5c 5c 2e 22 2c 0a 09 09 53 6f 6d 65 28 6d 73  s\\.",...Some(ms
02e0: 67 2e 63 68 61 74 2e 67 65 74 5f 69 64 28 29 29  g.chat.get_id())
02f0: 2c 20 53 6f 6d 65 28 4d 61 72 6b 64 6f 77 6e 56  , Some(MarkdownV
0300: 32 29 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28  2)).await.stack(
0310: 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a 0a 2f  )?;..Ok(()).}../
0320: 2f 2f 20 53 65 6e 64 20 74 68 65 20 73 65 6e 64  // Send the send
0330: 65 72 27 73 20 73 75 62 73 63 72 69 70 74 69 6f  er's subscriptio
0340: 6e 20 6c 69 73 74 20 74 6f 20 74 68 65 20 63 68  n list to the ch
0350: 61 74 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 52 65 74 72  at..///./// Retr
0360: 69 65 76 65 73 20 74 68 65 20 6d 65 73 73 61 67  ieves the messag
0370: 65 20 73 65 6e 64 65 72 27 73 20 75 73 65 72 20  e sender's user 
0380: 49 44 2c 20 6f 62 74 61 69 6e 73 20 74 68 65 69  ID, obtains thei
0390: 72 20 73 75 62 73 63 72 69 70 74 69 6f 6e 20 6c  r subscription l
03a0: 69 73 74 20 66 72 6f 6d 20 60 63 6f 72 65 60 2c  ist from `core`,
03b0: 0a 2f 2f 2f 20 61 6e 64 20 73 65 6e 64 73 20 74  ./// and sends t
03c0: 68 65 20 72 65 73 75 6c 74 69 6e 67 20 72 65 70  he resulting rep
03d0: 6c 79 20 69 6e 74 6f 20 74 68 65 20 6d 65 73 73  ly into the mess
03e0: 61 67 65 20 63 68 61 74 20 75 73 69 6e 67 20 4d  age chat using M
03f0: 61 72 6b 64 6f 77 6e 56 32 2e 0a 70 75 62 20 61  arkdownV2..pub a
0400: 73 79 6e 63 20 66 6e 20 6c 69 73 74 20 28 63 6f  sync fn list (co
0410: 72 65 3a 20 26 43 6f 72 65 2c 20 6d 73 67 3a 20  re: &Core, msg: 
0420: 26 4d 65 73 73 61 67 65 29 20 2d 3e 20 52 65 73  &Message) -> Res
0430: 75 6c 74 3c 28 29 3e 20 7b 0a 09 6c 65 74 20 73  ult<()> {..let s
0440: 65 6e 64 65 72 20 3d 20 6d 73 67 2e 73 65 6e 64  ender = msg.send
0450: 65 72 2e 67 65 74 5f 75 73 65 72 5f 69 64 28 29  er.get_user_id()
0460: 0a 09 09 2e 73 74 61 63 6b 5f 65 72 72 28 22 49  ....stack_err("I
0470: 67 6e 6f 72 69 6e 67 20 75 6e 72 65 61 6c 20 75  gnoring unreal u
0480: 73 65 72 73 2e 22 29 3f 3b 0a 09 6c 65 74 20 72  sers.")?;..let r
0490: 65 70 6c 79 20 3d 20 63 6f 72 65 2e 6c 69 73 74  eply = core.list
04a0: 28 73 65 6e 64 65 72 29 2e 61 77 61 69 74 2e 73  (sender).await.s
04b0: 74 61 63 6b 28 29 3f 3b 0a 09 63 6f 72 65 2e 74  tack()?;..core.t
04c0: 67 2e 73 65 6e 64 28 72 65 70 6c 79 2c 20 53 6f  g.send(reply, So
04d0: 6d 65 28 6d 73 67 2e 63 68 61 74 2e 67 65 74 5f  me(msg.chat.get_
04e0: 69 64 28 29 29 2c 20 53 6f 6d 65 28 4d 61 72 6b  id()), Some(Mark
04f0: 64 6f 77 6e 56 32 29 29 2e 61 77 61 69 74 2e 73  downV2)).await.s
0500: 74 61 63 6b 28 29 3f 3b 0a 09 4f 6b 28 28 29 29  tack()?;..Ok(())
0510: 0a 7d 0a 0a 2f 2f 2f 20 48 61 6e 64 6c 65 20 63  .}../// Handle c
0520: 68 61 6e 6e 65 6c 2d 6d 61 6e 61 67 65 6d 65 6e  hannel-managemen
0530: 74 20 63 6f 6d 6d 61 6e 64 73 20 74 68 61 74 20  t commands that 
0540: 6f 70 65 72 61 74 65 20 6f 6e 20 61 20 73 69 6e  operate on a sin
0550: 67 6c 65 20 6e 75 6d 65 72 69 63 20 73 6f 75 72  gle numeric sour
0560: 63 65 20 49 44 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 54  ce ID..///./// T
0570: 68 69 73 20 76 61 6c 69 64 61 74 65 73 20 74 68  his validates th
0580: 61 74 20 65 78 61 63 74 6c 79 20 6f 6e 65 20 6e  at exactly one n
0590: 75 6d 65 72 69 63 20 61 72 67 75 6d 65 6e 74 20  umeric argument 
05a0: 69 73 20 70 72 6f 76 69 64 65 64 2c 20 70 65 72  is provided, per
05b0: 66 6f 72 6d 73 20 74 68 65 20 72 65 71 75 65 73  forms the reques
05c0: 74 65 64 0a 2f 2f 2f 20 6f 70 65 72 61 74 69 6f  ted./// operatio
05d0: 6e 20 28 63 68 65 63 6b 2c 20 63 6c 65 61 6e 2c  n (check, clean,
05e0: 20 65 6e 61 62 6c 65 2c 20 64 65 6c 65 74 65 2c   enable, delete,
05f0: 20 64 69 73 61 62 6c 65 29 20 61 67 61 69 6e 73   disable) agains
0600: 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 6f  t the database o
0610: 72 20 63 6f 72 65 2c 0a 2f 2f 2f 20 61 6e 64 20  r core,./// and 
0620: 73 65 6e 64 73 20 74 68 65 20 72 65 73 75 6c 74  sends the result
0630: 69 6e 67 20 72 65 70 6c 79 20 74 6f 20 74 68 65  ing reply to the
0640: 20 63 68 61 74 2e 0a 2f 2f 2f 0a 2f 2f 2f 20 23   chat..///./// #
0650: 20 50 61 72 61 6d 65 74 65 72 73 0a 2f 2f 2f 0a   Parameters.///.
0660: 2f 2f 2f 20 2d 20 60 63 6f 72 65 60 3a 20 61 70  /// - `core`: ap
0670: 70 6c 69 63 61 74 69 6f 6e 20 63 6f 72 65 20 63  plication core c
0680: 6f 6e 74 61 69 6e 69 6e 67 20 64 61 74 61 62 61  ontaining databa
0690: 73 65 20 61 6e 64 20 54 65 6c 65 67 72 61 6d 20  se and Telegram 
06a0: 63 6c 69 65 6e 74 73 2e 0a 2f 2f 2f 20 2d 20 60  clients../// - `
06b0: 63 6f 6d 6d 61 6e 64 60 3a 20 63 6f 6d 6d 61 6e  command`: comman
06c0: 64 20 73 74 72 69 6e 67 20 28 65 2e 67 2e 20 22  d string (e.g. "
06d0: 2f 63 68 65 63 6b 22 2c 20 22 2f 63 6c 65 61 6e  /check", "/clean
06e0: 22 2c 20 22 2f 65 6e 61 62 6c 65 22 2c 20 22 2f  ", "/enable", "/
06f0: 64 65 6c 65 74 65 22 2c 20 22 2f 64 69 73 61 62  delete", "/disab
0700: 6c 65 22 29 2e 0a 2f 2f 2f 20 2d 20 60 6d 73 67  le")../// - `msg
0710: 60 3a 20 69 6e 63 6f 6d 69 6e 67 20 54 65 6c 65  `: incoming Tele
0720: 67 72 61 6d 20 6d 65 73 73 61 67 65 20 74 68 61  gram message tha
0730: 74 20 74 72 69 67 67 65 72 65 64 20 74 68 65 20  t triggered the 
0740: 63 6f 6d 6d 61 6e 64 3b 20 75 73 65 64 20 74 6f  command; used to
0750: 20 64 65 74 65 72 6d 69 6e 65 20 73 65 6e 64 65   determine sende
0760: 72 20 61 6e 64 20 63 68 61 74 2e 0a 2f 2f 2f 20  r and chat../// 
0770: 2d 20 60 77 6f 72 64 73 60 3a 20 63 6f 6d 6d 61  - `words`: comma
0780: 6e 64 20 61 72 67 75 6d 65 6e 74 73 3b 20 65 78  nd arguments; ex
0790: 70 65 63 74 65 64 20 74 6f 20 63 6f 6e 74 61 69  pected to contai
07a0: 6e 20 65 78 61 63 74 6c 79 20 6f 6e 65 20 65 6c  n exactly one el
07b0: 65 6d 65 6e 74 20 74 68 61 74 20 70 61 72 73 65  ement that parse
07c0: 73 20 61 73 20 61 20 33 32 2d 62 69 74 20 69 6e  s as a 32-bit in
07d0: 74 65 67 65 72 2e 0a 70 75 62 20 61 73 79 6e 63  teger..pub async
07e0: 20 66 6e 20 63 6f 6d 6d 61 6e 64 20 28 63 6f 72   fn command (cor
07f0: 65 3a 20 26 43 6f 72 65 2c 20 63 6f 6d 6d 61 6e  e: &Core, comman
0800: 64 3a 20 26 73 74 72 2c 20 6d 73 67 3a 20 26 4d  d: &str, msg: &M
0810: 65 73 73 61 67 65 2c 20 77 6f 72 64 73 3a 20 26  essage, words: &
0820: 5b 53 74 72 69 6e 67 5d 29 20 2d 3e 20 52 65 73  [String]) -> Res
0830: 75 6c 74 3c 28 29 3e 20 7b 0a 09 6c 65 74 20 6d  ult<()> {..let m
0840: 75 74 20 63 6f 6e 6e 20 3d 20 63 6f 72 65 2e 64  ut conn = core.d
0850: 62 2e 62 65 67 69 6e 28 29 2e 61 77 61 69 74 2e  b.begin().await.
0860: 73 74 61 63 6b 28 29 3f 3b 0a 09 6c 65 74 20 73  stack()?;..let s
0870: 65 6e 64 65 72 20 3d 20 6d 73 67 2e 73 65 6e 64  ender = msg.send
0880: 65 72 2e 67 65 74 5f 75 73 65 72 5f 69 64 28 29  er.get_user_id()
0890: 0a 09 09 2e 73 74 61 63 6b 5f 65 72 72 28 22 49  ....stack_err("I
08a0: 67 6e 6f 72 69 6e 67 20 75 6e 72 65 61 6c 20 75  gnoring unreal u
08b0: 73 65 72 73 2e 22 29 3f 3b 0a 09 6c 65 74 20 72  sers.")?;..let r
08c0: 65 70 6c 79 20 3d 20 69 66 20 77 6f 72 64 73 2e  eply = if words.
08d0: 6c 65 6e 28 29 20 3d 3d 20 31 20 7b 0a 09 09 6d  len() == 1 {...m
08e0: 61 74 63 68 20 77 6f 72 64 73 5b 30 5d 2e 70 61  atch words[0].pa
08f0: 72 73 65 3a 3a 3c 69 33 32 3e 28 29 20 7b 0a 09  rse::<i32>() {..
0900: 09 09 45 72 72 28 65 72 72 29 20 3d 3e 20 66 6f  ..Err(err) => fo
0910: 72 6d 61 74 21 28 22 49 20 6e 65 65 64 20 61 20  rmat!("I need a 
0920: 6e 75 6d 62 65 72 2e 5c 6e 7b 7d 22 2c 20 26 65  number.\n{}", &e
0930: 72 72 29 2e 69 6e 74 6f 28 29 2c 0a 09 09 09 4f  rr).into(),....O
0940: 6b 28 6e 75 6d 62 65 72 29 20 3d 3e 20 6d 61 74  k(number) => mat
0950: 63 68 20 63 6f 6d 6d 61 6e 64 20 7b 0a 09 09 09  ch command {....
0960: 09 22 2f 63 68 65 63 6b 22 20 3d 3e 20 63 6f 72  ."/check" => cor
0970: 65 2e 63 68 65 63 6b 28 6e 75 6d 62 65 72 2c 20  e.check(number, 
0980: 66 61 6c 73 65 2c 20 4e 6f 6e 65 29 2e 61 77 61  false, None).awa
0990: 69 74 0a 09 09 09 09 09 2e 63 6f 6e 74 65 78 74  it.......context
09a0: 28 22 43 68 61 6e 6e 65 6c 20 63 68 65 63 6b 20  ("Channel check 
09b0: 66 61 69 6c 65 64 2e 22 29 3f 2e 69 6e 74 6f 28  failed.")?.into(
09c0: 29 2c 0a 09 09 09 09 22 2f 63 6c 65 61 6e 22 20  ),....."/clean" 
09d0: 3d 3e 20 63 6f 6e 6e 2e 63 6c 65 61 6e 28 6e 75  => conn.clean(nu
09e0: 6d 62 65 72 2c 20 73 65 6e 64 65 72 29 2e 61 77  mber, sender).aw
09f0: 61 69 74 2e 73 74 61 63 6b 28 29 3f 2c 0a 09 09  ait.stack()?,...
0a00: 09 09 22 2f 65 6e 61 62 6c 65 22 20 3d 3e 20 63  .."/enable" => c
0a10: 6f 6e 6e 2e 65 6e 61 62 6c 65 28 6e 75 6d 62 65  onn.enable(numbe
0a20: 72 2c 20 73 65 6e 64 65 72 29 2e 61 77 61 69 74  r, sender).await
0a30: 2e 73 74 61 63 6b 28 29 3f 2e 69 6e 74 6f 28 29  .stack()?.into()
0a40: 2c 0a 09 09 09 09 22 2f 64 65 6c 65 74 65 22 20  ,....."/delete" 
0a50: 3d 3e 20 63 6f 6e 6e 2e 64 65 6c 65 74 65 28 6e  => conn.delete(n
0a60: 75 6d 62 65 72 2c 20 73 65 6e 64 65 72 29 2e 61  umber, sender).a
0a70: 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 2c 0a 09  wait.stack()?,..
0a80: 09 09 09 22 2f 64 69 73 61 62 6c 65 22 20 3d 3e  ..."/disable" =>
0a90: 20 63 6f 6e 6e 2e 64 69 73 61 62 6c 65 28 6e 75   conn.disable(nu
0aa0: 6d 62 65 72 2c 20 73 65 6e 64 65 72 29 2e 61 77  mber, sender).aw
0ab0: 61 69 74 2e 73 74 61 63 6b 28 29 3f 2e 69 6e 74  ait.stack()?.int
0ac0: 6f 28 29 2c 0a 09 09 09 09 5f 20 3d 3e 20 62 61  o(),....._ => ba
0ad0: 69 6c 21 28 22 43 6f 6d 6d 61 6e 64 20 7b 63 6f  il!("Command {co
0ae0: 6d 6d 61 6e 64 7d 20 7b 77 6f 72 64 73 3a 3f 7d  mmand} {words:?}
0af0: 20 6e 6f 74 20 68 61 6e 64 6c 65 64 2e 22 29 2c   not handled."),
0b00: 0a 09 09 09 7d 2c 0a 09 09 7d 0a 09 7d 20 65 6c  ....},...}..} el
0b10: 73 65 20 7b 0a 09 09 22 54 68 69 73 20 63 6f 6d  se {..."This com
0b20: 6d 61 6e 64 20 6e 65 65 64 73 20 65 78 61 63 6c  mand needs exacl
0b30: 79 20 6f 6e 65 20 6e 75 6d 62 65 72 2e 22 2e 69  y one number.".i
0b40: 6e 74 6f 28 29 0a 09 7d 3b 0a 09 63 6f 72 65 2e  nto()..};..core.
0b50: 74 67 2e 73 65 6e 64 28 72 65 70 6c 79 2c 20 53  tg.send(reply, S
0b60: 6f 6d 65 28 6d 73 67 2e 63 68 61 74 2e 67 65 74  ome(msg.chat.get
0b70: 5f 69 64 28 29 29 2c 20 4e 6f 6e 65 29 2e 61 77  _id()), None).aw
0b80: 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 4f  ait.stack()?;..O
0b90: 6b 28 28 29 29 0a 7d 0a 0a 2f 2f 2f 20 56 61 6c  k(()).}../// Val
0ba0: 69 64 61 74 65 20 63 6f 6d 6d 61 6e 64 20 61 72  idate command ar
0bb0: 67 75 6d 65 6e 74 73 2c 20 63 68 65 63 6b 20 70  guments, check p
0bc0: 65 72 6d 69 73 73 69 6f 6e 73 20 61 6e 64 20 75  ermissions and u
0bd0: 70 64 61 74 65 20 6f 72 20 61 64 64 20 61 20 63  pdate or add a c
0be0: 68 61 6e 6e 65 6c 20 66 65 65 64 20 63 6f 6e 66  hannel feed conf
0bf0: 69 67 75 72 61 74 69 6f 6e 20 69 6e 20 74 68 65  iguration in the
0c00: 20 64 61 74 61 62 61 73 65 2e 0a 2f 2f 2f 0a 2f   database..///./
0c10: 2f 2f 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e  // This function
0c20: 20 70 61 72 73 65 73 20 61 6e 64 20 76 61 6c 69   parses and vali
0c30: 64 61 74 65 73 20 70 61 72 61 6d 65 74 65 72 73  dates parameters
0c40: 20 73 75 70 70 6c 69 65 64 20 62 79 20 61 20 75   supplied by a u
0c50: 73 65 72 20 63 6f 6d 6d 61 6e 64 20 28 65 69 74  ser command (eit
0c60: 68 65 72 20 22 2f 75 70 64 61 74 65 20 3c 69 64  her "/update <id
0c70: 3e 20 2e 2e 2e 22 20 6f 72 20 22 2f 61 64 64 20  > ..." or "/add 
0c80: 2e 2e 2e 22 29 2c 0a 2f 2f 2f 20 76 65 72 69 66  ..."),./// verif
0c90: 69 65 73 20 74 68 65 20 63 68 61 6e 6e 65 6c 20  ies the channel 
0ca0: 75 73 65 72 6e 61 6d 65 20 61 6e 64 20 66 65 65  username and fee
0cb0: 64 20 55 52 4c 2c 20 6f 70 74 69 6f 6e 61 6c 6c  d URL, optionall
0cc0: 79 20 76 61 6c 69 64 61 74 65 73 20 61 6e 20 49  y validates an I
0cd0: 56 20 68 61 73 68 20 61 6e 64 20 61 20 72 65 70  V hash and a rep
0ce0: 6c 61 63 65 6d 65 6e 74 20 72 65 67 65 78 70 2c  lacement regexp,
0cf0: 0a 2f 2f 2f 20 65 6e 73 75 72 65 73 20 62 6f 74  ./// ensures bot
0d00: 68 20 74 68 65 20 62 6f 74 20 61 6e 64 20 74 68  h the bot and th
0d10: 65 20 63 6f 6d 6d 61 6e 64 20 73 65 6e 64 65 72  e command sender
0d20: 20 61 72 65 20 61 64 6d 69 6e 69 73 74 72 61 74   are administrat
0d30: 6f 72 73 20 6f 66 20 74 68 65 20 74 61 72 67 65  ors of the targe
0d40: 74 20 63 68 61 6e 6e 65 6c 2c 20 61 6e 64 20 70  t channel, and p
0d50: 65 72 66 6f 72 6d 73 20 74 68 65 20 64 61 74 61  erforms the data
0d60: 62 61 73 65 20 75 70 64 61 74 65 2e 0a 2f 2f 2f  base update..///
0d70: 0a 2f 2f 2f 20 23 20 50 61 72 61 6d 65 74 65 72  ./// # Parameter
0d80: 73 0a 2f 2f 2f 0a 2f 2f 2f 20 2d 20 60 63 6f 6d  s.///./// - `com
0d90: 6d 61 6e 64 60 20 e2 80 94 20 74 68 65 20 69 6e  mand` — the in
0da0: 76 6f 6b 65 64 20 63 6f 6d 6d 61 6e 64 2c 20 65  voked command, e
0db0: 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 65 69  xpected to be ei
0dc0: 74 68 65 72 20 60 22 2f 75 70 64 61 74 65 22 60  ther `"/update"`
0dd0: 20 28 66 6f 6c 6c 6f 77 65 64 20 62 79 20 61 20   (followed by a 
0de0: 6e 75 6d 65 72 69 63 20 73 6f 75 72 63 65 20 69  numeric source i
0df0: 64 29 20 6f 72 20 60 22 2f 61 64 64 22 60 2e 0a  d) or `"/add"`..
0e00: 2f 2f 2f 20 2d 20 60 6d 73 67 60 20 e2 80 94 20  /// - `msg` — 
0e10: 74 68 65 20 69 6e 63 6f 6d 69 6e 67 20 54 65 6c  the incoming Tel
0e20: 65 67 72 61 6d 20 6d 65 73 73 61 67 65 3b 20 75  egram message; u
0e30: 73 65 64 20 74 6f 20 64 65 72 69 76 65 20 74 68  sed to derive th
0e40: 65 20 63 6f 6d 6d 61 6e 64 20 73 65 6e 64 65 72  e command sender
0e50: 20 61 6e 64 20 74 61 72 67 65 74 20 63 68 61 74   and target chat
0e60: 20 69 64 20 66 6f 72 20 74 68 65 20 72 65 70 6c   id for the repl
0e70: 79 2e 0a 2f 2f 2f 20 2d 20 60 77 6f 72 64 73 60  y../// - `words`
0e80: 20 e2 80 94 20 74 68 65 20 63 6f 6d 6d 61 6e 64   — the command
0e90: 20 61 72 67 75 6d 65 6e 74 73 3a 20 66 6f 72 20   arguments: for 
0ea0: 60 22 2f 61 64 64 22 60 20 65 78 70 65 63 74 65  `"/add"` expecte
0eb0: 64 20 60 63 68 61 6e 6e 65 6c 20 75 72 6c 20 5b  d `channel url [
0ec0: 69 76 5f 68 61 73 68 7c 27 2d 27 5d 20 5b 75 72  iv_hash|'-'] [ur
0ed0: 6c 5f 72 65 7c 27 2d 27 5d 60 3b 20 66 6f 72 20  l_re|'-']`; for 
0ee0: 60 22 2f 75 70 64 61 74 65 22 60 20 74 68 65 20  `"/update"` the 
0ef0: 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6d 75  first element mu
0f00: 73 74 20 62 65 20 61 20 6e 75 6d 65 72 69 63 20  st be a numeric 
0f10: 60 73 6f 75 72 63 65 5f 69 64 60 20 66 6f 6c 6c  `source_id` foll
0f20: 6f 77 65 64 20 62 79 20 74 68 65 20 73 61 6d 65  owed by the same
0f30: 20 70 61 72 61 6d 65 74 65 72 73 2e 0a 70 75 62   parameters..pub
0f40: 20 61 73 79 6e 63 20 66 6e 20 75 70 64 61 74 65   async fn update
0f50: 20 28 63 6f 72 65 3a 20 26 43 6f 72 65 2c 20 63   (core: &Core, c
0f60: 6f 6d 6d 61 6e 64 3a 20 26 73 74 72 2c 20 6d 73  ommand: &str, ms
0f70: 67 3a 20 26 4d 65 73 73 61 67 65 2c 20 77 6f 72  g: &Message, wor
0f80: 64 73 3a 20 26 5b 53 74 72 69 6e 67 5d 29 20 2d  ds: &[String]) -
0f90: 3e 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09  > Result<()> {..
0fa0: 6c 65 74 20 73 65 6e 64 65 72 20 3d 20 6d 73 67  let sender = msg
0fb0: 2e 73 65 6e 64 65 72 2e 67 65 74 5f 75 73 65 72  .sender.get_user
0fc0: 5f 69 64 28 29 0a 09 09 2e 73 74 61 63 6b 5f 65  _id()....stack_e
0fd0: 72 72 28 22 49 67 6e 6f 72 69 6e 67 20 75 6e 72  rr("Ignoring unr
0fe0: 65 61 6c 20 75 73 65 72 73 2e 22 29 3f 3b 0a 09  eal users.")?;..
0ff0: 6c 65 74 20 6d 75 74 20 73 6f 75 72 63 65 5f 69  let mut source_i
1000: 64 3a 20 4f 70 74 69 6f 6e 3c 69 33 32 3e 20 3d  d: Option<i32> =
1010: 20 4e 6f 6e 65 3b 0a 09 6c 65 74 20 61 74 5f 6c   None;..let at_l
1020: 65 61 73 74 20 3d 20 22 52 65 71 75 69 72 65 73  east = "Requires
1030: 20 61 74 20 6c 65 61 73 74 20 33 20 70 61 72 61   at least 3 para
1040: 6d 65 74 65 72 73 2e 22 3b 0a 09 6c 65 74 20 6d  meters.";..let m
1050: 75 74 20 69 5f 77 6f 72 64 73 20 3d 20 77 6f 72  ut i_words = wor
1060: 64 73 2e 69 74 65 72 28 29 3b 0a 09 6d 61 74 63  ds.iter();..matc
1070: 68 20 63 6f 6d 6d 61 6e 64 20 7b 0a 09 09 22 2f  h command {..."/
1080: 75 70 64 61 74 65 22 20 3d 3e 20 7b 0a 09 09 09  update" => {....
1090: 6c 65 74 20 6e 65 78 74 5f 77 6f 72 64 20 3d 20  let next_word = 
10a0: 69 5f 77 6f 72 64 73 2e 6e 65 78 74 28 29 2e 63  i_words.next().c
10b0: 6f 6e 74 65 78 74 28 61 74 5f 6c 65 61 73 74 29  ontext(at_least)
10c0: 3f 3b 0a 09 09 09 73 6f 75 72 63 65 5f 69 64 20  ?;....source_id 
10d0: 3d 20 53 6f 6d 65 28 6e 65 78 74 5f 77 6f 72 64  = Some(next_word
10e0: 2e 70 61 72 73 65 3a 3a 3c 69 33 32 3e 28 29 0a  .parse::<i32>().
10f0: 09 09 09 09 2e 63 6f 6e 74 65 78 74 28 66 6f 72  .....context(for
1100: 6d 61 74 21 28 22 49 20 6e 65 65 64 20 61 20 6e  mat!("I need a n
1110: 75 6d 62 65 72 2c 20 62 75 74 20 67 6f 74 20 7b  umber, but got {
1120: 6e 65 78 74 5f 77 6f 72 64 7d 2e 22 29 29 3f 29  next_word}."))?)
1130: 3b 0a 09 09 7d 2c 0a 09 09 22 2f 61 64 64 22 20  ;...},..."/add" 
1140: 3d 3e 20 7b 7d 2c 0a 09 09 5f 20 3d 3e 20 62 61  => {},..._ => ba
1150: 69 6c 21 28 22 50 61 73 73 69 6e 67 20 7b 63 6f  il!("Passing {co
1160: 6d 6d 61 6e 64 7d 20 69 73 20 6e 6f 74 20 70 6f  mmand} is not po
1170: 73 73 69 62 6c 65 20 68 65 72 65 2e 22 29 2c 0a  ssible here."),.
1180: 09 7d 3b 0a 09 6c 65 74 20 28 63 68 61 6e 6e 65  .};..let (channe
1190: 6c 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c  l, url, iv_hash,
11a0: 20 75 72 6c 5f 72 65 29 20 3d 20 28 0a 09 09 69   url_re) = (...i
11b0: 5f 77 6f 72 64 73 2e 6e 65 78 74 28 29 2e 63 6f  _words.next().co
11c0: 6e 74 65 78 74 28 61 74 5f 6c 65 61 73 74 29 3f  ntext(at_least)?
11d0: 2c 0a 09 09 69 5f 77 6f 72 64 73 2e 6e 65 78 74  ,...i_words.next
11e0: 28 29 2e 63 6f 6e 74 65 78 74 28 61 74 5f 6c 65  ().context(at_le
11f0: 61 73 74 29 3f 2c 0a 09 09 69 5f 77 6f 72 64 73  ast)?,...i_words
1200: 2e 6e 65 78 74 28 29 2c 0a 09 09 69 5f 77 6f 72  .next(),...i_wor
1210: 64 73 2e 6e 65 78 74 28 29 29 3b 0a 09 2f 2a 0a  ds.next());../*.
1220: 09 6c 65 74 20 63 68 61 6e 6e 65 6c 20 3d 20 6d  .let channel = m
1230: 61 74 63 68 20 52 45 5f 55 53 45 52 4e 41 4d 45  atch RE_USERNAME
1240: 2e 63 61 70 74 75 72 65 73 28 63 68 61 6e 6e 65  .captures(channe
1250: 6c 29 20 7b 0a 09 09 53 6f 6d 65 28 63 61 70 73  l) {...Some(caps
1260: 29 20 3d 3e 20 6d 61 74 63 68 20 63 61 70 73 2e  ) => match caps.
1270: 67 65 74 28 31 29 20 7b 0a 09 09 09 53 6f 6d 65  get(1) {....Some
1280: 28 64 61 74 61 29 20 3d 3e 20 64 61 74 61 2e 61  (data) => data.a
1290: 73 5f 73 74 72 28 29 2c 0a 09 09 09 4e 6f 6e 65  s_str(),....None
12a0: 20 3d 3e 20 62 61 69 6c 21 28 22 4e 6f 20 73 74   => bail!("No st
12b0: 72 69 6e 67 20 66 6f 75 6e 64 20 69 6e 20 63 68  ring found in ch
12c0: 61 6e 6e 65 6c 20 6e 61 6d 65 22 29 2c 0a 09 09  annel name"),...
12d0: 7d 2c 0a 09 09 4e 6f 6e 65 20 3d 3e 20 7b 0a 09  },...None => {..
12e0: 09 09 62 61 69 6c 21 28 22 55 73 65 72 6e 61 6d  ..bail!("Usernam
12f0: 65 73 20 73 68 6f 75 6c 64 20 62 65 20 73 6f 6d  es should be som
1300: 65 74 68 69 6e 67 20 6c 69 6b 65 20 5c 22 40 5c  ething like \"@\
1310: 5c 5b 61 5c 5c 2d 7a 41 5c 5c 2d 5a 5d 5c 5c 5b  \[a\\-zA\\-Z]\\[
1320: 61 5c 5c 2d 7a 41 5c 5c 2d 5a 30 5c 5c 2d 39 5c  a\\-zA\\-Z0\\-9\
1330: 5c 5f 5d 2b 5c 22 2c 20 61 72 65 6e 27 74 20 74  \_]+\", aren't t
1340: 68 65 79 3f 5c 6e 4e 6f 74 20 7b 63 68 61 6e 6e  hey?\nNot {chann
1350: 65 6c 3a 3f 7d 22 29 3b 0a 09 09 7d 2c 0a 09 7d  el:?}");...},..}
1360: 3b 0a 09 2a 2f 0a 09 69 66 20 21 20 52 45 5f 55  ;..*/..if ! RE_U
1370: 53 45 52 4e 41 4d 45 2e 69 73 5f 6d 61 74 63 68  SERNAME.is_match
1380: 28 63 68 61 6e 6e 65 6c 29 20 7b 0a 09 09 62 61  (channel) {...ba
1390: 69 6c 21 28 22 55 73 65 72 6e 61 6d 65 73 20 73  il!("Usernames s
13a0: 68 6f 75 6c 64 20 62 65 20 73 6f 6d 65 74 68 69  hould be somethi
13b0: 6e 67 20 6c 69 6b 65 20 5c 22 40 5c 5c 5b 61 5c  ng like \"@\\[a\
13c0: 5c 2d 7a 41 5c 5c 2d 5a 5d 5c 5c 5b 61 5c 5c 2d  \-zA\\-Z]\\[a\\-
13d0: 7a 41 5c 5c 2d 5a 30 5c 5c 2d 39 5c 5c 5f 5d 2b  zA\\-Z0\\-9\\_]+
13e0: 5c 22 2c 20 61 72 65 6e 27 74 20 74 68 65 79 3f  \", aren't they?
13f0: 5c 6e 4e 6f 74 20 7b 63 68 61 6e 6e 65 6c 3a 3f  \nNot {channel:?
1400: 7d 22 29 3b 0a 09 7d 3b 0a 09 7b 0a 09 09 6c 65  }");..};..{...le
1410: 74 20 70 61 72 73 65 64 5f 75 72 6c 20 3d 20 55  t parsed_url = U
1420: 72 6c 3a 3a 70 61 72 73 65 28 75 72 6c 29 0a 09  rl::parse(url)..
1430: 09 09 2e 73 74 61 63 6b 5f 65 72 72 28 22 45 78  ...stack_err("Ex
1440: 70 65 63 74 69 6e 67 20 61 20 76 61 6c 69 64 20  pecting a valid 
1450: 6c 69 6e 6b 20 74 6f 20 41 54 4f 4d 2f 52 53 53  link to ATOM/RSS
1460: 20 66 65 65 64 2e 22 29 3f 3b 0a 09 09 6d 61 74   feed.")?;...mat
1470: 63 68 20 70 61 72 73 65 64 5f 75 72 6c 2e 73 63  ch parsed_url.sc
1480: 68 65 6d 65 28 29 20 7b 0a 09 09 09 22 68 74 74  heme() {...."htt
1490: 70 22 20 7c 20 22 68 74 74 70 73 22 20 3d 3e 20  p" | "https" => 
14a0: 7b 7d 2c 0a 09 09 09 73 63 68 65 6d 65 20 3d 3e  {},....scheme =>
14b0: 20 7b 0a 09 09 09 09 62 61 69 6c 21 28 22 55 6e   {.....bail!("Un
14c0: 73 75 70 70 6f 72 74 65 64 20 55 52 4c 20 73 63  supported URL sc
14d0: 68 65 6d 65 3a 20 7b 73 63 68 65 6d 65 7d 22 29  heme: {scheme}")
14e0: 3b 0a 09 09 09 7d 2c 0a 09 09 7d 3b 0a 09 7d 0a  ;....},...};..}.
14f0: 09 6c 65 74 20 69 76 5f 68 61 73 68 20 3d 20 6d  .let iv_hash = m
1500: 61 74 63 68 20 69 76 5f 68 61 73 68 20 7b 0a 09  atch iv_hash {..
1510: 09 53 6f 6d 65 28 68 61 73 68 29 20 3d 3e 20 7b  .Some(hash) => {
1520: 0a 09 09 09 6d 61 74 63 68 20 68 61 73 68 2e 61  ....match hash.a
1530: 73 5f 72 65 66 28 29 20 7b 0a 09 09 09 09 22 2d  s_ref() {....."-
1540: 22 20 3d 3e 20 4e 6f 6e 65 2c 0a 09 09 09 09 74  " => None,.....t
1550: 68 69 6e 67 20 3d 3e 20 7b 0a 09 09 09 09 09 69  hing => {......i
1560: 66 20 21 20 52 45 5f 49 56 5f 48 41 53 48 2e 69  f ! RE_IV_HASH.i
1570: 73 5f 6d 61 74 63 68 28 74 68 69 6e 67 29 20 7b  s_match(thing) {
1580: 0a 09 09 09 09 09 09 62 61 69 6c 21 28 22 49 56  .......bail!("IV
1590: 20 68 61 73 68 20 73 68 6f 75 6c 64 20 62 65 20   hash should be 
15a0: 31 34 20 68 65 78 20 64 69 67 69 74 73 2e 5c 6e  14 hex digits.\n
15b0: 4e 6f 74 20 7b 74 68 69 6e 67 3a 3f 7d 22 29 3b  Not {thing:?}");
15c0: 0a 09 09 09 09 09 7d 3b 0a 09 09 09 09 09 53 6f  ......};......So
15d0: 6d 65 28 74 68 69 6e 67 29 0a 09 09 09 09 7d 2c  me(thing).....},
15e0: 0a 09 09 09 7d 0a 09 09 7d 2c 0a 09 09 4e 6f 6e  ....}...},...Non
15f0: 65 20 3d 3e 20 4e 6f 6e 65 2c 0a 09 7d 3b 0a 09  e => None,..};..
1600: 6c 65 74 20 75 72 6c 5f 72 65 20 3d 20 6d 61 74  let url_re = mat
1610: 63 68 20 75 72 6c 5f 72 65 20 7b 0a 09 09 53 6f  ch url_re {...So
1620: 6d 65 28 72 65 29 20 3d 3e 20 7b 0a 09 09 09 6d  me(re) => {....m
1630: 61 74 63 68 20 72 65 2e 61 73 5f 72 65 66 28 29  atch re.as_ref()
1640: 20 7b 0a 09 09 09 09 22 2d 22 20 3d 3e 20 4e 6f   {....."-" => No
1650: 6e 65 2c 0a 09 09 09 09 74 68 69 6e 67 20 3d 3e  ne,.....thing =>
1660: 20 7b 0a 09 09 09 09 09 6c 65 74 20 5f 75 72 6c   {......let _url
1670: 5f 72 65 78 20 3d 20 52 65 70 6c 61 63 65 43 6f  _rex = ReplaceCo
1680: 6d 6d 61 6e 64 3a 3a 6e 65 77 28 74 68 69 6e 67  mmand::new(thing
1690: 29 2e 63 6f 6e 74 65 78 74 28 22 52 65 67 65 78  ).context("Regex
16a0: 70 20 70 61 72 73 69 6e 67 20 65 72 72 6f 72 3a  p parsing error:
16b0: 22 29 3f 3b 0a 09 09 09 09 09 53 6f 6d 65 28 74  ")?;......Some(t
16c0: 68 69 6e 67 29 0a 09 09 09 09 7d 0a 09 09 09 7d  hing).....}....}
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 63  None,..};..let c
16f0: 68 61 74 5f 69 64 20 3d 20 43 68 61 74 55 73 65  hat_id = ChatUse
1700: 72 6e 61 6d 65 3a 3a 66 72 6f 6d 28 63 68 61 6e  rname::from(chan
1710: 6e 65 6c 2e 61 73 5f 72 65 66 28 29 29 3b 0a 09  nel.as_ref());..
1720: 6c 65 74 20 63 68 61 6e 6e 65 6c 5f 69 64 20 3d  let channel_id =
1730: 20 63 6f 72 65 2e 74 67 2e 63 6c 69 65 6e 74 2e   core.tg.client.
1740: 65 78 65 63 75 74 65 28 47 65 74 43 68 61 74 3a  execute(GetChat:
1750: 3a 6e 65 77 28 63 68 61 74 5f 69 64 2e 63 6c 6f  :new(chat_id.clo
1760: 6e 65 28 29 29 29 2e 61 77 61 69 74 2e 73 74 61  ne())).await.sta
1770: 63 6b 5f 65 72 72 28 22 67 65 74 74 74 69 6e 67  ck_err("gettting
1780: 20 47 65 74 43 68 61 74 22 29 3f 2e 69 64 3b 0a   GetChat")?.id;.
1790: 09 6c 65 74 20 63 68 61 6e 5f 61 64 6d 20 3d 20  .let chan_adm = 
17a0: 63 6f 72 65 2e 74 67 2e 63 6c 69 65 6e 74 2e 65  core.tg.client.e
17b0: 78 65 63 75 74 65 28 47 65 74 43 68 61 74 41 64  xecute(GetChatAd
17c0: 6d 69 6e 69 73 74 72 61 74 6f 72 73 3a 3a 6e 65  ministrators::ne
17d0: 77 28 63 68 61 74 5f 69 64 29 29 2e 61 77 61 69  w(chat_id)).awai
17e0: 74 0a 09 09 2e 63 6f 6e 74 65 78 74 28 22 53 6f  t....context("So
17f0: 72 72 79 2c 20 49 20 68 61 76 65 20 6e 6f 20 61  rry, I have no a
1800: 63 63 65 73 73 20 74 6f 20 74 68 61 74 20 63 68  ccess to that ch
1810: 61 74 2e 22 29 3f 3b 0a 09 6c 65 74 20 28 6d 75  at.")?;..let (mu
1820: 74 20 6d 65 2c 20 6d 75 74 20 75 73 65 72 29 20  t me, mut user) 
1830: 3d 20 28 66 61 6c 73 65 2c 20 66 61 6c 73 65 29  = (false, false)
1840: 3b 0a 09 66 6f 72 20 61 64 6d 69 6e 20 69 6e 20  ;..for admin in 
1850: 63 68 61 6e 5f 61 64 6d 20 7b 0a 09 09 6c 65 74  chan_adm {...let
1860: 20 6d 65 6d 62 65 72 5f 69 64 20 3d 20 6d 61 74   member_id = mat
1870: 63 68 20 61 64 6d 69 6e 20 7b 0a 09 09 09 43 68  ch admin {....Ch
1880: 61 74 4d 65 6d 62 65 72 3a 3a 43 72 65 61 74 6f  atMember::Creato
1890: 72 28 6d 65 6d 62 65 72 29 20 3d 3e 20 6d 65 6d  r(member) => mem
18a0: 62 65 72 2e 75 73 65 72 2e 69 64 2c 0a 09 09 09  ber.user.id,....
18b0: 43 68 61 74 4d 65 6d 62 65 72 3a 3a 41 64 6d 69  ChatMember::Admi
18c0: 6e 69 73 74 72 61 74 6f 72 28 6d 65 6d 62 65 72  nistrator(member
18d0: 29 20 3d 3e 20 6d 65 6d 62 65 72 2e 75 73 65 72  ) => member.user
18e0: 2e 69 64 2c 0a 09 09 09 43 68 61 74 4d 65 6d 62  .id,....ChatMemb
18f0: 65 72 3a 3a 4c 65 66 74 28 5f 29 0a 09 09 09 7c  er::Left(_)....|
1900: 20 43 68 61 74 4d 65 6d 62 65 72 3a 3a 4b 69 63   ChatMember::Kic
1910: 6b 65 64 28 5f 29 0a 09 09 09 7c 20 43 68 61 74  ked(_)....| Chat
1920: 4d 65 6d 62 65 72 3a 3a 4d 65 6d 62 65 72 7b 2e  Member::Member{.
1930: 2e 7d 0a 09 09 09 7c 20 43 68 61 74 4d 65 6d 62  .}....| ChatMemb
1940: 65 72 3a 3a 52 65 73 74 72 69 63 74 65 64 28 5f  er::Restricted(_
1950: 29 20 3d 3e 20 63 6f 6e 74 69 6e 75 65 2c 0a 09  ) => continue,..
1960: 09 7d 3b 0a 09 09 69 66 20 6d 65 6d 62 65 72 5f  .};...if member_
1970: 69 64 20 3d 3d 20 63 6f 72 65 2e 74 67 2e 6d 65  id == core.tg.me
1980: 2e 69 64 20 7b 0a 09 09 09 6d 65 20 3d 20 74 72  .id {....me = tr
1990: 75 65 3b 0a 09 09 7d 0a 09 09 69 66 20 6d 65 6d  ue;...}...if mem
19a0: 62 65 72 5f 69 64 20 3d 3d 20 73 65 6e 64 65 72  ber_id == sender
19b0: 20 7b 0a 09 09 09 75 73 65 72 20 3d 20 74 72 75   {....user = tru
19c0: 65 3b 0a 09 09 7d 0a 09 7d 3b 0a 09 69 66 20 21  e;...}..};..if !
19d0: 20 6d 65 20 20 20 7b 20 62 61 69 6c 21 28 22 49   me   { bail!("I
19e0: 20 6e 65 65 64 20 74 6f 20 62 65 20 61 64 6d 69   need to be admi
19f0: 6e 20 6f 6e 20 74 68 61 74 20 63 68 61 6e 6e 65  n on that channe
1a00: 6c 2e 22 29 3b 20 7d 3b 0a 09 69 66 20 21 20 75  l."); };..if ! u
1a10: 73 65 72 20 7b 20 62 61 69 6c 21 28 22 59 6f 75  ser { bail!("You
1a20: 20 73 68 6f 75 6c 64 20 62 65 20 61 64 6d 69 6e   should be admin
1a30: 20 6f 6e 20 74 68 61 74 20 63 68 61 6e 6e 65 6c   on that channel
1a40: 2e 22 29 3b 20 7d 3b 0a 09 6c 65 74 20 6d 75 74  ."); };..let mut
1a50: 20 63 6f 6e 6e 20 3d 20 63 6f 72 65 2e 64 62 2e   conn = core.db.
1a60: 62 65 67 69 6e 28 29 2e 61 77 61 69 74 2e 73 74  begin().await.st
1a70: 61 63 6b 28 29 3f 3b 0a 09 6c 65 74 20 75 70 64  ack()?;..let upd
1a80: 61 74 65 20 3d 20 63 6f 6e 6e 2e 75 70 64 61 74  ate = conn.updat
1a90: 65 28 73 6f 75 72 63 65 5f 69 64 2c 20 63 68 61  e(source_id, cha
1aa0: 6e 6e 65 6c 2c 20 63 68 61 6e 6e 65 6c 5f 69 64  nnel, channel_id
1ab0: 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c 20  , url, iv_hash, 
1ac0: 75 72 6c 5f 72 65 2c 20 73 65 6e 64 65 72 29 2e  url_re, sender).
1ad0: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a  await.stack()?;.
1ae0: 09 63 6f 72 65 2e 74 67 2e 73 65 6e 64 28 75 70  .core.tg.send(up
1af0: 64 61 74 65 2c 20 53 6f 6d 65 28 6d 73 67 2e 63  date, Some(msg.c
1b00: 68 61 74 2e 67 65 74 5f 69 64 28 29 29 2c 20 4e  hat.get_id()), N
1b10: 6f 6e 65 29 2e 61 77 61 69 74 2e 73 74 61 63 6b  one).await.stack
1b20: 28 29 3f 3b 0a 09 4f 6b 28 28 29 29 0a 7d 0a     ()?;..Ok(()).}.