Some /code staff

This commit is contained in:
AB
2021-01-05 05:04:26 +03:00
parent ed32bd9195
commit 5528177e52
10 changed files with 1770 additions and 4947 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ memory.sqlite3
/video /video
/voice /voice
/.idea /.idea
Cargo.lock

3178
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,38 @@
[package] [package]
name = "desubot" name = "desubot"
version = "0.1.0" version = "0.1.0"
authors = ["AB <ab@hexor.ru>"] authors = ["AB <ab@hexor.ru>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bytes = "0.5" bytes = "0.5"
tokio = { version = "0.2", features = ["full"]} tokio = { version = "0.2", features = ["full"]}
tracing = "0.1.9" tracing = "0.1.9"
tracing-futures = "0.2" tracing-futures = "0.2"
multipart = { version = "0.16", default-features = false, features = ["client"] } multipart = { version = "0.16", default-features = false, features = ["client"] }
telegram-bot = "0.8.0" telegram-bot = "0.8.0"
silicon = "0.4.0" silicon = "0.4.0"
hyper = "0.13" hyper = "0.13"
hyper-tls = { version = "0.4", optional = true } hyper-tls = { version = "0.4", optional = true }
futures = "0.3" futures = "0.3"
hyper-rustls = { version = "0.19", optional = true } hyper-rustls = { version = "0.19", optional = true }
rusqlite = { version = "0.24.2", features = ["bundled"]} rusqlite = { version = "0.24.2", features = ["bundled"]}
html-escape = "0.2" html-escape = "0.2"
regex = "1" regex = "1"
reqwest = "0.10.9" reqwest = "0.10.9"
uuid = { version = "0.8", features = ["v4"] } uuid = { version = "0.8", features = ["v4"] }
sha1 = "*" sha1 = "*"
env_logger = "0.7" env_logger = "0.7"
log = { version = "^0.4.5", features = ["std"] } log = { version = "^0.4.5", features = ["std"] }
subprocess = "0.2.6" subprocess = "0.2.6"
serde_json = "1.0" serde_json = "1.0"
markov = "1.1.0" markov = "1.1.0"
rand = "0.7.3" rand = "0.7.3"
mystem = "0.2.1" mystem = "0.2.1"
async-trait = "0.1.42" async-trait = "0.1.42"
sqlparser = "0.7.0" sqlparser = "0.7.0"

View File

@ -1,3 +1,3 @@
# Assets # Assets
Silicon uses [bat](https://github.com/sharkdp/bat/tree/master/assets)'s syntax and theme resources. Silicon uses [bat](https://github.com/sharkdp/bat/tree/master/assets)'s syntax and theme resources.

View File

@ -1,21 +1,21 @@
#!/usr/bin/env python #!/usr/bin/env python
# Sync themes and syntaxes from [bat](https://github.com/sharkdp/bat/tree/master/assets) # Sync themes and syntaxes from [bat](https://github.com/sharkdp/bat/tree/master/assets)
import os import os
from glob import glob from glob import glob
from shutil import copy from shutil import copy
if not os.path.exists('../../bat'): if not os.path.exists('../../bat'):
os.system('git clone https://github.com/sharkdp/bat ../../bat') os.system('git clone https://github.com/sharkdp/bat ../../bat')
else: else:
os.system('git -C ../../bat pull') os.system('git -C ../../bat pull')
for syntax_file in glob('../../bat/assets/syntaxes/**/*.sublime-syntax'): for syntax_file in glob('../../bat/assets/syntaxes/**/*.sublime-syntax'):
copy(syntax_file, './syntaxes/') copy(syntax_file, './syntaxes/')
for theme_file in glob('../../bat/assets/themes/**/*.tmTheme'): for theme_file in glob('../../bat/assets/themes/**/*.tmTheme'):
copy(theme_file, './themes/') copy(theme_file, './themes/')
os.system('bat cache --build --source . --target .') os.system('bat cache --build --source . --target .')
print('Finished.') print('Finished.')

View File

@ -1,4 +1,4 @@
# Ignore everything in this directory # Ignore everything in this directory
* *
# Except this file # Except this file
!.gitignore !.gitignore

View File

@ -1,5 +1,5 @@
# Ignore everything in this directory # Ignore everything in this directory
* *
# Except this file # Except this file
!.gitignore !.gitignore
!Dracula.tmTheme !Dracula.tmTheme

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,184 +1,184 @@
//use crate::commands::Command; //use crate::commands::Command;
use crate::commands::{Code, Execute, Here, Markov, MarkovAll, Omedeto, Sql, Top}; use crate::commands::{Code, Execute, Here, Markov, MarkovAll, Omedeto, Sql, Top};
use crate::db; use crate::db;
use crate::errors; use crate::errors;
use crate::utils; use crate::utils;
use mystem::MyStem; use mystem::MyStem;
use telegram_bot::*; use telegram_bot::*;
pub async fn handler( pub async fn handler(
api: Api, api: Api,
message: Message, message: Message,
token: String, token: String,
mystem: &mut MyStem, mystem: &mut MyStem,
me: User, me: User,
) -> Result<(), errors::Error> { ) -> Result<(), errors::Error> {
match message.kind { match message.kind {
MessageKind::Text { ref data, .. } => { MessageKind::Text { ref data, .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: {}", "<{}({})>[{}({})]: {}",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
data data
); );
db::add_sentence(&message, mystem).await?; db::add_sentence(&message, mystem).await?;
let cleaned_message = data.replace(&format!("@{}", me.clone().username.unwrap()), ""); let cleaned_message = data.replace(&format!("@{}", me.clone().username.unwrap()), "");
match cleaned_message.as_str() { match cleaned_message.as_str() {
s if s.contains("/here") => { s if s.contains("/here") => {
Here { Here {
data: "".to_string(), data: "".to_string(),
} }
.exec(&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 ", ""),
} }
.exec_with_result(&api, &message) .exec_with_result(&api, &message)
.await .await
} { } {
Ok(msg) => { Ok(msg) => {
let _ = api let _ = api
.send( .send(
message message
.text_reply(msg) .text_reply(msg)
.parse_mode(ParseMode::Html), .parse_mode(ParseMode::Html),
) )
.await?; .await?;
}, },
Err(e) => { Err(e) => {
let _ = api let _ = api
.send( .send(
message message
.text_reply(format!("Error: {:#?}", e)) .text_reply(format!("Error: {:#?}", e))
.parse_mode(ParseMode::Html), .parse_mode(ParseMode::Html),
) )
.await?; .await?;
} }
}, },
s if s.to_string().starts_with("/code") => { s if s.to_string().starts_with("/code") => {
Code { Code {
data: s.to_string(), data: s.to_string(),
} }
.exec(&api, &message) .exec(&api, &message)
.await? .await?
} }
"/top" => { "/top" => {
Top { Top {
data: "".to_string(), data: "".to_string(),
} }
.exec(&api, &message) .exec(&api, &message)
.await? .await?
} }
"/stat" => { "/stat" => {
Top { Top {
data: "".to_string(), data: "".to_string(),
} }
.exec(&api, &message) .exec(&api, &message)
.await? .await?
} }
"/markov_all" => { "/markov_all" => {
MarkovAll { MarkovAll {
data: "".to_string(), data: "".to_string(),
} }
.exec(&api, &message) .exec(&api, &message)
.await? .await?
} }
"/markov" => { "/markov" => {
Markov { Markov {
data: "".to_string(), data: "".to_string(),
} }
.exec(&api, &message) .exec(&api, &message)
.await? .await?
} }
"/omedeto" => { "/omedeto" => {
Omedeto { Omedeto {
data: "".to_string(), data: "".to_string(),
} }
.exec_mystem(&api, &message, mystem) .exec_mystem(&api, &message, mystem)
.await? .await?
} }
_ => (), _ => (),
} }
} }
MessageKind::Photo { ref caption, .. } => { MessageKind::Photo { ref caption, .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *PHOTO* {}", "<{}({})>[{}({})]: *PHOTO* {}",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
caption.clone().unwrap_or("NO_TITLE".to_string()) caption.clone().unwrap_or("NO_TITLE".to_string())
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
MessageKind::Document { ref caption, .. } => { MessageKind::Document { ref caption, .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *DOCUMENT* {}", "<{}({})>[{}({})]: *DOCUMENT* {}",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
caption.clone().unwrap_or("NO_TITLE".to_string()) caption.clone().unwrap_or("NO_TITLE".to_string())
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
MessageKind::Sticker { .. } => { MessageKind::Sticker { .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *STICKER*", "<{}({})>[{}({})]: *STICKER*",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
MessageKind::Voice { .. } => { MessageKind::Voice { .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *VOICE*", "<{}({})>[{}({})]: *VOICE*",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
MessageKind::Video { .. } => { MessageKind::Video { .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *VIDEO*", "<{}({})>[{}({})]: *VIDEO*",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
MessageKind::VideoNote { .. } => { MessageKind::VideoNote { .. } => {
let title = utils::get_title(&message); let title = utils::get_title(&message);
info!( info!(
"<{}({})>[{}({})]: *VIDEO_NOTE*", "<{}({})>[{}({})]: *VIDEO_NOTE*",
&message.chat.id(), &message.chat.id(),
title, title,
&message.from.id, &message.from.id,
&message.from.first_name, &message.from.first_name,
); );
utils::get_files(api, message, token).await?; utils::get_files(api, message, token).await?;
} }
_ => (), _ => (),
}; };
Ok(()) Ok(())
} }