mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 13:04:06 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
77dec205f1 | |||
6c761d7576 | |||
865fd3bbe4 | |||
30bdb23a32 | |||
f97562e9b7 | |||
2d000101c2 | |||
a26d227190 | |||
cc44f0e23b | |||
96df636195 | |||
a48e25800c | |||
36660d384d | |||
788c2cbbd4 | |||
9d5e5a3217 | |||
945da05794 | |||
3085d4c450 |
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 }}"
|
80
Cargo.toml
80
Cargo.toml
@ -1,41 +1,41 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "desubot"
|
name = "desubot"
|
||||||
version = "0.5.1"
|
version = "0.5.4"
|
||||||
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 = "0.6.0"
|
sha1 = "0.6.0"
|
||||||
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"
|
mystem = "^0.2"
|
||||||
#mystem = { path = "../mystem-rs" }
|
#mystem = { path = "../mystem-rs" }
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
sqlparser = "0.7.0"
|
sqlparser = "0.7.0"
|
||||||
|
|
||||||
[dependencies.syntect]
|
[dependencies.syntect]
|
||||||
version = "4.4"
|
version = "4.4"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["parsing", "dump-load", "regex-onig"]
|
features = ["parsing", "dump-load", "regex-onig"]
|
4
README
4
README
@ -7,10 +7,8 @@ Telegram bot with light group statistic and heavy spy features.
|
|||||||
* /here command to mention all members.
|
* /here command to mention all members.
|
||||||
* Alongside with saving whole message bot perform blacklist filter and stemming for every word (only Russian). "Красивую собаку мыли негры" -> "красивый собака мыть негр"
|
* 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.
|
* Generate sentences using Markov Chains trained on history with /markov_all.
|
||||||
|
|
||||||
== TODO ==
|
|
||||||
* Syntax highlighting for CODE exported to image.
|
* Syntax highlighting for CODE exported to image.
|
||||||
|
|
||||||
== Important ==
|
== Important ==
|
||||||
* Desubot uses MyStem by Yandex for word stemming and assume that mystem binary is available in PATH.
|
* Desubot uses MyStem by Yandex for word stemming and assume that mystem binary is available in PATH.
|
||||||
On Windows it may be placed on working directory. Both Linux and Windows mystem binary is in repo.
|
On Windows it may be placed on working directory. Both Linux and Windows mystem binary is in repo.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
static CODE_HELP: &str = "<b>Code highlighter</b>
|
static CODE_HELP: &str = "<b>Code highlighter</b>
|
||||||
|
|
||||||
<i>Usage</i>
|
<i>Usage</i>
|
||||||
<pre>/CODE
|
<pre>/code
|
||||||
<CODE>
|
<CODE>
|
||||||
#<lang - JS by default> #<theme - Dracula by default></pre>
|
#<lang - JS by default> #<theme - Dracula by default></pre>
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ impl Execute for Sql {
|
|||||||
}
|
}
|
||||||
res.push(tmp);
|
res.push(tmp);
|
||||||
}
|
}
|
||||||
if res.len() > 100 {
|
if res.len() >= 100 {
|
||||||
return Err(Error::SQLResultTooLong(
|
return Err(Error::SQLResultTooLong(
|
||||||
"SQL result too long. Lines limit is 100. Use LIMIT".to_string(),
|
"SQL result too long. Lines limit is 100. Use LIMIT".to_string(),
|
||||||
));
|
));
|
||||||
@ -192,7 +192,7 @@ impl Execute for Sql {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Execute for Here {
|
impl Execute for Here {
|
||||||
async fn exec(&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(), 60).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());
|
||||||
}
|
}
|
||||||
|
30
src/db.rs
30
src/db.rs
@ -180,17 +180,27 @@ pub(crate) async fn get_messages_user_all(
|
|||||||
Ok(messages)
|
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 conn = open()?;
|
||||||
let mut stmt = conn.prepare_cached(
|
let mut stmt = conn.prepare_cached(
|
||||||
"
|
&format!("
|
||||||
SELECT DISTINCT(u.username), u.id, u.first_name, u.last_name, u.date
|
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
|
FROM relations r
|
||||||
JOIN user u
|
JOIN user u
|
||||||
ON u.id = r.user_id
|
ON u.id = r.user_id
|
||||||
LEFT JOIN conf c
|
LEFT JOIN conf c
|
||||||
ON r.conf_id = c.id
|
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 rows = stmt.query_named(&[(":id", &id.to_string())])?;
|
||||||
let mut users = Vec::new();
|
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()) {
|
match get_conf(message.chat.id()) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
//info!("Group found: {:?}", message.chat.id());
|
debug!("Group found: {:?}", message.chat.id());
|
||||||
let update = Conf {
|
let update = Conf {
|
||||||
id: message.chat.id(),
|
id: message.chat.id(),
|
||||||
title,
|
title,
|
||||||
@ -228,10 +238,10 @@ pub(crate) async fn add_conf(message: Message) -> Result<(), Error> {
|
|||||||
id = :id",
|
id = :id",
|
||||||
)?;
|
)?;
|
||||||
stmt.execute_named(&[(":id", &update.id.to_string()), (":title", &update.title)])?;
|
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(_) => {
|
Err(_) => {
|
||||||
//info!("Group didn't found: {:?}", message.chat.id());
|
debug!("Group didn't found: {:?}", message.chat.id());
|
||||||
|
|
||||||
let update = Conf {
|
let update = Conf {
|
||||||
id: message.chat.id(),
|
id: message.chat.id(),
|
||||||
@ -250,7 +260,7 @@ pub(crate) async fn add_conf(message: Message) -> Result<(), Error> {
|
|||||||
(":title", &update.title),
|
(":title", &update.title),
|
||||||
(":date", &unix_time),
|
(":date", &unix_time),
|
||||||
])?;
|
])?;
|
||||||
//info!("Conf {:?} added: {:?}", update.title, get_conf(update.id));
|
debug!("Conf {:?} added: {:?}", update.title, get_conf(update.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -283,7 +293,7 @@ pub(crate) async fn add_user(message: Message) -> Result<(), Error> {
|
|||||||
(":first_name", &update.first_name),
|
(":first_name", &update.first_name),
|
||||||
(":last_name", &update.last_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(_) => {
|
Err(_) => {
|
||||||
let unix_time = SystemTime::now()
|
let unix_time = SystemTime::now()
|
||||||
@ -310,7 +320,7 @@ pub(crate) async fn add_user(message: Message) -> Result<(), Error> {
|
|||||||
(":last_name", &user.last_name),
|
(":last_name", &user.last_name),
|
||||||
(":date", &unix_time),
|
(":date", &unix_time),
|
||||||
])?;
|
])?;
|
||||||
//println!("User added: {:?}", user);
|
debug!("User added: {:?}", user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -53,7 +53,7 @@ pub async fn handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s if s.contains("/here") => {
|
s if s.contains("/here") || s.contains("@here") => {
|
||||||
db::add_sentence(&message, mystem).await?;
|
db::add_sentence(&message, mystem).await?;
|
||||||
Here {
|
Here {
|
||||||
data: "".to_string(),
|
data: "".to_string(),
|
||||||
|
Reference in New Issue
Block a user