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