mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 04:54:08 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
428416a2a3 | |||
77dec205f1 | |||
6c761d7576 | |||
865fd3bbe4 | |||
30bdb23a32 |
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "desubot"
|
||||
version = "0.5.1"
|
||||
version = "0.5.5"
|
||||
authors = ["AB <ab@hexor.ru>"]
|
||||
edition = "2018"
|
||||
|
||||
@ -38,4 +38,4 @@ sqlparser = "0.7.0"
|
||||
[dependencies.syntect]
|
||||
version = "4.4"
|
||||
default-features = false
|
||||
features = ["parsing", "dump-load", "regex-onig"]
|
||||
features = ["parsing", "dump-load", "regex-onig"]
|
||||
|
@ -21,7 +21,7 @@ use syntect::highlighting::Theme;
|
||||
use syntect::parsing::SyntaxReference;
|
||||
use syntect::util::LinesWithEndings;
|
||||
use telegram_bot::prelude::*;
|
||||
use telegram_bot::{Api, Message, ParseMode};
|
||||
use telegram_bot::{Api, Message, ParseMode, UserId};
|
||||
|
||||
include!("../assets/help_text.rs");
|
||||
|
||||
@ -69,7 +69,7 @@ impl Execute for Sql {
|
||||
let mut sql = self.data.clone();
|
||||
debug!("PIZDA - {}", sql);
|
||||
if sql == "/sql" || sql == "/sql-" {
|
||||
return Ok(SQL_HELP.to_string())
|
||||
return Ok(SQL_HELP.to_string());
|
||||
}
|
||||
let is_head = if sql.starts_with('-') {
|
||||
sql = sql.replacen("-", "", 1);
|
||||
@ -192,7 +192,15 @@ impl Execute for Sql {
|
||||
#[async_trait]
|
||||
impl Execute for Here {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
let members: Vec<telegram_bot::User> = db::get_members(message.chat.id()).unwrap();
|
||||
let members: Vec<telegram_bot::User> =
|
||||
db::get_members(message.chat.id(), 60).unwrap_or(vec![telegram_bot::User {
|
||||
id: UserId::new(124317807),
|
||||
first_name: "Ultradesu".to_string(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
is_bot: false,
|
||||
language_code: None,
|
||||
}]);
|
||||
for u in &members {
|
||||
debug!("Found user {:?} in chat {}", u, message.chat.id());
|
||||
}
|
||||
|
27
src/db.rs
27
src/db.rs
@ -180,18 +180,29 @@ pub(crate) async fn get_messages_user_all(
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
pub(crate) fn get_members(id: telegram_bot::ChatId) -> Result<Vec<telegram_bot::User>> {
|
||||
pub(crate) fn get_members(id: telegram_bot::ChatId, limit: u32) -> Result<Vec<telegram_bot::User>> {
|
||||
let where_statement = if limit > 0 {
|
||||
format!("and days_seen <= {}", limit)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
debug!("{}", where_statement);
|
||||
let conn = open()?;
|
||||
let mut stmt = conn.prepare_cached(
|
||||
let mut stmt = conn.prepare_cached(&format!(
|
||||
"
|
||||
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date
|
||||
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date,
|
||||
(strftime('%s','now')-r.date)/60/60/24 as days_seen
|
||||
FROM relations r
|
||||
JOIN user u
|
||||
ON u.id = r.user_id
|
||||
LEFT JOIN conf c
|
||||
ON r.conf_id = c.id
|
||||
WHERE c.id = :id",
|
||||
)?;
|
||||
WHERE c.id = :id
|
||||
{}
|
||||
GROUP BY u.id
|
||||
ORDER BY r.date DESC",
|
||||
where_statement
|
||||
))?;
|
||||
let mut rows = stmt.query_named(&[(":id", &id.to_string())])?;
|
||||
let mut users = Vec::new();
|
||||
|
||||
@ -283,7 +294,11 @@ pub(crate) async fn add_user(message: Message) -> Result<(), Error> {
|
||||
(":first_name", &update.first_name),
|
||||
(":last_name", &update.last_name),
|
||||
])?;
|
||||
debug!("User {} updated: {:?}", update.first_name, get_user(update.id));
|
||||
debug!(
|
||||
"User {} updated: {:?}",
|
||||
update.first_name,
|
||||
get_user(update.id)
|
||||
);
|
||||
}
|
||||
Err(_) => {
|
||||
let unix_time = SystemTime::now()
|
||||
|
@ -53,7 +53,7 @@ pub async fn handler(
|
||||
}
|
||||
}
|
||||
}
|
||||
s if s.contains("/here") => {
|
||||
s if s.contains("/here") || s.contains("@here") => {
|
||||
db::add_sentence(&message, mystem).await?;
|
||||
Here {
|
||||
data: "".to_string(),
|
||||
@ -118,9 +118,7 @@ pub async fn handler(
|
||||
.exec_mystem(&api, &message, mystem)
|
||||
.await?
|
||||
}
|
||||
_ => {
|
||||
db::add_sentence(&message, mystem).await?
|
||||
}
|
||||
_ => db::add_sentence(&message, mystem).await?,
|
||||
}
|
||||
}
|
||||
MessageKind::Photo { ref caption, .. } => {
|
||||
|
Reference in New Issue
Block a user