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
|
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
|
-
+
-
-
-
-
+
+
+
+
-
+
-
+
-
+
|
Ok(())
}
pub async fn command(core: &Core, sender: telegram_bot::UserId, command: Vec<&str>) -> Result<()> {
core.send( match &command[1].parse::<i32>() {
Err(err) => format!("I need a number.\n{}", &err).into(),
Ok(number) => match command[0] {
"/check" => core.check(&number, sender, false).await
"/check" => core.check(number, sender, false).await
.context("Channel check failed.")?,
"/clean" => core.clean(&number, sender).await?,
"/enable" => core.enable(&number, sender).await?.into(),
"/delete" => core.delete(&number, sender).await?,
"/disable" => core.disable(&number, sender).await?.into(),
"/clean" => core.clean(number, sender).await?,
"/enable" => core.enable(number, sender).await?.into(),
"/delete" => core.delete(number, sender).await?,
"/disable" => core.disable(number, sender).await?.into(),
_ => bail!("Command {} not handled.", &command[0]),
},
}, Some(sender), None)?;
Ok(())
}
pub async fn update(core: &Core, sender: telegram_bot::UserId, command: Vec<&str>) -> Result<()> {
let mut source_id: Option<i32> = None;
let at_least = "Requires at least 3 parameters.";
let first_word = command[0];
let command = match first_word {
"/update" => {
source_id = Some(command[1].parse::<i32>()
.context(format!("I need a number, but got {}.", command[1]))?);
&command[2..]
},
"/add" => &command[1..],
_ => bail!("Passing {} is not possible here.", command[1]),
};
let mut i_command = command.into_iter();
let mut i_command = command.iter();
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());
if ! RE_USERNAME.is_match(&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) {
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 {
Some(hash) => {
match *hash {
"-" => None,
thing => {
|
98
99
100
101
102
103
104
105
106
107
|
97
98
99
100
101
102
103
104
105
106
|
-
+
|
};
if admin.user.id == sender {
user = true;
};
};
if ! me { bail!("I need to be admin on that channel."); };
if ! user { bail!("You should be admin on that channel."); };
core.send(core.update(source_id, channel, channel_id, url, iv_hash, url_re, sender).await?, Some(sender), None)?;
core.send(core.update(source_id, channel, channel_id, url, iv_hash, url_re, sender.into()).await?, Some(sender), None)?;
Ok(())
}
|