mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 13:04:06 +00:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
77dec205f1 | |||
6c761d7576 | |||
865fd3bbe4 | |||
30bdb23a32 | |||
f97562e9b7 | |||
2d000101c2 | |||
a26d227190 | |||
cc44f0e23b | |||
96df636195 | |||
a48e25800c | |||
36660d384d | |||
0d24976ec2 | |||
6ae3b2af1f | |||
a39f6a8c2a | |||
788c2cbbd4 | |||
9d5e5a3217 | |||
945da05794 |
27
.github/workflows/automerge.yml
vendored
Normal file
27
.github/workflows/automerge.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
name: automerge
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- labeled
|
||||
- unlabeled
|
||||
- synchronize
|
||||
- opened
|
||||
- edited
|
||||
- ready_for_review
|
||||
- reopened
|
||||
- unlocked
|
||||
pull_request_review:
|
||||
types:
|
||||
- submitted
|
||||
check_suite:
|
||||
types:
|
||||
- completed
|
||||
status: {}
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: automerge
|
||||
uses: "pascalgn/automerge-action@v0.13.0"
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "desubot"
|
||||
version = "0.5.0"
|
||||
version = "0.5.4"
|
||||
authors = ["AB <ab@hexor.ru>"]
|
||||
edition = "2018"
|
||||
|
||||
@ -30,7 +30,8 @@ subprocess = "0.2.6"
|
||||
serde_json = "1.0"
|
||||
markov = "1.1.0"
|
||||
rand = "0.7.3"
|
||||
mystem = "0.2.1"
|
||||
mystem = "^0.2"
|
||||
#mystem = { path = "../mystem-rs" }
|
||||
async-trait = "0.1.42"
|
||||
sqlparser = "0.7.0"
|
||||
|
||||
|
2
README
2
README
@ -7,8 +7,6 @@ Telegram bot with light group statistic and heavy spy features.
|
||||
* /here command to mention all members.
|
||||
* Alongside with saving whole message bot perform blacklist filter and stemming for every word (only Russian). "Красивую собаку мыли негры" -> "красивый собака мыть негр"
|
||||
* Generate sentences using Markov Chains trained on history with /markov_all.
|
||||
|
||||
== TODO ==
|
||||
* Syntax highlighting for CODE exported to image.
|
||||
|
||||
== Important ==
|
||||
|
@ -1,10 +1,10 @@
|
||||
static CODE: &str = "<b>Code highlighter</b>
|
||||
#[allow(dead_code)]
|
||||
static CODE_HELP: &str = "<b>Code highlighter</b>
|
||||
|
||||
<i>Usage</i>
|
||||
<pre>/CODE
|
||||
#<theme - Dracula by default>
|
||||
<pre>/code
|
||||
<CODE>
|
||||
#<lang - JS by default></pre>
|
||||
#<lang - JS by default> #<theme - Dracula by default></pre>
|
||||
|
||||
Language may be defined by both name and extension - Rust, rs...
|
||||
Max lines - 80
|
||||
@ -34,3 +34,10 @@ gruvbox-light
|
||||
gruvbox-white
|
||||
zenburn
|
||||
";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub static SQL_HELP: &str = "<b>Perform an SQL command</b>
|
||||
<i>* Only one sentence per message.
|
||||
* Only SELECT command.
|
||||
* Max result length is 100 lines. Use LIMIT 100.
|
||||
* SQLITE syntax is available only.</i>";
|
@ -17,11 +17,13 @@ use sqlparser::ast::Statement;
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
use sqlparser::parser::Parser;
|
||||
use syntect::easy::HighlightLines;
|
||||
use syntect::highlighting::Theme;
|
||||
use syntect::parsing::SyntaxReference;
|
||||
use syntect::util::LinesWithEndings;
|
||||
use telegram_bot::prelude::*;
|
||||
use telegram_bot::{Api, Message, ParseMode};
|
||||
use syntect::highlighting::Theme;
|
||||
|
||||
include!("../assets/help_text.rs");
|
||||
|
||||
pub struct Here {
|
||||
pub data: String,
|
||||
@ -65,6 +67,10 @@ impl Execute for Sql {
|
||||
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
let mut sql = self.data.clone();
|
||||
debug!("PIZDA - {}", sql);
|
||||
if sql == "/sql" || sql == "/sql-" {
|
||||
return Ok(SQL_HELP.to_string())
|
||||
}
|
||||
let is_head = if sql.starts_with('-') {
|
||||
sql = sql.replacen("-", "", 1);
|
||||
false
|
||||
@ -137,7 +143,7 @@ impl Execute for Sql {
|
||||
}
|
||||
res.push(tmp);
|
||||
}
|
||||
if res.len() > 100 {
|
||||
if res.len() >= 100 {
|
||||
return Err(Error::SQLResultTooLong(
|
||||
"SQL result too long. Lines limit is 100. Use LIMIT".to_string(),
|
||||
));
|
||||
@ -186,7 +192,7 @@ impl Execute for Sql {
|
||||
#[async_trait]
|
||||
impl Execute for Here {
|
||||
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(), 60).unwrap();
|
||||
for u in &members {
|
||||
debug!("Found user {:?} in chat {}", u, message.chat.id());
|
||||
}
|
||||
@ -551,7 +557,12 @@ impl Execute for Code {
|
||||
unimplemented!()
|
||||
}
|
||||
async fn exec_with_result(&self, api: &Api, message: &Message) -> Result<String, Error> {
|
||||
let mut lines: Vec<String> = self.data.trim().split("\n").map(|s| s.to_string()).collect();
|
||||
let mut lines: Vec<String> = self
|
||||
.data
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
if lines.len() >= 81 {
|
||||
return Err(CodeHighlightningError);
|
||||
}
|
||||
@ -593,7 +604,6 @@ impl Execute for Code {
|
||||
.map(|s| s.unwrap())
|
||||
.collect();
|
||||
|
||||
|
||||
let theme = if theme.len() != 1 {
|
||||
ts.themes.get("Dracula").unwrap()
|
||||
} else {
|
||||
@ -606,6 +616,7 @@ impl Execute for Code {
|
||||
.collect::<Vec<_>>();
|
||||
let formatter = silicon::formatter::ImageFormatterBuilder::<String>::new()
|
||||
.window_controls(false)
|
||||
.line_offset(1)
|
||||
.round_corner(false);
|
||||
let mut formatter = formatter.build().unwrap();
|
||||
let image = formatter.format(&highlight, &theme);
|
||||
|
30
src/db.rs
30
src/db.rs
@ -180,17 +180,27 @@ pub(crate) async fn get_messages_user_all(
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
pub(crate) fn get_members(id: telegram_bot::ChatId) -> Result<Vec<telegram_bot::User>> {
|
||||
pub(crate) fn get_members(id: telegram_bot::ChatId, limit: u32) -> Result<Vec<telegram_bot::User>> {
|
||||
let where_statement = if limit > 0 {
|
||||
format!("and days_seen <= {}", limit)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
debug!("{}", where_statement);
|
||||
let conn = open()?;
|
||||
let mut stmt = conn.prepare_cached(
|
||||
"
|
||||
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date
|
||||
&format!("
|
||||
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date,
|
||||
(strftime('%s','now')-r.date)/60/60/24 as days_seen
|
||||
FROM relations r
|
||||
JOIN user u
|
||||
ON u.id = r.user_id
|
||||
LEFT JOIN conf c
|
||||
ON r.conf_id = c.id
|
||||
WHERE c.id = :id",
|
||||
WHERE c.id = :id
|
||||
{}
|
||||
GROUP BY u.id
|
||||
ORDER BY r.date DESC", where_statement),
|
||||
)?;
|
||||
let mut rows = stmt.query_named(&[(":id", &id.to_string())])?;
|
||||
let mut users = Vec::new();
|
||||
@ -214,7 +224,7 @@ pub(crate) async fn add_conf(message: Message) -> Result<(), Error> {
|
||||
|
||||
match get_conf(message.chat.id()) {
|
||||
Ok(_) => {
|
||||
//info!("Group found: {:?}", message.chat.id());
|
||||
debug!("Group found: {:?}", message.chat.id());
|
||||
let update = Conf {
|
||||
id: message.chat.id(),
|
||||
title,
|
||||
@ -228,10 +238,10 @@ pub(crate) async fn add_conf(message: Message) -> Result<(), Error> {
|
||||
id = :id",
|
||||
)?;
|
||||
stmt.execute_named(&[(":id", &update.id.to_string()), (":title", &update.title)])?;
|
||||
//info!("Conf {:?} updated: {:?}", update.title, get_conf(update.id));
|
||||
debug!("Conf {:?} updated: {:?}", update.title, get_conf(update.id));
|
||||
}
|
||||
Err(_) => {
|
||||
//info!("Group didn't found: {:?}", message.chat.id());
|
||||
debug!("Group didn't found: {:?}", message.chat.id());
|
||||
|
||||
let update = Conf {
|
||||
id: message.chat.id(),
|
||||
@ -250,7 +260,7 @@ pub(crate) async fn add_conf(message: Message) -> Result<(), Error> {
|
||||
(":title", &update.title),
|
||||
(":date", &unix_time),
|
||||
])?;
|
||||
//info!("Conf {:?} added: {:?}", update.title, get_conf(update.id));
|
||||
debug!("Conf {:?} added: {:?}", update.title, get_conf(update.id));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@ -283,7 +293,7 @@ pub(crate) async fn add_user(message: Message) -> Result<(), Error> {
|
||||
(":first_name", &update.first_name),
|
||||
(":last_name", &update.last_name),
|
||||
])?;
|
||||
//println!("User {} updated: {:?}", update.first_name, get_user(user.id));
|
||||
debug!("User {} updated: {:?}", update.first_name, get_user(update.id));
|
||||
}
|
||||
Err(_) => {
|
||||
let unix_time = SystemTime::now()
|
||||
@ -310,7 +320,7 @@ pub(crate) async fn add_user(message: Message) -> Result<(), Error> {
|
||||
(":last_name", &user.last_name),
|
||||
(":date", &unix_time),
|
||||
])?;
|
||||
//println!("User added: {:?}", user);
|
||||
debug!("User added: {:?}", user);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -6,7 +6,6 @@ use crate::utils;
|
||||
use mystem::MyStem;
|
||||
use telegram_bot::*;
|
||||
|
||||
|
||||
include!("../assets/help_text.rs");
|
||||
|
||||
pub async fn handler(
|
||||
@ -25,13 +24,12 @@ pub async fn handler(
|
||||
title,
|
||||
&message.from.id,
|
||||
&message.from.first_name,
|
||||
{if data.len() <= 200 {data} else {&data[..200]}}.replace("\n", " ")
|
||||
data.replace("\n", " ")
|
||||
);
|
||||
|
||||
let cleaned_message = data.replace(&format!("@{}", me.clone().username.unwrap()), "");
|
||||
match cleaned_message.as_str() {
|
||||
s if s.to_string().starts_with("/code") => {
|
||||
|
||||
match {
|
||||
Code {
|
||||
data: s.replace("/code", ""),
|
||||
@ -50,12 +48,12 @@ pub async fn handler(
|
||||
}
|
||||
Err(_) => {
|
||||
let _ = api
|
||||
.send(message.text_reply(CODE).parse_mode(ParseMode::Html))
|
||||
.send(message.text_reply(CODE_HELP).parse_mode(ParseMode::Html))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
s if s.contains("/here") => {
|
||||
s if s.contains("/here") || s.contains("@here") => {
|
||||
db::add_sentence(&message, mystem).await?;
|
||||
Here {
|
||||
data: "".to_string(),
|
||||
@ -120,7 +118,9 @@ pub async fn handler(
|
||||
.exec_mystem(&api, &message, mystem)
|
||||
.await?
|
||||
}
|
||||
_ => db::add_sentence(&message, mystem).await?,
|
||||
_ => {
|
||||
db::add_sentence(&message, mystem).await?
|
||||
}
|
||||
}
|
||||
}
|
||||
MessageKind::Photo { ref caption, .. } => {
|
||||
|
Reference in New Issue
Block a user