Compare commits
4 Commits
0c71fd3796
...
85f16311fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85f16311fa | ||
|
|
f3ec4188bb | ||
|
|
2d5e2ed34e | ||
|
|
53edb54118 |
@ -1,6 +1,9 @@
|
|||||||
use crate::query_call_consume;
|
use crate::query_call_consume;
|
||||||
use crate::CallDB;
|
use crate::CallDB;
|
||||||
use bson::oid::ObjectId;
|
use bson::oid::ObjectId;
|
||||||
|
use chrono::DateTime;
|
||||||
|
use chrono::FixedOffset;
|
||||||
|
use chrono::Local;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::DbResult;
|
use super::DbResult;
|
||||||
@ -12,6 +15,7 @@ where
|
|||||||
C: Serialize,
|
C: Serialize,
|
||||||
{
|
{
|
||||||
pub _id: bson::oid::ObjectId,
|
pub _id: bson::oid::ObjectId,
|
||||||
|
pub created_at: DateTime<FixedOffset>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub callback: C,
|
pub callback: C,
|
||||||
}
|
}
|
||||||
@ -23,6 +27,7 @@ where
|
|||||||
pub fn new(callback: C) -> Self {
|
pub fn new(callback: C) -> Self {
|
||||||
Self {
|
Self {
|
||||||
_id: Default::default(),
|
_id: Default::default(),
|
||||||
|
created_at: Local::now().into(),
|
||||||
callback,
|
callback,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
pub mod callback_info;
|
pub mod callback_info;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use enum_stringify::EnumStringify;
|
use enum_stringify::EnumStringify;
|
||||||
@ -129,6 +131,25 @@ impl DB {
|
|||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// clear callbacks after a day because otherwise database will contain so much data
|
||||||
|
// for just button clicks
|
||||||
|
let callback_info = self
|
||||||
|
.get_database()
|
||||||
|
.await
|
||||||
|
.collection::<Event>("callback_info");
|
||||||
|
callback_info
|
||||||
|
.create_index(
|
||||||
|
IndexModel::builder()
|
||||||
|
.keys(doc! {"created_at": 1})
|
||||||
|
.options(
|
||||||
|
IndexOptions::builder()
|
||||||
|
.expire_after(Duration::from_secs(60 * 60 * 24 /* 1 day */))
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/main.rs
16
src/main.rs
@ -75,7 +75,7 @@ pub enum State {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum Callback {
|
pub enum Callback {
|
||||||
MoreInfo,
|
MoreInfo,
|
||||||
ProjectPage { id: u32 },
|
ProjectPage { id: u32 },
|
||||||
@ -611,14 +611,14 @@ async fn make_start_buttons(db: &mut DB) -> BotResult<InlineKeyboardMarkup> {
|
|||||||
)]
|
)]
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
buttons.push(vec![InlineKeyboardButton::callback(
|
||||||
|
"More info",
|
||||||
|
CallbackStore::new(Callback::MoreInfo)
|
||||||
|
.store(db)
|
||||||
|
.await?
|
||||||
|
.get_id(),
|
||||||
|
)]);
|
||||||
buttons.push(vec![
|
buttons.push(vec![
|
||||||
InlineKeyboardButton::callback(
|
|
||||||
"More info",
|
|
||||||
CallbackStore::new(Callback::MoreInfo)
|
|
||||||
.store(db)
|
|
||||||
.await?
|
|
||||||
.get_id(),
|
|
||||||
),
|
|
||||||
create_callback_button(
|
create_callback_button(
|
||||||
"show_projects",
|
"show_projects",
|
||||||
CallbackStore::new(Callback::ProjectPage { id: 1 }),
|
CallbackStore::new(Callback::ProjectPage { id: 1 }),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user