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
/voice
/.idea
Cargo.lock

3178
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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