cargo add chrono_tz
This commit is contained in:
parent
f7ced4b780
commit
2bad5d79c7
89
Cargo.lock
generated
89
Cargo.lock
generated
@ -17,6 +17,15 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.2.21"
|
version = "0.2.21"
|
||||||
@ -180,6 +189,27 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono-tz"
|
||||||
|
version = "0.10.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "efdce149c370f133a071ca8ef6ea340b7b88748ab0810097a9e2976eaa34b4f3"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"chrono-tz-build",
|
||||||
|
"phf",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono-tz-build"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f10f8c9340e31fc120ff885fcdb54a0b48e474bbd77cab557f0c30a3e569402"
|
||||||
|
dependencies = [
|
||||||
|
"parse-zoneinfo",
|
||||||
|
"phf_codegen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@ -735,6 +765,7 @@ name = "gongbotrs"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"chrono-tz",
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
"diesel-derive-enum",
|
"diesel-derive-enum",
|
||||||
@ -1369,6 +1400,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parse-zoneinfo"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24"
|
||||||
|
dependencies = [
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
@ -1384,6 +1424,26 @@ dependencies = [
|
|||||||
"phf_shared",
|
"phf_shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_codegen"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
|
||||||
|
dependencies = [
|
||||||
|
"phf_generator",
|
||||||
|
"phf_shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_generator"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||||
|
dependencies = [
|
||||||
|
"phf_shared",
|
||||||
|
"rand 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf_shared"
|
name = "phf_shared"
|
||||||
version = "0.11.3"
|
version = "0.11.3"
|
||||||
@ -1608,6 +1668,35 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.15"
|
version = "0.12.15"
|
||||||
|
|||||||
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.40"
|
chrono = "0.4.40"
|
||||||
|
chrono-tz = "0.10.3"
|
||||||
diesel = { version = "2.2.8", features = ["postgres", "chrono"] }
|
diesel = { version = "2.2.8", features = ["postgres", "chrono"] }
|
||||||
diesel-async = { version = "0.5.2", features = ["bb8", "postgres"] }
|
diesel-async = { version = "0.5.2", features = ["bb8", "postgres"] }
|
||||||
diesel-derive-enum = "2.1.0"
|
diesel-derive-enum = "2.1.0"
|
||||||
|
|||||||
26
src/db.rs
26
src/db.rs
@ -4,6 +4,7 @@ use crate::Config;
|
|||||||
|
|
||||||
use self::models::*;
|
use self::models::*;
|
||||||
|
|
||||||
|
use chrono::Utc;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel_async::pooled_connection::bb8::Pool;
|
use diesel_async::pooled_connection::bb8::Pool;
|
||||||
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
||||||
@ -186,4 +187,29 @@ impl DB {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_all_events(&mut self) -> Vec<Event> {
|
||||||
|
use self::schema::events::dsl::*;
|
||||||
|
let mut conn = self.pool.get().await.unwrap();
|
||||||
|
events
|
||||||
|
.filter(id.gt(0))
|
||||||
|
.load::<Event>(&mut conn)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_event(
|
||||||
|
&mut self,
|
||||||
|
event_datetime: chrono::DateTime<Utc>,
|
||||||
|
) -> Result<Event, Box<dyn std::error::Error>> {
|
||||||
|
use self::schema::events::dsl::*;
|
||||||
|
let conn = &mut self.pool.get().await.unwrap();
|
||||||
|
|
||||||
|
let new_event = diesel::insert_into(events)
|
||||||
|
.values((time.eq(event_datetime),))
|
||||||
|
.get_result::<Event>(conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(new_event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@ -9,6 +9,7 @@ use envconfig::Envconfig;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use teloxide::dispatching::dialogue::serializer::Json;
|
use teloxide::dispatching::dialogue::serializer::Json;
|
||||||
use teloxide::dispatching::dialogue::{InMemStorage, PostgresStorage};
|
use teloxide::dispatching::dialogue::{InMemStorage, PostgresStorage};
|
||||||
|
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
payloads::SendMessageSetters,
|
payloads::SendMessageSetters,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -68,6 +69,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let db_url2 = config.db_url.clone();
|
let db_url2 = config.db_url.clone();
|
||||||
let state_mgr = PostgresStorage::open(&db_url2, 8, Json).await?;
|
let state_mgr = PostgresStorage::open(&db_url2, 8, Json).await?;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: delete this in production
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
let handler = dptree::entry()
|
let handler = dptree::entry()
|
||||||
.inspect(|u: Update| {
|
.inspect(|u: Update| {
|
||||||
eprintln!("{u:#?}"); // Print the update to the console with inspect
|
eprintln!("{u:#?}"); // Print the update to the console with inspect
|
||||||
@ -214,6 +220,7 @@ async fn user_command_handler(
|
|||||||
.unwrap_or("Please, set content of this message".into());
|
.unwrap_or("Please, set content of this message".into());
|
||||||
let msg = bot
|
let msg = bot
|
||||||
.send_message(msg.chat.id, text)
|
.send_message(msg.chat.id, text)
|
||||||
|
.reply_markup(make_start_buttons())
|
||||||
.parse_mode(teloxide::types::ParseMode::Html)
|
.parse_mode(teloxide::types::ParseMode::Html)
|
||||||
.await?;
|
.await?;
|
||||||
db.set_message_literal(msg.chat.id.0, msg.id.0, literal)
|
db.set_message_literal(msg.chat.id.0, msg.id.0, literal)
|
||||||
@ -229,6 +236,18 @@ async fn user_command_handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_start_buttons() -> InlineKeyboardMarkup {
|
||||||
|
let mut buttons = vec![
|
||||||
|
vec![
|
||||||
|
InlineKeyboardButton::callback("Button 1", "callback_data_1"),
|
||||||
|
InlineKeyboardButton::callback("Button 2", "callback_data_2"),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
buttons.push(vec![InlineKeyboardButton::callback("More info", "more_info")]);
|
||||||
|
|
||||||
|
InlineKeyboardMarkup::new(buttons)
|
||||||
|
}
|
||||||
|
|
||||||
async fn echo(bot: Bot, msg: Message) -> Result<(), teloxide::RequestError> {
|
async fn echo(bot: Bot, msg: Message) -> Result<(), teloxide::RequestError> {
|
||||||
if let Some(photo) = msg.photo() {
|
if let Some(photo) = msg.photo() {
|
||||||
println!("File ID: {}", photo[0].file.id);
|
println!("File ID: {}", photo[0].file.id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user