{"id":336797,"date":"2022-08-09T15:00:33","date_gmt":"2022-08-09T15:00:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336797"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336797","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b telegram \u0431\u043e\u0442\u0430 \u043d\u0430 Rust \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0432 \u0432\u0443\u0437<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u043b\u044c\u044f, \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0434\u0430\u044e \u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u044b \u0432 \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u0443. \u0421\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u043e\u0432 \u0432 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0441\u0440\u0430\u0437\u0443, \u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 &#8212; \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0430 \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e\u0435\u043b\u043e. \u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f devtools \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430, \u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c. \u0410 Rust \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 &#8212; \u043e\u043d \u043c\u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f, \u043d\u0443 \u0438 \u0435\u0441\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0448\u0442\u0443\u043a\u0438 \u0432\u0441\u044f\u043a\u0438\u0435.<\/p>\n<p>\u041d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e, \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 (\u0438 \u0431\u043e\u0442\u0430). \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u043e\u0432 \u043d\u0430 Rust, \u043d\u043e \u044f \u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f. \u0418 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b reqwest \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0438\u0447\u0435\u0439 <code>json<\/code> \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>async\/await<\/code> &#8212; <a href=\"https:\/\/crates.io\/crates\/tokio\" rel=\"noopener noreferrer nofollow\">tokio<\/a>, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SQLite &#8212; <a href=\"https:\/\/crates.io\/crates\/rusqlite\" rel=\"noopener noreferrer nofollow\">rusqlite<\/a>.<\/p>\n<p><em>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u044b \u0418\u0422\u041c\u041e<\/em><\/p>\n<h4>\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b<\/h4>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0431\u0430\u0437\u0435, \u0434\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b, \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430, \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0435 10 \u043c\u0438\u043d\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u0441 \u0441\u0430\u0439\u0442\u0430.<\/p>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430<\/h4>\n<p>\u041d\u0430\u0447\u0430\u043b \u044f \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0435 \u0441 <code>abitlk.itmo.ru<\/code>. \u0417\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>find_score<\/code> \u0438\u0449\u0435\u0442 \u0432 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430, \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e<\/p>\n<details class=\"spoiler\">\n<summary>get_rating_competition<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn get_rating_competition(     degree: &amp;str,     program_id: &amp;str,     case_number: &amp;str, ) -> Result&lt;Option&lt;Competition>, Box&lt;dyn std::error::Error>> {     let rating_response: RatingResponse = reqwest::get(format!(         \"{API_PREFIX}\/{API_KEY}\/rating\/{degree}\/budget?program_id={program_id}\"     ))     .await?     .json()     .await?;      match find_score(rating_response, case_number) {         None => Err(Box::from(\"no matching competition\")),         competition => Ok(competition),     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0432 \u043f\u043e\u043b\u0435 <code>ok<\/code> \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c <code>false<\/code>, \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <code>None<\/code>. \u0418\u043d\u0430\u0447\u0435 \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 <code>response.result.general_competition<\/code>, \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0443 \u0434\u0435\u043b\u0430 \u0438\u0437 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0430 (\u0443 \u043c\u0435\u043d\u044f \u0432\u0438\u0434\u0430 <code>\u041c\u0445-\u0445\u0445\u0445\u0445-2022<\/code>)<\/p>\n<details class=\"spoiler\">\n<summary>find_score<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">fn find_score(response: RatingResponse, case_number: &amp;str) -> Option&lt;Competition> {     if !response.ok {         return None;     }      response         .result         .general_competition         .iter()         .find(|c| -> bool {             if let Some(c) = &amp;c.case_number {                 c == case_number             } else {                 false             }         })         .cloned() } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>RatingResponse<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a. \u0422\u0443\u0442 \u044f \u0437\u0430\u0434\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0434\u0443\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u0440\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub struct Response&lt;T> {     pub ok: bool,     pub message: String,     pub result: T, }  pub type RatingResponse = Response&lt;RatingResult>;  pub struct RatingResult {     pub general_competition: Vec&lt;Competition>, }  pub struct Competition {     pub position: i32,     pub priority: i32,     pub total_scores: f64,     pub case_number: Option&lt;String>,     pub exam_scores: Option&lt;f64>, } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>serde::Deserialize<\/code> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 json) \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"rust\">#[derive(Deserialize)] pub struct Response&lt;T> {} <\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u043d\u0434\u043f\u043e\u0439\u043d\u0442 <code>https:\/\/api.telegram.org\/botTOKEN\/getUpdates?offset=x<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. <code>offset<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043a\u0430\u043a \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f:<\/p>\n<details class=\"spoiler\">\n<summary>get_updates<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">async fn get_updates(offset: i32) -> Result&lt;GetUpdatesResponse, Box&lt;dyn std::error::Error>> {     let params = [(\"offset\", &amp;offset.to_string())];     let url =         reqwest::Url::parse_with_params(&amp;format!(\"{TG_API_PREFIX}{TOKEN}\/getUpdates\"), &amp;params)?;      let response = reqwest::get(url).await?;     if !response.status().is_success() {         let error: ErrorResponse = response.json().await?;         let text = format!(             \"cannot get updates\\nerror: `{}`\",             error.description.unwrap_or_default()         );         send_message(&amp;text, LOGS_CHAT_ID).await?;         return Err(Box::from(\"cannot get updates\"));     }      Ok(response.json().await?) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c. \u0417\u0434\u0435\u0441\u044c \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 <code>update_id<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>offset<\/code>, \u0434\u0430\u043b\u0435\u0435 \u0432 <code>MessageRequest::from(text)<\/code> \u043f\u0430\u0440\u0441\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u043e\u043d\u0430 \u0434\u0430\u043b\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>handle_updates<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn handle_updates(db: &amp;DB, offset: i32) -> Result&lt;i32, Box&lt;dyn std::error::Error>> {     let data = get_updates(offset).await?;      let mut max_update_id = 0;     for update in data.result {         if update.update_id > max_update_id {             max_update_id = update.update_id;         }          if let Some(message) = update.message {             if let Some(text) = message.text {                 let chat_id = message.from.id.to_string();                 match MessageRequest::from(text) {                     Some(request) => handle_message_request(db, request, &amp;chat_id).await?,                     None => send_message(messages::unknown_message, &amp;chat_id).await?,                 }             }         }     }      Ok(max_update_id + 1) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0430\u0440\u0441\u0438\u0442\u0441\u044f \u0442\u0430\u043a (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>from<\/code>). \u0422\u0435\u043a\u0441\u0442 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u0430\u043c, \u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0434\u043d\u043e\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <code>\/watch<\/code> \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0438\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438. \u041f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0435\u0451 \u0438\u043c\u044f, \u0434\u0430\u043b\u0435\u0435 \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<details class=\"spoiler\">\n<summary>MessageRequest::from<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">impl MessageRequest {     pub fn from(text: String) -> Option&lt;Self> {         let text: Vec&lt;String> = text.split(' ').map(|w| w.to_string()).collect();         if text.is_empty() {             return None;         }          let command = text[0].as_str();         match command {             \"\/watch\" | \"\/unwatch\" => {                 let incorrect_command = Some(Self::IncorrectCommand(command.to_string()));                  if text.len() &lt; 5 {                     if text.len() == 2 &amp;&amp; text[1] == \"all\" {                         return Some(Self::UnwatchAll);                     }                     return incorrect_command;                 }                  \/\/ waiting for let-chain                 if let Some(watch) = Watch::new(\"itmo\", &amp;text[2], &amp;text[3], &amp;text[4]) {                     if watch.degree == Degree::Master {                         return match command {                             \"\/watch\" => Some(Self::Watch(watch)),                             \"\/unwatch\" => Some(Self::Unwatch(watch)),                             _ => incorrect_command,                         };                     }                 }                  incorrect_command             }             \"\/about\" => Some(Self::About),             \"\/help\" => Some(Self::Help),             \"\/start\" => Some(Self::Start),             _ => None,         }     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>MessageRequest<\/code> \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <code>Degree<\/code> \u0438 <code>Watch<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub enum Degree {     Bachelor,     Master,     Postgraduate, }  pub struct Watch {     pub uni: String,     pub degree: Degree,     pub program_id: String,     pub case_number: String, }  pub enum MessageRequest {     About,     Help,     Start,     Unwatch(Watch),     UnwatchAll,     Watch(Watch),     IncorrectCommand(String), } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><code>MessageRequest<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>\/watch<\/code> \u0438 <code>\/unwatch<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c (\u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435).<\/p>\n<details class=\"spoiler\">\n<summary>handle_message_request<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">async fn handle_message_request(     db: &amp;DB,     request: MessageRequest,     chat_id: &amp;str, ) -> Result&lt;(), CrateError> {     match request {         MessageRequest::Watch(args) => {             let result = handle_competition(db, chat_id, &amp;args.degree.to_string(), &amp;args.case_number, &amp;args.program_id, true).await;             if let Err(_) = result {                 send_message(messages::rating_not_found, chat_id).await?;             }         }         MessageRequest::Unwatch(args) => {             db.delete_competition(                 &amp;args.case_number,                 chat_id,                 &amp;args.program_id,                 &amp;args.degree.to_string(),             )?;             send_message(messages::done, chat_id).await?;         }         MessageRequest::UnwatchAll => {             db.delete_competition_by_user(chat_id)?;             send_message(messages::done, chat_id).await?;         }         MessageRequest::IncorrectCommand(command) => {             send_incorrect_command_message(&amp;command, chat_id).await?         }         MessageRequest::Help => send_message(messages::help, chat_id).await?,         MessageRequest::Start => send_message(messages::start, chat_id).await?,         MessageRequest::About => send_message(messages::about, chat_id).await?,     };     Ok(()) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u0443\u0447\u043d\u044b\u0439, \u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0434\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438\u0437 \u0431\u0430\u0437\u044b, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u043e \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0431\u0430\u0437\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439. \u0417\u0430 \u044d\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>is_user_request<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>handle_competition<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn handle_competition(     db: &amp;DB,     chat_id: &amp;str,     degree: &amp;str,     case_number: &amp;str,     program_id: &amp;str,     is_user_request: bool, ) -> Result&lt;(), Box&lt;dyn std::error::Error>> {     let competition = get_rating_competition(db, degree, program_id, case_number).await?;      match db.select_competition(chat_id, case_number, degree, program_id) {         Ok(old_competition) => {             if let Some(competition) = competition {                 let program = db.select_program(\"itmo\", program_id)?;                 let program_name = if let Some(program) = program {                     program.title_ru                 } else {                     \"\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0442\".to_string()                 };                  let mut should_send_message = false;                  \/\/ update if competition is old (competition != old_competition)                 \/\/ insert if is new (when old == None, on first user request)                 if let Some(old_competition) = old_competition {                     if competition != old_competition {                         db.update_competition(&amp;competition, chat_id, program_id, degree)?;                         should_send_message = true;                     }                 } else {                     db.insert_competition(&amp;competition, chat_id, program_id, degree)?;                 }                  \/\/ send if it's user request or record in db was updated                 if is_user_request || should_send_message {                     send_competition_message(&amp;competition, chat_id, &amp;program_name).await?;                 }             }         }         Err(e) => {             eprintln!(\"cannot select competition: {e}\")         }     };     Ok(()) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a. \u042d\u043a\u0440\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>send_message<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn send_message(text: &amp;str, chat_id: &amp;str) -> Result&lt;(), Box&lt;dyn std::error::Error>> {     let text = &amp;text.replace('-', \"\\\\-\").replace('.', \"\\\\.\");      let params = [         (\"chat_id\", chat_id),         (\"text\", text),         (\"parse_mode\", \"MarkdownV2\"),     ];      let url =         reqwest::Url::parse_with_params(&amp;format!(\"{TG_API_PREFIX}{TOKEN}\/sendMessage\"), &amp;params)?;     let response = reqwest::get(url).await?;     if !response.status().is_success() {         let error: ErrorResponse = response.json().await?;         let msg = \"Cannot send message request\";         if let Some(description) = error.description {             eprintln!(\"{msg}: {description}\");         }         return Err(Box::from(msg));     }      let data: SendMessageResponse = response.json().await?;      if !data.ok {         eprintln!(             \"Cannot send message: {}\",             data.description                 .unwrap_or_else(|| \"error has no description\".to_string())         )     }      Ok(()) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c<\/h4>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>main<\/code> \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (\u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439), \u0434\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>handle_updates<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 10 \u043c\u0438\u043d\u0443\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u0438 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438. <code>#[tokio::main]<\/code> \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430 main \u0441\u0440\u0430\u0437\u0443 \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f loop-\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>main<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">const TEN_MIN_IN_SEC: i32 = 10 * 60;  #[tokio::main] async fn main() -> Result&lt;(), Box&lt;dyn std::error::Error>> {     let db = init_db()?;      load_programs(&amp;db).await.unwrap();      let mut offset = 0;     let mut sec_counter = 0;     loop {         offset = handle_updates(&amp;db, offset).await.unwrap();          if sec_counter == 0 {             check_rating_updates(&amp;db).await?;         }         sec_counter = (sec_counter + 1) % TEN_MIN_IN_SEC;          time::sleep(time::Duration::from_secs(1)).await;     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>check_rating_updates<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">async fn check_rating_updates(db: &amp;DB) -> Result&lt;(), Box&lt;dyn std::error::Error>> {     \/\/ select registered watchers from 'results'     for c in db.select_all_competitions()? {         if let Some(case_number) = c.competition.case_number {             handle_competition(db, &amp;c.tg_chat_id, &amp;c.degree, &amp;case_number, &amp;c.program_id, false)             .await?;         }     }     Ok(()) }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u0431\u043e\u0442 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451 \u043a\u0440\u043e\u043c\u0435 \u043c\u0435\u043d\u044f. \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0431\u043e\u0442\u0430 <a href=\"https:\/\/t.me\/uni_rating_checker_bot\" rel=\"noopener noreferrer nofollow\">@uni_rating_checker_bot<\/a> \u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/istudyatuni\/uni-rating-checker\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<h4>P.S.<\/h4>\n<ul>\n<li>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 (\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u0430\u0431\u0435\u043d\u044c\u043a\u0438\u0439)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0444\u0438\u0447 &#8212; \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0438\u0437 \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u0448\u0435 \u043f\u043e \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0443, \u0443\u0436\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443 \u043d\u0438\u0445 \u0432\u044b\u0448\u0435 \u043f\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0443<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043b \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0443\u043b\u0443\u0447\u0448\u0438\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430\u0432\u0435\u0440\u0445 \u0438 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u0431\u0430\u043a\u0430\u043b\u0430\u0432\u0440\u0438\u0430\u0442\u0430 \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0434\u0440\u0443\u0433\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430 \u044d\u0442\u043e<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443, \u0432\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0430 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433 \u0432\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 &#8212; \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043d\u043e\u043f\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0412\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 <a href=\"https:\/\/habr.com\/p\/679832\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/p\/679832<\/a><\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0442\u044c: <code>\/watch itmo master 15850 M1-0979-2022<\/code>. \u042d\u0442\u043e \u043d\u0435 \u044f \ud83d\ude42 \u0412\u044b\u0431\u0440\u0430\u043b \u043d\u0430\u0443\u0433\u0430\u0434<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/681648\/\"> https:\/\/habr.com\/ru\/post\/681648\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u043b\u044c\u044f, \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0434\u0430\u044e \u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u044b \u0432 \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u0443. \u0421\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u043e\u0432 \u0432 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0441\u0440\u0430\u0437\u0443, \u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 &#8212; \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0430 \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e\u0435\u043b\u043e. \u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f devtools \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430, \u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c. \u0410 Rust \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 &#8212; \u043e\u043d \u043c\u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f, \u043d\u0443 \u0438 \u0435\u0441\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0448\u0442\u0443\u043a\u0438 \u0432\u0441\u044f\u043a\u0438\u0435.<\/p>\n<p>\u041d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e, \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 (\u0438 \u0431\u043e\u0442\u0430). \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u043e\u0432 \u043d\u0430 Rust, \u043d\u043e \u044f \u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f. \u0418 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b reqwest \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0438\u0447\u0435\u0439 <code>json<\/code> \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>async\/await<\/code> &#8212; <a href=\"https:\/\/crates.io\/crates\/tokio\" rel=\"noopener noreferrer nofollow\">tokio<\/a>, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SQLite &#8212; <a href=\"https:\/\/crates.io\/crates\/rusqlite\" rel=\"noopener noreferrer nofollow\">rusqlite<\/a>.<\/p>\n<p><em>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u044b \u0418\u0422\u041c\u041e<\/em><\/p>\n<h4>\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b<\/h4>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0431\u0430\u0437\u0435, \u0434\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b, \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430, \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0435 10 \u043c\u0438\u043d\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u0441 \u0441\u0430\u0439\u0442\u0430.<\/p>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430<\/h4>\n<p>\u041d\u0430\u0447\u0430\u043b \u044f \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0435 \u0441 <code>abitlk.itmo.ru<\/code>. \u0417\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>find_score<\/code> \u0438\u0449\u0435\u0442 \u0432 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430, \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e<\/p>\n<details class=\"spoiler\">\n<summary>get_rating_competition<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn get_rating_competition(     degree: &amp;str,     program_id: &amp;str,     case_number: &amp;str, ) -> Result&lt;Option&lt;Competition>, Box&lt;dyn std::error::Error>> {     let rating_response: RatingResponse = reqwest::get(format!(         \"{API_PREFIX}\/{API_KEY}\/rating\/{degree}\/budget?program_id={program_id}\"     ))     .await?     .json()     .await?;      match find_score(rating_response, case_number) {         None => Err(Box::from(\"no matching competition\")),         competition => Ok(competition),     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0432 \u043f\u043e\u043b\u0435 <code>ok<\/code> \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c <code>false<\/code>, \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <code>None<\/code>. \u0418\u043d\u0430\u0447\u0435 \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 <code>response.result.general_competition<\/code>, \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0443 \u0434\u0435\u043b\u0430 \u0438\u0437 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0430 (\u0443 \u043c\u0435\u043d\u044f \u0432\u0438\u0434\u0430 <code>\u041c\u0445-\u0445\u0445\u0445\u0445-2022<\/code>)<\/p>\n<details class=\"spoiler\">\n<summary>find_score<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">fn find_score(response: RatingResponse, case_number: &amp;str) -> Option&lt;Competition> {     if !response.ok {         return None;     }      response         .result         .general_competition         .iter()         .find(|c| -> bool {             if let Some(c) = &amp;c.case_number {                 c == case_number             } else {                 false             }         })         .cloned() } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>RatingResponse<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a. \u0422\u0443\u0442 \u044f \u0437\u0430\u0434\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0434\u0443\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u0440\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub struct Response&lt;T> {     pub ok: bool,     pub message: String,     pub result: T, }  pub type RatingResponse = Response&lt;RatingResult>;  pub struct RatingResult {     pub general_competition: Vec&lt;Competition>, }  pub struct Competition {     pub position: i32,     pub priority: i32,     pub total_scores: f64,     pub case_number: Option&lt;String>,     pub exam_scores: Option&lt;f64>, } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>serde::Deserialize<\/code> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 json) \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"rust\">#[derive(Deserialize)] pub struct Response&lt;T> {} <\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u043d\u0434\u043f\u043e\u0439\u043d\u0442 <code>https:\/\/api.telegram.org\/botTOKEN\/getUpdates?offset=x<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. <code>offset<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043a\u0430\u043a \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f:<\/p>\n<details class=\"spoiler\">\n<summary>get_updates<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">async fn get_updates(offset: i32) -> Result&lt;GetUpdatesResponse, Box&lt;dyn std::error::Error>> {     let params = [(\"offset\", &amp;offset.to_string())];     let url =         reqwest::Url::parse_with_params(&amp;format!(\"{TG_API_PREFIX}{TOKEN}\/getUpdates\"), &amp;params)?;      let response = reqwest::get(url).await?;     if !response.status().is_success() {         let error: ErrorResponse = response.json().await?;         let text = format!(             \"cannot get updates\\nerror: `{}`\",             error.description.unwrap_or_default()         );         send_message(&amp;text, LOGS_CHAT_ID).await?;         return Err(Box::from(\"cannot get updates\"));     }      Ok(response.json().await?) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c. \u0417\u0434\u0435\u0441\u044c \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 <code>update_id<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>offset<\/code>, \u0434\u0430\u043b\u0435\u0435 \u0432 <code>MessageRequest::from(text)<\/code> \u043f\u0430\u0440\u0441\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u043e\u043d\u0430 \u0434\u0430\u043b\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>handle_updates<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn handle_updates(db: &amp;DB, offset: i32) -> Result&lt;i32, Box&lt;dyn std::error::Error>> {     let data = get_updates(offset).await?;      let mut max_update_id = 0;     for update in data.result {         if update.update_id > max_update_id {             max_update_id = update.update_id;         }          if let Some(message) = update.message {             if let Some(text) = message.text {                 let chat_id = message.from.id.to_string();                 match MessageRequest::from(text) {                     Some(request) => handle_message_request(db, request, &amp;chat_id).await?,                     None => send_message(messages::unknown_message, &amp;chat_id).await?,                 }             }         }     }      Ok(max_update_id + 1) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0430\u0440\u0441\u0438\u0442\u0441\u044f \u0442\u0430\u043a (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>from<\/code>). \u0422\u0435\u043a\u0441\u0442 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u0430\u043c, \u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0434\u043d\u043e\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <code>\/watch<\/code> \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0438\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438. \u041f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0435\u0451 \u0438\u043c\u044f, \u0434\u0430\u043b\u0435\u0435 \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<details class=\"spoiler\">\n<summary>MessageRequest::from<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">impl MessageRequest {     pub fn from(text: String) -> Option&lt;Self> {         let text: Vec&lt;String> = text.split(' ').map(|w| w.to_string()).collect();         if text.is_empty() {             return None;         }          let command = text[0].as_str();         match command {             \"\/watch\" | \"\/unwatch\" => {                 let incorrect_command = Some(Self::IncorrectCommand(command.to_string()));                  if text.len() &lt; 5 {                     if text.len() == 2 &amp;&amp; text[1] == \"all\" {                         return Some(Self::UnwatchAll);                     }                     return incorrect_command;                 }                  \/\/ waiting for let-chain                 if let Some(watch) = Watch::new(\"itmo\", &amp;text[2], &amp;text[3], &amp;text[4]) {                     if watch.degree == Degree::Master {                         return match command {                             \"\/watch\" => Some(Self::Watch(watch)),                             \"\/unwatch\" => Some(Self::Unwatch(watch)),                             _ => incorrect_command,                         };                     }                 }                  incorrect_command             }             \"\/about\" => Some(Self::About),             \"\/help\" => Some(Self::Help),             \"\/start\" => Some(Self::Start),             _ => None,         }     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>MessageRequest<\/code> \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <code>Degree<\/code> \u0438 <code>Watch<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub enum Degree {     Bachelor,     Master,     Postgraduate, }  pub struct Watch {     pub uni: String,     pub degree: Degree,     pub program_id: String,     pub case_number: String, }  pub enum MessageRequest {     About,     Help,     Start,     Unwatch(Watch),     UnwatchAll,     Watch(Watch),     IncorrectCommand(String), } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><code>MessageRequest<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>\/watch<\/code> \u0438 <code>\/unwatch<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c (\u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435).<\/p>\n<details class=\"spoiler\">\n<summary>handle_message_request<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">async fn handle_message_request(     db: &amp;DB,     request: MessageRequest,     chat_id: &amp;str, ) -> Result&lt;(), CrateError> {     match request {         MessageRequest::Watch(args) => {             let result = handle_competition(db, chat_id, &amp;args.degree.to_string(), &amp;args.case_number, &amp;args.program_id, true).await;             if let Err(_) = result {                 send_message(messages::rating_not_found, chat_id).await?;             }         }         MessageRequest::Unwatch(args) => {             db.delete_competition(                 &amp;args.case_number,                 chat_id,                 &amp;args.program_id,                 &amp;args.degree.to_string(),             )?;             send_message(messages::done, chat_id).await?;         }         MessageRequest::UnwatchAll => {             db.delete_competition_by_user(chat_id)?;             send_message(messages::done, chat_id).await?;         }         MessageRequest::IncorrectCommand(command) => {             send_incorrect_command_message(&amp;command, chat_id).await?         }         MessageRequest::Help => send_message(messages::help, chat_id).await?,         MessageRequest::Start => send_message(messages::start, chat_id).await?,         MessageRequest::About => send_message(messages::about, chat_id).await?,     };     Ok(()) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u0443\u0447\u043d\u044b\u0439, \u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0434\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438\u0437 \u0431\u0430\u0437\u044b, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u043e \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0431\u0430\u0437\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439. \u0417\u0430 \u044d\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>is_user_request<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>handle_competition<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"rust\">pub async fn handle_competition(     db: &amp;DB,     chat_id: &amp;str,     degree: &amp;str,     case_number: &amp;str,     program_id: &amp;str,     is_user_request: bool, ) -> Result&lt;(), Box&lt;dyn std::error::Error>> {     let competition = get_rating_competition(db, degree, program_id, case_number).await?;      match db.select_competition(chat_id, case_number, degree, program_id) {         Ok(old_competition) => {             if let Some(competition) = competition {                 let program = db.select_program(\"itmo\", program_id)?;    <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336797","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336797"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336797\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}