mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 13:04:06 +00:00
Add top.
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
use crate::db;
|
||||
use html_escape::encode_text;
|
||||
use telegram_bot::prelude::*;
|
||||
use telegram_bot::{Api, Error, Message, ParseMode, };
|
||||
use telegram_bot::{Api, Message, ParseMode};
|
||||
use crate::errors::Error;
|
||||
|
||||
pub(crate) async fn here(api: Api, message: Message) -> Result<(), Error> {
|
||||
let members: Vec<telegram_bot::User> = db::get_members(message.chat.id()).unwrap();
|
||||
for u in &members {
|
||||
debug!("Found user {:?}", u);
|
||||
debug!("Found user {:?} in chat {}", u, message.chat.id());
|
||||
}
|
||||
let mut msg = "<b>I summon you</b>, ".to_string();
|
||||
for user in members {
|
||||
@ -25,10 +26,30 @@ pub(crate) async fn here(api: Api, message: Message) -> Result<(), Error> {
|
||||
.send(message.text_reply(msg).parse_mode(ParseMode::Html))
|
||||
.await
|
||||
{
|
||||
Ok(_) => debug!("@here command sent to {}", message.from.id),
|
||||
Err(_) => warn!("@here command sent failed to {}", message.from.id),
|
||||
Ok(_) => debug!("/here command sent to {}", message.chat.id()),
|
||||
Err(_) => warn!("/here command sent failed to {}", message.chat.id()),
|
||||
}
|
||||
//api.send(message.chat.text("Text to message chat")).await?;
|
||||
//api.send(message.from.text("Private text")).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn top(api: Api, message: Message) -> Result<(), Error> {
|
||||
let top = db::get_top(&message).await?;
|
||||
let mut msg = "<b>Your top using words:</b>\n<pre>".to_string();
|
||||
let mut counter = 1;
|
||||
for word in top.iter() {
|
||||
msg = format!("{} <b>{}</b> {} - {}\n", msg, counter, word.word, word.count);
|
||||
counter += 1;
|
||||
}
|
||||
msg = format!("{}{}", msg, "</pre>");
|
||||
match api
|
||||
.send(message.text_reply(msg).parse_mode(ParseMode::Html))
|
||||
.await
|
||||
{
|
||||
Ok(_) => debug!("/top command sent to {}", message.chat.id()),
|
||||
Err(_) => warn!("/top command sent failed to {}", message.chat.id()),
|
||||
}
|
||||
//api.send(message.chat.text("Text to message chat")).await?;
|
||||
//api.send(message.from.text("Private text")).await?;
|
||||
Ok(())}
|
||||
|
Reference in New Issue
Block a user