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
|
use url::Url;
lazy_static! {
static ref RE_USERNAME: Regex = Regex::new(r"^@([a-zA-Z][a-zA-Z0-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<()> {
core.tg.send("We are open\\. Probably\\. Visit [channel](https://t.me/rsstg_bot_help/3) for details\\.",
Some(msg.chat.get_id()), Some(MarkdownV2)).await.stack()?;
Ok(())
}
pub async fn list (core: &Core, msg: &Message) -> Result<()> {
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let reply = core.list(sender).await.stack()?;
core.tg.send(reply, Some(msg.chat.get_id()), Some(MarkdownV2)).await.stack()?;
Ok(())
}
pub async fn command (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
let mut conn = core.db.begin().await.stack()?;
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let reply = if words.len() == 1 {
match words[0].parse::<i32>() {
Err(err) => format!("I need a number.\n{}", &err).into(),
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
use url::Url;
lazy_static! {
static ref RE_USERNAME: Regex = Regex::new(r"^@([a-zA-Z][a-zA-Z0-9_]+)$").unwrap();
static ref RE_IV_HASH: Regex = Regex::new(r"^[a-f0-9]{14}$").unwrap();
}
/// Sends an informational message to the message's chat linking to the bot help channel.
pub async fn start (core: &Core, msg: &Message) -> Result<()> {
core.tg.send("We are open\\. Probably\\. Visit [channel](https://t.me/rsstg_bot_help/3) for details\\.",
Some(msg.chat.get_id()), Some(MarkdownV2)).await.stack()?;
Ok(())
}
/// Send the sender's subscription list to the chat.
///
/// Retrieves the message sender's user ID, obtains their subscription list from `core`,
/// and sends the resulting reply into the message chat using MarkdownV2.
pub async fn list (core: &Core, msg: &Message) -> Result<()> {
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let reply = core.list(sender).await.stack()?;
core.tg.send(reply, Some(msg.chat.get_id()), Some(MarkdownV2)).await.stack()?;
Ok(())
}
/// Handle channel-management commands that operate on a single numeric source ID.
///
/// This validates that exactly one numeric argument is provided, performs the requested
/// operation (check, clean, enable, delete, disable) against the database or core,
/// and sends the resulting reply to the chat.
///
/// # Parameters
///
/// - `core`: application core containing database and Telegram clients.
/// - `command`: command string (e.g. "/check", "/clean", "/enable", "/delete", "/disable").
/// - `msg`: incoming Telegram message that triggered the command; used to determine sender and chat.
/// - `words`: command arguments; expected to contain exactly one element that parses as a 32-bit integer.
pub async fn command (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
let mut conn = core.db.begin().await.stack()?;
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let reply = if words.len() == 1 {
match words[0].parse::<i32>() {
Err(err) => format!("I need a number.\n{}", &err).into(),
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
} else {
"This command needs exacly one number.".into()
};
core.tg.send(reply, Some(msg.chat.get_id()), None).await.stack()?;
Ok(())
}
pub async fn update (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let mut source_id: Option<i32> = None;
let at_least = "Requires at least 3 parameters.";
let mut i_words = words.iter();
match command {
|
>
>
>
>
>
>
>
>
>
>
>
|
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
|
} else {
"This command needs exacly one number.".into()
};
core.tg.send(reply, Some(msg.chat.get_id()), None).await.stack()?;
Ok(())
}
/// Validate command arguments, check permissions and update or add a channel feed configuration in the database.
///
/// This function parses and validates parameters supplied by a user command (either "/update <id> ..." or "/add ..."),
/// verifies the channel username and feed URL, optionally validates an IV hash and a replacement regexp,
/// ensures both the bot and the command sender are administrators of the target channel, and performs the database update.
///
/// # Parameters
///
/// - `command` — the invoked command, expected to be either `"/update"` (followed by a numeric source id) or `"/add"`.
/// - `msg` — the incoming Telegram message; used to derive the command sender and target chat id for the reply.
/// - `words` — the command arguments: for `"/add"` expected `channel url [iv_hash|'-'] [url_re|'-']`; for `"/update"` the first element must be a numeric `source_id` followed by the same parameters.
pub async fn update (core: &Core, command: &str, msg: &Message, words: &[String]) -> Result<()> {
let sender = msg.sender.get_user_id()
.stack_err("Ignoring unreal users.")?;
let mut source_id: Option<i32> = None;
let at_least = "Requires at least 3 parameters.";
let mut i_words = words.iter();
match command {
|
151
152
153
154
155
156
157
158
159
160
|
if member_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."); };
let mut conn = core.db.begin().await.stack()?;
core.tg.send(conn.update(source_id, channel, channel_id, url, iv_hash, url_re, sender).await.stack()?, Some(msg.chat.get_id()), None).await.stack()?;
Ok(())
}
|
|
>
|
179
180
181
182
183
184
185
186
187
188
189
|
if member_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."); };
let mut conn = core.db.begin().await.stack()?;
let update = conn.update(source_id, channel, channel_id, url, iv_hash, url_re, sender).await.stack()?;
core.tg.send(update, Some(msg.chat.get_id()), None).await.stack()?;
Ok(())
}
|