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
|
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
|
+
+
+
+
+
+
+
+
+
+
+
|
use anyhow::{
anyhow,
bail,
Result,
};
use async_std::task;
use chrono::DateTime;
use lazy_static::lazy_static;
use regex::Regex;
use tgbot::{
api::Client,
handler::UpdateHandler,
types::{
Bot,
ChatPeerId,
Command,
GetBot,
Message,
ParseMode,
SendMessage,
Update,
UpdateType,
UserPeerId,
},
};
lazy_static!{
pub static ref RE_SPECIAL: Regex = Regex::new(r"([\-_*\[\]()~`>#+|{}\.!])").unwrap();
}
/// Encodes special HTML entities to prevent them interfering with Telegram HTML
pub fn encode (text: &str) -> Cow<'_, str> {
RE_SPECIAL.replace_all(text, "\\$1")
}
#[derive(Clone)]
pub struct Core {
owner_chat: ChatPeerId,
// max_delay: u16,
pub tg: Client,
pub me: Bot,
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
-
+
|
Ok(Some(source)) => source.to_string(),
Ok(None) => "Source not found in database?".to_string(),
Err(err) => format!("Failed to fetch source data:\n{err}"),
}
};
task::spawn(async move {
if let Err(err) = clone.check(source_id, true).await {
if let Err(err) = clone.send(&format!("{source}\nš {err:?}"), None, None).await {
if let Err(err) = clone.send(&format!("{source}\nš {}", encode(&err.to_string())), None, Some(ParseMode::MarkdownV2)).await {
eprintln!("Check error: {err:?}");
// clone.disable(&source_id, owner).await.unwrap();
};
};
});
}
} else if next_fetch - now < delay {
|