mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 13:04:06 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
d5b30cc94e | |||
ea6d9b55a1 | |||
c8c55782ec | |||
ed68dbd4bd | |||
5a41d4a0b9 |
2057
Cargo.lock
generated
2057
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,6 @@
|
||||
#![allow(unused_variables)]
|
||||
use crate::db;
|
||||
use crate::errors::Error;
|
||||
use crate::errors::Error::{SQLITE3Error, SQLInvalidCommand};
|
||||
use crate::errors::Error::{SQLInvalidCommand, SQLITE3Error};
|
||||
use async_trait::async_trait;
|
||||
use html_escape::encode_text;
|
||||
use markov::Chain;
|
||||
@ -40,9 +39,8 @@ pub struct Sql {
|
||||
|
||||
#[async_trait]
|
||||
pub trait Execute {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error>;
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error>;
|
||||
async fn exec_mystem(
|
||||
async fn run(&self, api: &Api, message: &Message) -> Result<(), Error>;
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -52,12 +50,8 @@ pub trait Execute {
|
||||
|
||||
#[async_trait]
|
||||
impl Execute for Sql {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
let mut sql = self.data.clone();
|
||||
async fn run(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
let mut sql = self.data.to_uppercase();
|
||||
let is_head = if sql.starts_with('-') {
|
||||
sql = sql.replacen("-", "", 1);
|
||||
false
|
||||
@ -94,7 +88,7 @@ impl Execute for Sql {
|
||||
|
||||
let mut rows = match stmt.query(rusqlite::NO_PARAMS) {
|
||||
Err(e) => return Err(SQLITE3Error(e)),
|
||||
Ok(rows) => rows,
|
||||
Ok(mut rows) => rows,
|
||||
};
|
||||
|
||||
let mut res: Vec<Vec<String>> = match rows.column_names() {
|
||||
@ -162,11 +156,11 @@ impl Execute for Sql {
|
||||
} else {
|
||||
msg
|
||||
};
|
||||
Ok(msg)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -178,7 +172,7 @@ impl Execute for Sql {
|
||||
|
||||
#[async_trait]
|
||||
impl Execute for Here {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
async fn run(&self, 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 {:?} in chat {}", u, message.chat.id());
|
||||
@ -206,12 +200,8 @@ impl Execute for Here {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -223,7 +213,7 @@ impl Execute for Here {
|
||||
|
||||
#[async_trait]
|
||||
impl Execute for Top {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
async fn run(&self, 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;
|
||||
@ -245,12 +235,8 @@ impl Execute for Top {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -262,7 +248,7 @@ impl Execute for Top {
|
||||
|
||||
#[async_trait]
|
||||
impl Execute for MarkovAll {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
async fn run(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
let messages = db::get_messages_random_all().await?;
|
||||
let mut chain = Chain::new();
|
||||
chain.feed(messages);
|
||||
@ -283,12 +269,8 @@ impl Execute for MarkovAll {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -300,7 +282,7 @@ impl Execute for MarkovAll {
|
||||
|
||||
#[async_trait]
|
||||
impl Execute for Markov {
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
async fn run(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
let messages = db::get_messages_random_group(&message).await?;
|
||||
let mut chain = Chain::new();
|
||||
chain.feed(messages);
|
||||
@ -321,12 +303,8 @@ impl Execute for Markov {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
@ -339,16 +317,12 @@ impl Execute for Markov {
|
||||
#[async_trait]
|
||||
impl Execute for Omedeto {
|
||||
#[allow(unused_variables)]
|
||||
async fn exec(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
async fn run(&self, api: &Api, message: &Message) -> Result<(), Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[warn(unused_must_use)]
|
||||
async fn exec_mystem(
|
||||
async fn run_mystem(
|
||||
&self,
|
||||
api: &Api,
|
||||
message: &Message,
|
||||
|
@ -31,68 +31,60 @@ pub async fn handler(
|
||||
Here {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await?
|
||||
}
|
||||
s if s.to_string().starts_with("/sql") => match {
|
||||
Sql {
|
||||
data: s.replace("/sql ", ""),
|
||||
}
|
||||
.exec_with_result(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await
|
||||
} {
|
||||
Ok(msg) => {
|
||||
let _ = api
|
||||
.send(
|
||||
message
|
||||
.text_reply(msg)
|
||||
.parse_mode(ParseMode::Html),
|
||||
)
|
||||
.await?;
|
||||
},
|
||||
Ok(_) => debug!("/sql command sent to {}", message.chat.id()),
|
||||
Err(e) => {
|
||||
let _ = api
|
||||
.send(
|
||||
api.send(
|
||||
message
|
||||
.text_reply(format!("Error: {:#?}", e))
|
||||
.parse_mode(ParseMode::Html),
|
||||
)
|
||||
.await?;
|
||||
()
|
||||
}
|
||||
},
|
||||
"/top" => {
|
||||
Top {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await?
|
||||
}
|
||||
"/stat" => {
|
||||
Top {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await?
|
||||
}
|
||||
"/markov_all" => {
|
||||
MarkovAll {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await?
|
||||
}
|
||||
"/markov" => {
|
||||
Markov {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec(&api, &message)
|
||||
.run(&api, &message)
|
||||
.await?
|
||||
}
|
||||
"/omedeto" => {
|
||||
Omedeto {
|
||||
data: "".to_string(),
|
||||
}
|
||||
.exec_mystem(&api, &message, mystem)
|
||||
.run_mystem(&api, &message, mystem)
|
||||
.await?
|
||||
}
|
||||
_ => (),
|
||||
|
Reference in New Issue
Block a user