1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
use crate::{
Arc,
command,
Mutex,
sql::Db,
tg_bot::{
Callback,
MyMessage,
Tg,
},
};
use std::{
borrow::Cow,
collections::{
BTreeMap,
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
use crate::{
Arc,
command,
Mutex,
sql::Db,
tg_bot::{
Callback,
MyMessage,
Tg,
validate,
},
};
use std::{
borrow::Cow,
collections::{
BTreeMap,
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
pub tg: Tg,
pub db: Db,
pub feeds: Arc<Mutex<UserCache>>,
running: Arc<Mutex<HashSet<i32>>>,
http_client: reqwest::Client,
}
pub struct Post {
uri: String,
_title: String,
_authors: String,
_summary: String,
}
|
>
>
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
pub tg: Tg,
pub db: Db,
pub feeds: Arc<Mutex<UserCache>>,
running: Arc<Mutex<HashSet<i32>>>,
http_client: reqwest::Client,
}
// XXX Right now that part is unfinished and I guess I need to finish menu first
#[allow(unused)]
pub struct Post {
uri: String,
_title: String,
_authors: String,
_summary: String,
}
|
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
}
impl UpdateHandler for Core {
/// Dispatches an incoming Telegram update to a matching command handler and reports handler errors to the originating chat.
///
/// This method inspects the update; if it contains a message that can be parsed as a bot command,
/// it executes the corresponding command handler. If the handler returns an error, the error text
/// is sent back to the message's chat using MarkdownV2 formatting. Unknown commands produce an error
/// which is also reported to the chat.
async fn handle (&self, update: Update) -> () {
match update.update_type {
UpdateType::Message(msg) => {
if let Ok(cmd) = Command::try_from(*msg) {
let msg = cmd.get_message();
let words = cmd.get_args();
let command = cmd.get_name();
let res = match command {
"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(self, command, msg, words).await,
"/start" => command::start(self, msg).await,
"/list" => command::list(self, msg).await,
"/test" => command::test(self, msg).await,
"/add" | "/update" => command::update(self, command, msg, words).await,
any => Err(anyhow!("Unknown command: {any}")),
};
if let Err(err) = res
&& let Err(err2) = self.tg.send(MyMessage::html_to(
format!("#error<pre>{err}</pre>"),
msg.chat.get_id(),
)).await
{
dbg!(err2);
}
} else {
// not a command
}
},
UpdateType::CallbackQuery(query) => {
if let Some(ref cb) = query.data
|
|
<
|
>
>
|
|
|
|
<
|
>
>
>
>
>
>
|
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
}
impl UpdateHandler for Core {
/// Dispatches an incoming Telegram update to a matching command handler and reports handler errors to the originating chat.
///
/// This method inspects the update; if it contains a message that can be parsed as a bot command,
/// it executes the corresponding command handler. If the handler returns an error, the error text
/// is sent back to the message's chat. Unknown commands produce an error which is also reported to the chat.
async fn handle (&self, update: Update) -> () {
match update.update_type {
UpdateType::Message(msg) => {
if let Ok(cmd) = Command::try_from(*msg) {
let msg = cmd.get_message();
let words = cmd.get_args();
let command = cmd.get_name();
let res = match command {
"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(self, command, msg, words).await,
"/start" => command::start(self, msg).await,
"/list" => command::list(self, msg).await,
"/test" => command::test(self, msg).await,
"/add" | "/update" => command::update(self, command, msg, words).await,
any => Err(anyhow!("Unknown command: {any}")),
};
if let Err(err) = res {
match validate(&err.to_string()) {
Ok(text) => {
if let Err(err2) = self.tg.send(MyMessage::html_to(
format!("#error<pre>{}</pre>", text),
msg.chat.get_id(),
)).await {
dbg!(err2);
}
},
Err(err2) => {
dbg!(err2);
},
}
}
} else {
// not a command
}
},
UpdateType::CallbackQuery(query) => {
if let Some(ref cb) = query.data
|