mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Update activity filter
This commit is contained in:
@@ -4,6 +4,8 @@ mod tools;
|
||||
|
||||
use teloxide::{prelude::*, types::BotCommand};
|
||||
|
||||
use crate::bots::approved_bot::services::user_settings::create_or_update_user_settings;
|
||||
|
||||
use self::{
|
||||
modules::{
|
||||
annotations::get_annotations_handler, book::get_book_handler,
|
||||
@@ -18,20 +20,26 @@ use super::{ignore_channel_messages, BotCommands, BotHandler};
|
||||
|
||||
async fn _update_activity(me: teloxide::types::Me, user: teloxide::types::User) -> Option<()> {
|
||||
tokio::spawn(async move {
|
||||
let allowed_langs = get_user_or_default_lang_codes(user.id).await;
|
||||
if let Err(err) = update_user_activity(user.id).await {
|
||||
let allowed_langs = get_user_or_default_lang_codes(user.id).await;
|
||||
|
||||
match update_user_activity(
|
||||
user.id,
|
||||
user.last_name.clone().unwrap_or("".to_string()),
|
||||
user.first_name.clone(),
|
||||
user.username.clone().unwrap_or("".to_string()),
|
||||
me.username.clone().unwrap(),
|
||||
allowed_langs,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(err) => log::warn!("{}", err),
|
||||
if let Ok(_) = create_or_update_user_settings(
|
||||
user.id,
|
||||
user.last_name.clone().unwrap_or("".to_string()),
|
||||
user.first_name.clone(),
|
||||
user.username.clone().unwrap_or("".to_string()),
|
||||
me.username.clone().unwrap(),
|
||||
allowed_langs,
|
||||
)
|
||||
.await
|
||||
{
|
||||
#[allow(unused_must_use)]
|
||||
{
|
||||
update_user_activity(user.id).await;
|
||||
}
|
||||
}
|
||||
|
||||
log::warn!("{}", err);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -45,7 +53,7 @@ fn update_user_activity_handler() -> BotHandler {
|
||||
|cq: CallbackQuery, me: teloxide::types::Me| async move {
|
||||
_update_activity(me, cq.from).await
|
||||
},
|
||||
))
|
||||
)),
|
||||
)
|
||||
.branch(Update::filter_message().chain(dptree::filter_map_async(
|
||||
|message: Message, me: teloxide::types::Me| async move {
|
||||
|
||||
@@ -127,26 +127,11 @@ pub async fn get_langs() -> Result<Vec<Lang>, Box<dyn std::error::Error + Send +
|
||||
|
||||
pub async fn update_user_activity(
|
||||
user_id: UserId,
|
||||
last_name: String,
|
||||
first_name: String,
|
||||
username: String,
|
||||
source: String,
|
||||
allowed_langs: Vec<String>,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let body = json!({
|
||||
"user_id": user_id,
|
||||
"last_name": last_name,
|
||||
"first_name": first_name,
|
||||
"username": username,
|
||||
"source": source,
|
||||
"allowed_langs": allowed_langs
|
||||
});
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.post(format!("{}/users/{user_id}/update_activity", &config::CONFIG.user_settings_url))
|
||||
.header("Authorization", &config::CONFIG.user_settings_api_key)
|
||||
.body(body.to_string())
|
||||
.send()
|
||||
.await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user