Compare commits
No commits in common. "85f16311fa440e3ad4be343978c86e79ceed856f" and "0c71fd379635815e6d00db81a48800b904afd445" have entirely different histories.
85f16311fa
...
0c71fd3796
@ -1,9 +1,6 @@
|
|||||||
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;
|
||||||
@ -15,7 +12,6 @@ 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,
|
||||||
}
|
}
|
||||||
@ -27,7 +23,6 @@ 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,7 +1,5 @@
|
|||||||
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;
|
||||||
@ -131,25 +129,6 @@ 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_all = "snake_case")]
|
#[serde(rename = "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