4 Commits
0.5.2 ... 0.5.4

Author SHA1 Message Date
AB
77dec205f1 Bump version. 2021-01-20 20:16:08 +03:00
AB
6c761d7576 @here command now call only active users (at least 1 message in last 60 days) 2021-01-20 20:15:46 +03:00
AB
865fd3bbe4 Bump 2021-01-20 15:54:05 +03:00
AB
30bdb23a32 Add @here command 2021-01-20 15:53:22 +03:00
4 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "desubot"
version = "0.5.1"
version = "0.5.4"
authors = ["AB <ab@hexor.ru>"]
edition = "2018"

View File

@ -192,7 +192,7 @@ 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();
for u in &members {
debug!("Found user {:?} in chat {}", u, message.chat.id());
}

View File

@ -180,17 +180,27 @@ 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(
"
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date
&format!("
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();

View File

@ -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(),