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 | |
---|---|---|---|
2fb5b03fbf | |||
55a7dd6a67 | |||
ff6e04988e | |||
7c067065bd | |||
175f056add |
@ -15,6 +15,10 @@ Telegram bot with light group statistic and heavy spy features.
|
|||||||
* Desubot uses MyStem by Yandex for word stemming and assume that mystem binary is available in PATH.
|
* Desubot uses MyStem by Yandex for word stemming and assume that mystem binary is available in PATH.
|
||||||
* ubuntu deps: libssl-dev libsqlite3-dev cmake libfreetype-dev
|
* ubuntu deps: libssl-dev libsqlite3-dev cmake libfreetype-dev
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## License
|
## License
|
||||||
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot?ref=badge_large)
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot?ref=badge_large)
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
т
|
т
|
||||||
у
|
у
|
||||||
я
|
я
|
||||||
|
чо
|
||||||
|
че
|
||||||
|
ща
|
||||||
|
ваще
|
||||||
бы
|
бы
|
||||||
stat
|
stat
|
||||||
вообще
|
вообще
|
||||||
|
@ -32,6 +32,12 @@ pub struct Here {
|
|||||||
pub struct Top {
|
pub struct Top {
|
||||||
pub data: String,
|
pub data: String,
|
||||||
}
|
}
|
||||||
|
pub struct ConfTop {
|
||||||
|
pub data: String,
|
||||||
|
}
|
||||||
|
pub struct GlobalTop {
|
||||||
|
pub data: String,
|
||||||
|
}
|
||||||
pub struct MarkovAll {
|
pub struct MarkovAll {
|
||||||
pub data: String,
|
pub data: String,
|
||||||
}
|
}
|
||||||
@ -347,6 +353,84 @@ impl Execute for Top {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Execute for GlobalTop {
|
||||||
|
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||||
|
let top = db::get_global_top().await?;
|
||||||
|
let mut msg = "<b>Global top 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!("/global_top command sent to {}", message.chat.id()),
|
||||||
|
Err(_) => warn!("/global_top command sent failed to {}", message.chat.id()),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
async fn exec_mystem(
|
||||||
|
&self,
|
||||||
|
api: &Api,
|
||||||
|
message: &Message,
|
||||||
|
mystem: &mut MyStem,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Execute for ConfTop {
|
||||||
|
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||||
|
let top = db::get_conf_top(&message).await?;
|
||||||
|
let mut msg = "<b>Conf top 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!("/conf_top command sent to {}", message.chat.id()),
|
||||||
|
Err(_) => warn!("/conf_top command sent failed to {}", message.chat.id()),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
async fn exec_mystem(
|
||||||
|
&self,
|
||||||
|
api: &Api,
|
||||||
|
message: &Message,
|
||||||
|
mystem: &mut MyStem,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Execute for MarkovAll {
|
impl Execute for MarkovAll {
|
||||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||||
@ -676,7 +760,7 @@ impl Execute for Code {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let theme = if theme.len() != 1 {
|
let theme = if theme.len() != 1 {
|
||||||
ts.themes.get("Dracula").unwrap()
|
ts.themes.get("gruvbox").unwrap()
|
||||||
} else {
|
} else {
|
||||||
theme[0]
|
theme[0]
|
||||||
};
|
};
|
||||||
|
53
src/db.rs
53
src/db.rs
@ -512,3 +512,56 @@ pub(crate) async fn get_top(
|
|||||||
}
|
}
|
||||||
Ok(top)
|
Ok(top)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_global_top() -> Result<Vec<TopWord>, errors::Error> {
|
||||||
|
let conn = open()?;
|
||||||
|
let mut stmt = conn.prepare_cached(
|
||||||
|
"
|
||||||
|
SELECT w.word, COUNT(*) as count FROM relations r
|
||||||
|
LEFT JOIN word w ON w.id = r.word_id
|
||||||
|
GROUP BY w.word
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT 50
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let mut rows = stmt.query_named(named_params! {})?;
|
||||||
|
let mut top = Vec::new();
|
||||||
|
|
||||||
|
while let Some(row) = rows.next()? {
|
||||||
|
top.push(TopWord {
|
||||||
|
word: row.get(0)?,
|
||||||
|
count: row.get(1)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Ok(top)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_conf_top(
|
||||||
|
message: &telegram_bot::Message,
|
||||||
|
) -> Result<Vec<TopWord>, errors::Error> {
|
||||||
|
let conf_id = i64::from(message.chat.id());
|
||||||
|
|
||||||
|
let conn = open()?;
|
||||||
|
let mut stmt = conn.prepare_cached(
|
||||||
|
"
|
||||||
|
SELECT w.word, COUNT(*) as count FROM relations r
|
||||||
|
LEFT JOIN word w ON w.id = r.word_id
|
||||||
|
WHERE r.conf_id = :conf_id
|
||||||
|
GROUP BY w.word
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT 10
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let mut rows = stmt.query_named(named_params! {":conf_id": conf_id})?;
|
||||||
|
let mut top = Vec::new();
|
||||||
|
|
||||||
|
while let Some(row) = rows.next()? {
|
||||||
|
top.push(TopWord {
|
||||||
|
word: row.get(0)?,
|
||||||
|
count: row.get(1)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Ok(top)
|
||||||
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//use crate::commands::Command;
|
//use crate::commands::Command;
|
||||||
use crate::commands::{Code, Execute, Here, Markov, MarkovAll, Omedeto, Scheme, Sql, Top};
|
use crate::commands::{
|
||||||
|
Code, ConfTop, Execute, GlobalTop, Here, Markov, MarkovAll, Omedeto, Scheme, Sql, Top,
|
||||||
|
};
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
@ -76,6 +78,8 @@ pub async fn handler(
|
|||||||
|| s.contains("@here")
|
|| s.contains("@here")
|
||||||
|| s.contains("/хере")
|
|| s.contains("/хере")
|
||||||
|| s.contains("@хере")
|
|| s.contains("@хере")
|
||||||
|
|| s.contains("@all")
|
||||||
|
|| s.contains("\"руку")
|
||||||
|| s.contains("\"хере") =>
|
|| s.contains("\"хере") =>
|
||||||
{
|
{
|
||||||
db::add_sentence(&message, mystem).await?;
|
db::add_sentence(&message, mystem).await?;
|
||||||
@ -107,15 +111,22 @@ pub async fn handler(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/top" => {
|
"/top" | "/stat" => {
|
||||||
Top {
|
Top {
|
||||||
data: "".to_string(),
|
data: "".to_string(),
|
||||||
}
|
}
|
||||||
.exec(&api, &message)
|
.exec(&api, &message)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
"/stat" => {
|
"/global_top" | "/global_stat" => {
|
||||||
Top {
|
GlobalTop {
|
||||||
|
data: "".to_string(),
|
||||||
|
}
|
||||||
|
.exec(&api, &message)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
"/conf_stat" | "/conf_top" => {
|
||||||
|
ConfTop {
|
||||||
data: "".to_string(),
|
data: "".to_string(),
|
||||||
}
|
}
|
||||||
.exec(&api, &message)
|
.exec(&api, &message)
|
||||||
|
Reference in New Issue
Block a user