Diff
Logged in as anonymous

Differences From Artifact [65c59c91da]:

To Artifact [9c3b6abd62]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
2
3

4


5
6
7
8
9
10
11



-

-
-







mod command;
mod core;

use config;
use futures::StreamExt;
use tokio;
use telegram_bot;

#[macro_use]
extern crate lazy_static;

use anyhow::Result;

#[tokio::main]
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
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







-
+




-
+






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




	stream.allowed_updates(&[telegram_bot::AllowedUpdate::Message]);
	let mut reply_to: Option<telegram_bot::UserId>;

	loop {
		reply_to = None;
		match stream.next().await {
			Some(update) => {
				if let Err(err) = handle(update?, &core, &mut reply_to).await {
				if let Err(err) = handle(update?, &core, &reply_to).await {
					core.send(&format!("🛑 {:?}", err), reply_to, None)?;
				};
			},
			None => {
				core.send(&format!("🛑 None error."), None, None)?;
				core.send("🛑 None error.".to_string(), None, None)?;
			}
		};
	}
}

async fn handle(update: telegram_bot::Update, core: &core::Core, mut _reply_to: &Option<telegram_bot::UserId>) -> Result<()> {
	match update.kind {
		telegram_bot::UpdateKind::Message(message) => {
	if let telegram_bot::UpdateKind::Message(message) = update.kind {
			match message.kind {
				telegram_bot::MessageKind::Text { ref data, .. } => {
					let sender = message.from.id;
					let words: Vec<&str> = data.split_whitespace().collect();
					match match words[0] {
						"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
						"/start" => command::start(core, sender).await,
						"/list" => command::list(core, sender).await,
						"/add" | "/update" => command::update(core, sender, words).await,
						_ => Ok(()),
					} {
						Err(err) => core.send(&format!("🛑 {:?}", err), Some(sender), None)?,
						Ok(()) => {},
					};
		if let telegram_bot::MessageKind::Text { ref data, .. } = message.kind {
			let sender = message.from.id;
			let words: Vec<&str> = data.split_whitespace().collect();
			match match words[0] {
				"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
				"/start" => command::start(core, sender).await,
				"/list" => command::list(core, sender).await,
				"/add" | "/update" => command::update(core, sender, words).await,
				_ => Ok(()),
			} {
				Err(err) => core.send(&format!("🛑 {:?}", err), Some(sender), None)?,
				Ok(()) => {},
			};
				},
				_ => {
				},
			};
		};
		},
		_ => {},
	};

	Ok(())
}