Diff
Logged in as anonymous

Differences From Artifact [b8d5906cd9]:

To Artifact [834f5b6fdc]:


15
16
17
18
19
20
21
22

23
24
25
26
27

28
29
30
31
32
33

34
35
36
37
38
39
40
41

42
43
44
45
46


47
48

49
50
51
52
53
54
55

56
57
58
59

60
61
62
63
64
65

66
67
68
69
70

71
72

73
74

75
76
77
78
79

80
81
82
83
84
85















86
87
88
89
90
91
92
15
16
17
18
19
20
21

22
23
24
25
26

27
28
29
30
31
32

33
34
35
36
37
38
39
40

41
42
43
44


45
46
47

48
49
50
51
52
53
54

55
56
57
58

59
60
61
62
63
64

65
66
67
68
69

70


71
72

73
74
75
76
77

78
79
80




81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102







-
+




-
+





-
+







-
+



-
-
+
+

-
+






-
+



-
+





-
+




-
+
-
-
+

-
+




-
+


-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	GetChat,
	GetChatAdministrators,
	Message,
	ParseMode::MarkdownV2,
};

lazy_static! {
	static ref RE_USERNAME: Regex = Regex::new(r"^@[a-zA-Z][a-zA-Z0-9_]+$").unwrap();
	static ref RE_USERNAME: Regex = Regex::new(r"^@([a-zA-Z][a-zA-Z0-9_]+)$").unwrap();
	static ref RE_LINK: Regex = Regex::new(r"^https?://[a-zA-Z.0-9-]+/[-_a-zA-Z.:0-9/?=]+$").unwrap();
	static ref RE_IV_HASH: Regex = Regex::new(r"^[a-f0-9]{14}$").unwrap();
}

pub async fn start(core: &Core, msg: &Message) -> Result<()> {
pub async fn start (core: &Core, msg: &Message) -> Result<()> {
	core.send("We are open\\. Probably\\. Visit [channel](https://t.me/rsstg_bot_help/3) for details\\.",
		Some(msg.chat.get_id()), Some(MarkdownV2)).await?;
	Ok(())
}

pub async fn list(core: &Core, msg: &Message) -> Result<()> {
pub async fn list (core: &Core, msg: &Message) -> Result<()> {
	let sender = msg.sender.get_user_id()
		.ok_or(anyhow!("Ignoring unreal users."))?;
	let reply = core.list(sender).await?;
	core.send(reply, Some(msg.chat.get_id()), Some(MarkdownV2)).await?;
	Ok(())
}

pub async fn command (core: &Core, msg: &Message, command: &[String]) -> Result<()> {
pub async fn command (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
	let mut conn = core.db.begin().await?;
	let sender = msg.sender.get_user_id()
		.ok_or(anyhow!("Ignoring unreal users."))?;
	let reply = if command.len() >= 2 {
		match command[1].parse::<i32>() {
	let reply = if words.len() == 1 {
		match words[0].parse::<i32>() {
			Err(err) => format!("I need a number.\n{}", &err).into(),
			Ok(number) => match &command[0][..] {
			Ok(number) => match command {
				"/check" => core.check(number, false).await
					.context("Channel check failed.")?.into(),
				"/clean" => conn.clean(number, sender).await?,
				"/enable" => conn.enable(number, sender).await?.into(),
				"/delete" => conn.delete(number, sender).await?,
				"/disable" => conn.disable(number, sender).await?.into(),
				_ => bail!("Command {} not handled.", &command[0]),
				_ => bail!("Command {command} {words:?} not handled."),
			},
		}
	} else {
		"This command needs a number.".into()
		"This command needs exacly one number.".into()
	};
	core.send(reply, Some(msg.chat.get_id()), None).await?;
	Ok(())
}

pub async fn update (core: &Core, msg: &Message, command: &[String]) -> Result<()> {
pub async fn update (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
	let sender = msg.sender.get_user_id()
		.ok_or(anyhow!("Ignoring unreal users."))?;
	let mut source_id: Option<i32> = None;
	let at_least = "Requires at least 3 parameters.";
	let mut i_command = command.iter();
	let mut i_words = words.iter();
	let first_word = i_command.next().context(at_least)?;
	match first_word.as_ref() {
	match command {
		"/update" => {
			let next_word = i_command.next().context(at_least)?;
			let next_word = i_words.next().context(at_least)?;
			source_id = Some(next_word.parse::<i32>()
				.context(format!("I need a number, but got {next_word}."))?);
		},
		"/add" => {},
		_ => bail!("Passing {first_word} is not possible here."),
		_ => bail!("Passing {command} is not possible here."),
	};
	let (channel, url, iv_hash, url_re) = (
		i_command.next().context(at_least)?,
		i_command.next().context(at_least)?,
		i_command.next(),
		i_command.next());
		i_words.next().context(at_least)?,
		i_words.next().context(at_least)?,
		i_words.next(),
		i_words.next());
	/*
	let channel = match RE_USERNAME.captures(channel) {
		Some(caps) => match caps.get(1) {
			Some(data) => data.as_str(),
			None => bail!("No string found in channel name"),
		},
		None => {
			bail!("Usernames should be something like \"@\\[a\\-zA\\-Z]\\[a\\-zA\\-Z0\\-9\\_]+\", aren't they?\nNot {channel:?}");
		},
	};
	*/
	if ! RE_USERNAME.is_match(channel) {
		bail!("Usernames should be something like \"@\\[a\\-zA\\-Z]\\[a\\-zA\\-Z0\\-9\\_]+\", aren't they?\nNot {channel:?}");
	};
	if ! RE_LINK.is_match(url) {
		bail!("Link should be a link to atom/rss feed, something like \"https://domain/path\".\nNot {url:?}");
	}
	let iv_hash = match iv_hash {
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135







-
+







					let _url_rex = ReplaceCommand::new(thing).context("Regexp parsing error:")?;
					Some(thing)
				}
			}
		},
		None => None,
	};
	let chat_id = ChatUsername::from(channel.clone());
	let chat_id = ChatUsername::from(channel.as_ref());
	let channel_id = core.tg.execute(GetChat::new(chat_id.clone())).await?.id;
	let chan_adm = core.tg.execute(GetChatAdministrators::new(chat_id)).await
		.context("Sorry, I have no access to that chat.")?;
	let (mut me, mut user) = (false, false);
	for admin in chan_adm {
		let member_id = match admin {
			ChatMember::Creator(member) => member.user.id,