101 Commits
0.3 ... main

Author SHA1 Message Date
739109e5f7 pux
Some checks failed
Build / build-windows (push) Has been cancelled
Build / build-linux (push) Has been cancelled
2024-10-17 21:15:33 +03:00
4ac7920815 bump rand 2024-10-17 21:04:04 +03:00
47f1ab9348 Fux 2024-10-17 20:58:09 +03:00
28cdf4be2e Fixing shit 2024-10-17 20:55:41 +03:00
0bcb99089b Update README.md
Some checks failed
Build / build-windows (push) Has been cancelled
Build / build-linux (push) Has been cancelled
2024-08-21 15:51:20 +03:00
0bba91486e Fix ci
Some checks failed
Build / build-windows (push) Has been cancelled
Build / build-linux (push) Has been cancelled
2024-08-07 20:10:49 +03:00
207717491c Fix docker build
Some checks failed
Build / build-linux (push) Failing after 31s
Build / build-windows (push) Has been cancelled
2024-08-05 17:18:15 +03:00
f185c31a17 Fix docker build 2024-08-05 17:14:00 +03:00
aeacc15439 Fix docker build 2024-08-05 17:07:38 +03:00
ccf54bc279 Fix docker build 2024-08-05 16:51:59 +03:00
AB
e07f173b7c Fix CI
Some checks are pending
Build / build-windows (push) Waiting to run
Build / build-linux (push) Waiting to run
2024-08-04 23:34:19 +03:00
AB
bcd869273d Fix CI 2024-08-04 23:17:56 +03:00
AB
1ee12fa0c0 Fix CI 2024-08-04 23:14:59 +03:00
76dab182cf pin docker ubuntu version 2024-08-04 23:05:07 +03:00
bacdf559c4 Fix /markov in private chats 2023-07-24 14:38:19 +03:00
82a81fffb6 Rebuild new docker 2023-07-01 04:28:04 +03:00
392669703d Update README.md 2022-12-16 12:29:50 +02:00
2fb5b03fbf Add global, conf stat. 2022-11-23 17:53:56 +02:00
55a7dd6a67 add @all command 2022-11-03 19:01:17 +02:00
AB
ff6e04988e Merge branch 'main' of https://github.com/house-of-vanity/desubot into main 2022-05-05 12:25:10 +03:00
AB
7c067065bd add a few stop words 2022-05-05 12:24:38 +03:00
175f056add Update README.md 2022-01-23 15:09:05 +03:00
AB
20f366572b Add scheme. 2022-01-23 15:02:21 +03:00
e5079fa584 Update db.rs 2021-12-08 17:51:32 +03:00
fdc52b7198 Update README.md
Add deps
2021-12-08 17:46:33 +03:00
AB
789b918bab Add stop-wards logic 2021-08-29 13:35:44 +03:00
AB
66a93e85b8 Add stop-wards logic 2021-08-29 13:35:29 +03:00
AB
e13a2688ab Merge branch 'main' of github.com:house-of-vanity/desubot 2021-08-29 13:34:30 +03:00
AB
04220703a3 Add stop-wards logic 2021-08-29 13:34:17 +03:00
9518ffd69b Rename README to README.md 2021-08-24 13:17:12 +03:00
5a6cb37ebb Fix CI 2021-08-24 12:59:51 +03:00
6c2837a76f Fix CI 2021-08-24 00:30:27 +03:00
d97eaf4284 Fix CI 2021-08-24 00:06:55 +03:00
AB
e7e0c6923e Fix WF 2021-08-23 01:25:01 +03:00
AB
382cc56492 docker build 2021-08-23 01:16:27 +03:00
6f48f116c9 Merge pull request #15 from house-of-vanity/add-docker-k8s
Add k8s deploy example
2021-08-22 15:07:06 -07:00
AB
282efe5be4 Add k8s deploy example 2021-08-23 01:06:11 +03:00
4175fe9029 Merge pull request #14 from house-of-vanity/add-docker-k8s
Add Dockerfile.
2021-08-22 14:59:22 -07:00
AB
f1dc1d0897 Add Dockerfile. 2021-08-23 00:58:25 +03:00
d5879a82b6 Merge pull request #13 from house-of-vanity/libs-bump
Update telegram-bot for a new UpdateKind
2021-08-20 12:24:53 -07:00
456c887a53 Merge pull request #11 from fossabot/add-license-scan-badge
Add license scan report and status
2021-08-20 11:25:12 -07:00
AB
d8b37b32df Bump version 2021-08-20 21:22:43 +03:00
AB
47c68ee432 Update telegram-bot for a new UPDATEKU 2021-08-20 20:38:13 +03:00
da53927288 Merge pull request #12 from house-of-vanity/libs-bump
Libs bump
2021-08-19 08:42:00 -07:00
AB
ac2be9929a Rollback tokio 2021-08-19 18:40:12 +03:00
7432ce6398 Bump many libs 2021-08-19 18:08:19 +03:00
049a3c4987 Add license scan report and status
Signed off by: fossabot <badges@fossa.com>
2021-06-15 15:54:38 -07:00
AB
0831e3f503 Add хере command. 2021-06-12 15:02:09 +03:00
AB
a0f4c40be0 Add хере command. 2021-06-12 14:58:38 +03:00
AB
1facef6897 Add debug message. 2021-04-04 22:35:33 +03:00
AB
428416a2a3 Add handler in case of error in here command. 2021-03-10 19:57:45 +03:00
AB
77dec205f1 Bump version. 2021-01-20 20:16:08 +03:00
AB
6c761d7576 @here command now call only active users (at least 1 message in last 60 days) 2021-01-20 20:15:46 +03:00
AB
865fd3bbe4 Bump 2021-01-20 15:54:05 +03:00
AB
30bdb23a32 Add @here command 2021-01-20 15:53:22 +03:00
AB
f97562e9b7 Merge remote-tracking branch 'origin/main' into main 2021-01-11 11:39:34 +03:00
AB
2d000101c2 Merge 2021-01-11 11:39:20 +03:00
a26d227190 Merge pull request #10 from house-of-vanity/code
code
2021-01-11 11:26:51 +03:00
AB
cc44f0e23b Merge remote-tracking branch 'origin/main' into main
# Conflicts:
#	assets/help_text.rs
2021-01-11 11:22:47 +03:00
AB
96df636195 Add automerge action. 2021-01-11 11:21:18 +03:00
AB
a48e25800c Improve logging. Fix /sql limit. 2021-01-11 11:12:38 +03:00
36660d384d Merge pull request #9 from house-of-vanity/code
Code
2021-01-10 21:39:38 +03:00
AB
0d24976ec2 Fix warnings. Bump version. 2021-01-10 21:38:18 +03:00
AB
6ae3b2af1f Fix warnings. 2021-01-10 21:22:27 +03:00
AB
a39f6a8c2a Update /code feature. 2021-01-10 21:21:07 +03:00
AB
788c2cbbd4 Fix type in help. 2021-01-09 01:06:10 +03:00
AB
9d5e5a3217 Fix type in help. 2021-01-08 17:54:05 +03:00
945da05794 Update README 2021-01-08 06:42:32 -08:00
3085d4c450 Merge pull request #8 from house-of-vanity/code
Code
2021-01-08 17:38:56 +03:00
AB
4b142ae8ef Add /code feature. 2021-01-08 17:32:39 +03:00
AB
8f3cccf01d Trying to fix clippy. doesn't work. 2021-01-05 14:56:31 +03:00
AB
3136bce84f Clippy lint 2021-01-05 05:17:22 +03:00
AB
e09047bb5b Simple lint 2021-01-05 05:14:44 +03:00
AB
5528177e52 Some /code staff 2021-01-05 05:04:26 +03:00
AB
ed32bd9195 Merge 2021-01-05 05:01:34 +03:00
AB
d14aa3beb4 Rebase 2021-01-05 04:39:32 +03:00
43e4f26af1 Merge pull request #7 from house-of-vanity/sql
Sql
2021-01-05 04:31:21 +03:00
AB
5d8d3441d2 Fix /sql command a lot. 2021-01-05 04:30:28 +03:00
AB
34fa54e6f4 add lock file. 2021-01-05 03:58:36 +03:00
d5b30cc94e Merge pull request #6 from house-of-vanity/sql
Simplify SQL command. Add limit.
2021-01-05 03:46:03 +03:00
7a66034381 Update handlers.rs 2021-01-04 16:40:46 -08:00
AB
47906fe22d Simplify SQL command. Add limit. 2021-01-05 03:30:21 +03:00
ea6d9b55a1 Merge pull request #5 from house-of-vanity/matching_commands
Fix typo.
2021-01-05 01:44:09 +03:00
AB
83a6045b18 Fix typo. 2021-01-04 15:13:06 +03:00
c8c55782ec Merge pull request #4 from house-of-vanity/matching_commands
lint.
2021-01-03 22:44:46 +03:00
AB
a1b272bd40 lint. 2021-01-03 22:42:49 +03:00
ed68dbd4bd Merge pull request #3 from house-of-vanity/matching_commands
Add /sql command.
2021-01-03 22:38:54 +03:00
AB
3f00505659 Add /sql command. 2021-01-03 22:37:37 +03:00
5a41d4a0b9 Merge pull request #2 from house-of-vanity/matching_commands
Rewrite command parsing.
2020-12-31 01:59:28 +03:00
AB
3fd5b124f3 Bump mystem lib. Lint code. 2020-12-31 01:56:20 +03:00
AB
17442819c4 Rewrite command parsing. 2020-12-31 01:42:36 +03:00
AB
7adc629292 Improve omedeto. Detect feminine by verbs. Fix 2020-12-30 15:25:33 +03:00
AB
39640139fa Improve omedeto. Detect feminine by verbs. 2020-12-30 15:12:17 +03:00
AB
0812c9e371 Improve omedeto. Nouns. 2020-12-30 14:30:53 +03:00
AB
f111f54606 Improve omedeto. Nouns. 2020-12-30 11:56:25 +03:00
AB
7e17851131 Improve omedeto 2020-12-30 11:50:19 +03:00
AB
b674ae5b15 Update omedeto 2020-12-30 09:58:17 +03:00
AB
412c3f313c Fix typo. 2020-12-30 09:47:33 +03:00
AB
1838674cab Fix typo. 2020-12-30 09:38:33 +03:00
AB
30d9d470cd Fix omedeto. 2020-12-30 09:24:15 +03:00
AB
3236131377 Move Mystem to external lib. add /omedeto 2020-12-29 17:09:49 +03:00
27 changed files with 2763 additions and 326 deletions

27
.github/workflows/automerge.yml vendored Normal file
View 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 }}"

View File

@ -11,38 +11,65 @@ jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose --release
- name: Upload Linux binary
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: desubot
path: ./target/release/desubot
build-windows:
runs-on: windows-latest
build-push-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --release
- name: Upload Windows binary
uses: actions/upload-artifact@v1
- name: Branch name
id: branch_name
run: |
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
name: desubot.exe
path: ./target/release/desubot.exe
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build_latest
uses: docker/build-push-action@v6
with:
push: true
tags: ultradesu/desubot:latest
-
name: Build and push
id: docker_build_tag
uses: docker/build-push-action@v6
with:
push: true
tags: ultradesu/desubot:${{ steps.branch_name.outputs.SOURCE_TAG }}
publish:
name: Publish release
needs: [build-windows, build-linux]
needs: [build-linux]
runs-on: ubuntu-latest
steps:
# - name: Checkout
# uses: actions/checkout@v4
- name: Get the version (git tag)
id: get_version
run: |
echo ${GITHUB_REF/refs\/tags\/v/}
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
echo ::set-output name=FULL_TAG::${GITHUB_REF/refs\/tags\//}
- name: Get the repo data (git tag)
id: get_repo_data
run: |
@ -50,40 +77,25 @@ jobs:
echo ::set-output name=AUTHOR::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $1}')
echo ::set-output name=REPO_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')
shell: bash
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload binary assets
- name: Prepare release downloading
run: |
mkdir artifacts
- name: Download Linux binary
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: desubot
path: ./artifacts/
- name: Download Windows binary
uses: actions/download-artifact@v1
with:
name: desubot.exe
path: ./artifacts/
- name: Upload binary assets
run: |
wget https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2
tar xjf linux-amd64-github-release.tar.bz2
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
for artifact in ./artifacts/*; do
./bin/linux/amd64/github-release upload \
-u ${{ steps.get_repo_data.outputs.AUTHOR }} \
-r ${{ steps.get_repo_data.outputs.REPO_NAME }} \
--tag ${{ steps.get_version.outputs.FULL_TAG }} \
--name ${artifact} \
--file ${artifact}
done
- name: Build
run: echo ${{ github.sha }} > Release.txt
- name: Test
run: cat Release.txt
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: './artifacts/*'

3
.gitignore vendored
View File

@ -6,3 +6,6 @@ memory.sqlite3
/video
/voice
/.idea
Cargo.lock
k8s/k8s-deploy.yaml
/identifier.sqlite

View File

@ -1,6 +1,6 @@
[package]
name = "desubot"
version = "0.1.0"
version = "0.5.12"
authors = ["AB <ab@hexor.ru>"]
edition = "2018"
@ -9,28 +9,34 @@ edition = "2018"
[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"
#telegram-bot = "0.8.0"
telegram-bot = { git = "https://github.com/ayrat555/telegram-bot", branch = "ayrat555/api-fixes-10" }
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 = "*"
sha1 = "0.6.0"
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"
rand = "0.8.5"
mystem = "^0.2"
#mystem = { path = "../mystem-rs" }
async-trait = "0.1.42"
sqlparser = "0.7.0"
[dependencies.syntect]
version = "4.4"
default-features = false
features = ["parsing", "dump-load", "regex-onig"]

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
# syntax=docker/dockerfile:1
FROM rust:bookworm AS builder
WORKDIR /desubot
ADD ./ /desubot/
RUN cargo build --release
FROM debian:bookworm
WORKDIR /storage
COPY --from=builder /desubot/target/release/desubot /usr/bin/
COPY mystem /usr/bin/
RUN apt update && apt install -y fontconfig openssl ca-certificates && rm -rf /var/lib/apt/lists/*
ENTRYPOINT desubot

16
README
View File

@ -1,16 +0,0 @@
Desubot
Telegram bot with light group statistic and heavy spy features.
== Features ==
* Collect all the messages sent to group.
* Collect all the media sent to group including voice, stickers, video, video notes, documents.
* /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 ==
* 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.

34
README.md Normal file
View File

@ -0,0 +1,34 @@
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot?ref=badge_shield)
# Desubot Telegram Bot
**Desubot** is a Telegram bot with light group statistics and powerful spy features.
## Features
- **Collect all messages**: The bot collects all messages sent to the group.
- **Collect all media**: The bot saves all media sent to the group, including voice messages, stickers, videos, video notes, and documents.
- **/here command**: Mention all group members.
- **Blacklist filter and stemming**: The bot saves the entire message, performs blacklist filtering, and stems every word (Russian only). For example, "Красивую собаку мыли негры" -> "красивый собака мыть негр".
- **Markov Chain sentence generation**: The bot generates sentences using Markov Chains trained on the history with the `/markov_all` command.
- **Syntax highlighting for CODE**: Export code with syntax highlighting to an image.
## Important
- **MyStem**: Desubot uses MyStem by Yandex for word stemming and assumes that the `mystem` binary is available in the PATH.
- **Ubuntu dependencies**: The following packages are required:
```bash
libssl-dev libsqlite3-dev cmake libfreetype-dev pkg-config
[Docker Hub](https://hub.docker.com/repository/docker/ultradesu/desubot/general)
![image](https://user-images.githubusercontent.com/4666566/150677613-32bdedf9-4b4c-4ec5-99cd-3d0221e56fb5.png)
![image](https://user-images.githubusercontent.com/4666566/150677660-183572b4-2a69-425f-a32c-dba5ec97e438.png)
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhouse-of-vanity%2Fdesubot?ref=badge_large)

3
assets/README.md Normal file
View File

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

BIN
assets/fonts/Hack-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

43
assets/help_text.rs Normal file
View File

@ -0,0 +1,43 @@
#[allow(dead_code)]
pub(crate) static CODE_HELP: &str = "<b>Code highlighter</b>
<i>Usage</i>
<pre>/code
&lt;CODE&gt;
#&lt;lang - JS by default&gt; #&lt;theme - Dracula by default&gt;</pre>
Language may be defined by both name and extension - Rust, rs...
Max length - 4000
List of themes:
1337
DarkNeon
Dracula
GitHub
Monokai_Extended
Monokai_Extended_Bright
Monokai_Extended_Light
Monokai_Extended_Origin
Nord
OneHalfDark
OneHalfLight
Solarized_(dark)
Solarized_(light)
Sublime_Snazzy
TwoDark
ansi-dark
ansi-light
base16
base16-256
gruvbox
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>";

431
assets/stop-words.txt Normal file
View File

@ -0,0 +1,431 @@
а
в
г
е
ж
и
к
м
о
с
т
у
я
чо
че
ща
ваще
бы
stat
вообще
ThreadTopBot
/stat
во
вы
да
до
ее
ей
ею
её
же
за
из
им
их
ли
мы
на
не
ни
но
ну
нх
об
он
от
по
со
та
те
то
ту
ты
уж
без
был
вам
вас
ваш
вон
вот
все
всю
вся
всё
где
год
два
две
дел
для
его
ему
еще
ещё
или
ими
имя
как
кем
ком
кто
лет
мне
мог
мож
мои
мой
мор
моя
моё
над
нам
нас
наш
нее
ней
нем
нет
нею
неё
них
оба
она
они
оно
под
пор
при
про
раз
сам
сих
так
там
тем
тех
том
тот
тою
три
тут
уже
чем
что
эта
эти
это
эту
алло
буду
будь
бывь
была
были
было
быть
вами
ваша
ваше
ваши
ведь
весь
вниз
всем
всех
всею
года
году
даже
двух
день
если
есть
зато
кого
кому
куда
лишь
люди
мало
меля
меня
мимо
мира
мной
мною
мочь
надо
нами
наша
наше
наши
него
нему
ниже
ними
один
пока
пора
пять
рано
сама
сами
само
саму
свое
свои
свою
себе
себя
семь
стал
суть
твой
твоя
твоё
тебе
тебя
теми
того
тоже
тому
туда
хоть
хотя
чаще
чего
чему
чтоб
чуть
этим
этих
этой
этом
этот
более
будем
будет
будто
будут
вверх
вдали
вдруг
везде
внизу
время
всего
всеми
всему
всюду
давно
даром
долго
друго
занят
затем
зачем
здесь
иметь
какая
какой
когда
кроме
лучше
между
менее
много
могут
может
можно
можхо
назад
низко
нужно
одной
около
опять
очень
перед
позже
после
потом
почти
пятый
разве
рядом
самим
самих
самой
самом
своей
своих
сеаой
снова
собой
собою
такая
также
такие
такое
такой
тобой
тобою
тогда
тысяч
уметь
часто
через
чтобы
шесть
этими
этого
этому
близко
больше
будете
будешь
бывает
важная
важное
важные
важный
вокруг
восемь
всегда
второй
далеко
дальше
девять
десять
должно
другая
другие
других
другое
другой
занята
занято
заняты
значит
именно
иногда
каждая
каждое
каждые
каждый
кругом
меньше
начала
нельзя
нибудь
никуда
ничего
обычно
однако
одного
отсюда
первый
потому
почему
просто
против
раньше
самими
самого
самому
своего
сейчас
сказал
совсем
теперь
только
третий
хорошо
хотеть
хочешь
четыре
шестой
восьмой
впрочем
времени
говорил
говорит
девятый
десятый
кажется
конечно
которая
которой
которые
который
которых
наверху
наконец
недавно
немного
нередко
никогда
однажды
посреди
сегодня
седьмой
сказала
сказать
сколько
слишком
сначала
спасибо
двадцать
довольно
которого
наиболее
недалеко
особенно
отовсюду
двадцатый
миллионов
несколько
прекрасно
процентов
четвертый
двенадцать
непрерывно
пожалуйста
пятнадцать
семнадцать
тринадцать
двенадцатый
одиннадцать
пятнадцатый
семнадцатый
тринадцатый
шестнадцать
восемнадцать
девятнадцать
одиннадцатый
четырнадцать
шестнадцатый
восемнадцатый
девятнадцатый
действительно
четырнадцатый
многочисленная
многочисленное
многочисленные
многочисленный
ага
делать
писать
бот

21
assets/sync_from_bat.py Normal file
View File

@ -0,0 +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.')

BIN
assets/syntaxes.bin Normal file

Binary file not shown.

4
assets/syntaxes/.gitignore vendored Normal file
View File

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

BIN
assets/themes.bin Normal file

Binary file not shown.

5
assets/themes/.gitignore vendored Normal file
View File

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

View File

@ -0,0 +1,940 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Dracula Theme v1.4.3
#
# https://github.com/dracula/sublime
#
# Copyright 2013-present, All rights reserved
#
# Code licensed under the MIT license
#
# @author Zeno Rocha <hi@zenorocha.com>
-->
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Dracula</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
<dict>
<key>background</key>
<string>#282a36</string>
<key>caret</key>
<string>#f8f8f0</string>
<key>block_caret</key>
<string>#999a9e</string>
<key>foreground</key>
<string>#f8f8f2</string>
<key>invisibles</key>
<string>#3B3A32</string>
<key>lineHighlight</key>
<string>#44475a</string>
<key>selection</key>
<string>#44475a</string>
<key>findHighlight</key>
<string>#effb7b</string>
<key>findHighlightForeground</key>
<string>#000000</string>
<key>selectionBorder</key>
<string>#222218</string>
<key>activeGuide</key>
<string>#9D550FB0</string>
<key>bracketsForeground</key>
<string>#F8F8F2A5</string>
<key>bracketsOptions</key>
<string>underline</string>
<key>bracketContentsForeground</key>
<string>#F8F8F2A5</string>
<key>bracketContentsOptions</key>
<string>underline</string>
<key>tagsOptions</key>
<string>stippled_underline</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272a4</string>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>String</string>
<key>scope</key>
<string>string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f1fa8c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Number</string>
<key>scope</key>
<string>constant.numeric</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Built-in constant</string>
<key>scope</key>
<string>constant.language</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>User-defined constant</string>
<key>scope</key>
<string>constant.character, constant.other</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable</string>
<key>scope</key>
<string>variable</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Ruby's @variable</string>
<key>scope</key>
<string>variable.other.readwrite.instance</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>String interpolation</string>
<key>scope</key>
<string>constant.character.escaped, constant.character.escape, string source, string source.ruby</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Ruby Regexp</string>
<key>scope</key>
<string>source.ruby string.regexp.classic.ruby,source.ruby string.regexp.mod-r.ruby</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff5555</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Keyword</string>
<key>scope</key>
<string>keyword</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage</string>
<key>scope</key>
<string>storage</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage type</string>
<key>scope</key>
<string>storage.type</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Namespace</string>
<key>scope</key>
<string>storage.type.namespace</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Class</string>
<key>scope</key>
<string>storage.type.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Class name</string>
<key>scope</key>
<string>entity.name.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Meta Path</string>
<key>scope</key>
<string>meta.path</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Inherited class</string>
<key>scope</key>
<string>entity.other.inherited-class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic underline</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function name</string>
<key>scope</key>
<string>entity.name.function</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function argument</string>
<key>scope</key>
<string>variable.parameter</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tag name</string>
<key>scope</key>
<string>entity.name.tag</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tag attribute</string>
<key>scope</key>
<string>entity.other.attribute-name</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library function</string>
<key>scope</key>
<string>support.function</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library constant</string>
<key>scope</key>
<string>support.constant</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#6be5fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library class&#x2f;type</string>
<key>scope</key>
<string>support.type, support.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library variable</string>
<key>scope</key>
<string>support.other.variable</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support Other Namespace</string>
<key>scope</key>
<string>support.other.namespace</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Invalid</string>
<key>scope</key>
<string>invalid</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#ff79c6</string>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#F8F8F0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Invalid deprecated</string>
<key>scope</key>
<string>invalid.deprecated</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#bd93f9</string>
<key>foreground</key>
<string>#F8F8F0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON String</string>
<key>scope</key>
<string>meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#CFCFC2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.header</string>
<key>scope</key>
<string>meta.diff, meta.diff.header</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272a4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.inserted</string>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.changed</string>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#E6DB74</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>constant.numeric.line-number.find-in-files - match</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>entity.name.filename</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#E6DB74</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>message.error</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F83333</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON Punctuation</string>
<key>scope</key>
<string>punctuation.definition.string.begin.json - meta.structure.dictionary.value.json, punctuation.definition.string.end.json - meta.structure.dictionary.value.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#EEEEEE</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON Structure</string>
<key>scope</key>
<string>meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON String</string>
<key>scope</key>
<string>meta.structure.dictionary.value.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f1fa8c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 6 deep</string>
<key>scope</key>
<string>meta meta meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 5 deep</string>
<key>scope</key>
<string>meta meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 4 deep</string>
<key>scope</key>
<string>meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 3 deep</string>
<key>scope</key>
<string>meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 2 deep</string>
<key>scope</key>
<string>meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 1 deep</string>
<key>scope</key>
<string>meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<!-- Markdown Tweaks -->
<dict>
<key>name</key>
<string>Markup: strike</string>
<key>scope</key>
<string>markup.strike</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: bold</string>
<key>scope</key>
<string>markup.bold</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: italic</string>
<key>scope</key>
<string>markup.italic</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: heading</string>
<key>scope</key>
<string>markup.heading</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8BE9FD</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: List Items Punctuation</string>
<key>scope</key>
<string>punctuation.definition.list_item.markdown</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Blockquote</string>
<key>scope</key>
<string>markup.quote</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Blockquote Punctuation</string>
<key>scope</key>
<string>punctuation.definition.blockquote.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>background</key>
<string>#6272A4</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Separator</string>
<key>scope</key>
<string>meta.separator</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: raw inline</string>
<key>scope</key>
<string>text.html.markdown markup.raw.inline</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50FA7B</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: underline</string>
<key>scope</key>
<string>markup.underline</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#BD93F9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: Raw block</string>
<key>scope</key>
<string>markup.raw.block</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#CFCFC2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Raw Block fenced source</string>
<key>scope</key>
<string>markup.raw.block.fenced.markdown source</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F8F8F2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Fenced Bode Block</string>
<key>scope</key>
<string>punctuation.definition.fenced.markdown, variable.language.fenced.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Fenced Language</string>
<key>scope</key>
<string>variable.language.fenced.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Accessor</string>
<key>scope</key>
<string>punctuation.accessor</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Meta Function Return Type</string>
<key>scope</key>
<string>meta.function.return-type</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Block Begin</string>
<key>scope</key>
<string>punctuation.section.block.begin</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Block End</string>
<key>scope</key>
<string>punctuation.section.block.end</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Embedded Begin</string>
<key>scope</key>
<string>punctuation.section.embedded.begin</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Embedded End</string>
<key>scope</key>
<string>punctuation.section.embedded.end</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Separator Namespace</string>
<key>scope</key>
<string>punctuation.separator.namespace</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Function</string>
<key>scope</key>
<string>variable.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Other</string>
<key>scope</key>
<string>variable.other</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Language</string>
<key>scope</key>
<string>variable.language</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Module Ruby</string>
<key>scope</key>
<string>entity.name.module.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Constant Ruby</string>
<key>scope</key>
<string>entity.name.constant.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support Function Builtin Ruby</string>
<key>scope</key>
<string>support.function.builtin.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Namespace CS</string>
<key>scope</key>
<string>storage.type.namespace.cs</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Namespace CS</string>
<key>scope</key>
<string>entity.name.namespace.cs</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
</array>
<key>uuid</key>
<string>83091B89-765E-4F0D-9275-0EC6CB084126</string>
<key>colorSpaceName</key>
<string>sRGB</string>
<key>semanticClass</key>
<string>theme.dracula</string>
<key>author</key>
<string>Zeno Rocha</string>
</dict>
</plist>

View File

@ -0,0 +1,43 @@
---
apiVersion: v1
kind: Secret
metadata:
name: desubot-api-token
data:
token: 123.... # Base64 encoded token.
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: desubot
spec:
serviceName: "desubot"
replicas: 1
selector:
matchLabels:
app: desubot
template:
metadata:
labels:
app: desubot
spec:
containers:
- name: desubot
image: ultradesu/desubot:latest
volumeMounts:
- name: storage
mountPath: /storage
env:
- name: TELEGRAM_BOT_TOKEN
valueFrom:
secretKeyRef:
name: desubot-api-token
key: token
volumeClaimTemplates:
- metadata:
name: storage
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Gi

File diff suppressed because it is too large Load Diff

140
src/db.rs
View File

@ -1,6 +1,7 @@
#[allow(unused_mut)]
#[allow(dead_code)]
use crate::errors;
use crate::utils;
use futures::StreamExt;
use rusqlite::{named_params, params, Connection, Error, Result};
use std::time::SystemTime;
use telegram_bot::*;
@ -35,6 +36,30 @@ pub(crate) fn update_scheme() -> Result<()> {
Ok(())
}
pub(crate) fn load_stopwords() -> Result<()> {
info!("Populating stop words wait please.");
let conn = open()?;
for table in include_str!("../assets/stop-words.txt")
.split('\n')
.into_iter()
{
let word = table.trim();
if word != "" {
let mut _stmt = conn
.prepare_cached(
"
INSERT OR IGNORE INTO
stop_words('word')
VALUES (:word)
",
)?
.insert(params![word]);
}
}
info!("Stop words updated.");
Ok(())
}
pub(crate) fn get_user(id: telegram_bot::UserId) -> Result<telegram_bot::User, errors::Error> {
let conn = open()?;
let mut stmt = conn.prepare_cached(
@ -55,7 +80,7 @@ pub(crate) fn get_user(id: telegram_bot::UserId) -> Result<telegram_bot::User, e
})
}
if users.len() == 0 {
if users.is_empty() {
Err(errors::Error::UserNotFound)
} else {
Ok(users[0].clone())
@ -75,14 +100,14 @@ pub(crate) fn get_conf(id: telegram_bot::ChatId) -> Result<Conf, errors::Error>
date: row.get(2)?,
})
}
if confs.len() == 0 {
if confs.is_empty() {
Err(errors::Error::ConfNotFound)
} else {
Ok(confs[0].clone())
}
}
/*
#[allow(dead_code)]
pub(crate) fn get_confs() -> Result<Vec<Conf>> {
let conn = open()?;
let mut stmt = conn.prepare("SELECT id, title, date FROM conf")?;
@ -101,7 +126,7 @@ pub(crate) fn get_confs() -> Result<Vec<Conf>> {
Ok(confs)
}
*/
pub(crate) async fn get_messages_random_all() -> Result<Vec<String>, Error> {
let conn = open()?;
let mut stmt = conn.prepare_cached("SELECT text FROM messages ORDER BY RANDOM() LIMIT 50")?;
@ -136,6 +161,7 @@ pub(crate) async fn get_messages_random_group(
Ok(messages)
}
#[allow(dead_code)]
pub(crate) async fn get_messages_user_group(
message: &telegram_bot::Message,
) -> Result<Vec<String>, Error> {
@ -180,18 +206,29 @@ 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(
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
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 +251,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 +265,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 +287,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 +320,11 @@ 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 +351,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(())
@ -345,14 +386,12 @@ pub(crate) async fn get_file(file_id: String) -> Result<i64, errors::Error> {
Ok(id) => Ok(id),
Err(_) => Err(errors::Error::FileNotFound),
};
file_rowid
}
async fn add_word(word: &String) -> Result<i64, errors::Error> {
match get_stop_word(&word).await {
Err(_) => return Err(errors::Error::WordInStopList),
_ => {}
async fn add_word(word: &str) -> Result<i64, errors::Error> {
if get_stop_word(&word).await.is_err() {
return Err(errors::Error::WordInStopList);
}
let conn = open()?;
let word_rowid =
@ -366,7 +405,7 @@ async fn add_word(word: &String) -> Result<i64, errors::Error> {
Ok(word_rowid)
}
async fn get_stop_word(stop_word: &String) -> Result<(), errors::Error> {
async fn get_stop_word(stop_word: &str) -> Result<(), errors::Error> {
let conn = open()?;
match conn.execute_named(
"SELECT rowid FROM stop_words WHERE word = (:stop_word)",
@ -400,6 +439,7 @@ async fn add_relation(word_id: i64, msg_id: i64, message: &Message) -> Result<i6
Ok(rowid)
}
#[allow(unused_must_use)]
pub(crate) async fn add_sentence(
message: &telegram_bot::Message,
mystem: &mut mystem::MyStem,
@ -418,6 +458,7 @@ pub(crate) async fn add_sentence(
};
// Save stemmed words
debug!("Going to stem: {}", text);
let words = mystem.stemming(text)?;
conn.execute("BEGIN TRANSACTION", params![]);
for word in words {
@ -432,7 +473,7 @@ pub(crate) async fn add_sentence(
Err(e) => panic!("SQLITE3 Error: Relations failed: {:?}", e),
}
}
Err(_) => debug!("Word {} is in stop list.", &word.lex[0].lex),
Err(_) => debug!("Word {} is in a stop list.", &word.lex[0].lex),
}
}
conn.execute("END TRANSACTION", params![]);
@ -471,3 +512,56 @@ pub(crate) async fn get_top(
}
Ok(top)
}
pub(crate) async fn get_global_top() -> Result<Vec<TopWord>, errors::Error> {
let conn = open()?;
let mut stmt = conn.prepare_cached(
"
SELECT w.word, COUNT(*) as count FROM relations r
LEFT JOIN word w ON w.id = r.word_id
GROUP BY w.word
ORDER BY count DESC
LIMIT 50
",
)?;
let mut rows = stmt.query_named(named_params! {})?;
let mut top = Vec::new();
while let Some(row) = rows.next()? {
top.push(TopWord {
word: row.get(0)?,
count: row.get(1)?,
})
}
Ok(top)
}
pub(crate) async fn get_conf_top(
message: &telegram_bot::Message,
) -> Result<Vec<TopWord>, errors::Error> {
let conf_id = i64::from(message.chat.id());
let conn = open()?;
let mut stmt = conn.prepare_cached(
"
SELECT w.word, COUNT(*) as count FROM relations r
LEFT JOIN word w ON w.id = r.word_id
WHERE r.conf_id = :conf_id
GROUP BY w.word
ORDER BY count DESC
LIMIT 10
",
)?;
let mut rows = stmt.query_named(named_params! {":conf_id": conf_id})?;
let mut top = Vec::new();
while let Some(row) = rows.next()? {
top.push(TopWord {
word: row.get(0)?,
count: row.get(1)?,
})
}
Ok(top)
}

View File

@ -20,51 +20,83 @@ pub enum Error {
JsonParseError(serde_error),
PopenError(popen_error),
MystemError(mystem_error),
SQLBannedCommand(String),
SQLInvalidCommand,
SQLResultTooLong(String),
CodeHighlightningError,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "An error occurred.")
// match self {
// _ => write!(f, "An error occurred."),
// // Error::UserNotFound => {}
// // Error::SQLITE3Error(_) => {}
// // Error::TelegramError(_) => {}
// // Error::ReqwestError(_) => {}
// // Error::ConfNotFound => {}
// // Error::WordNotFound => {}
// // Error::WordInStopList => {}
// // Error::IOError(_) => {}
// // Error::FileNotFound => {}
// // Error::JsonParseError(_) => {}
// // Error::PopenError(_) => {}
// // Error::MystemError(_) => {}
// // Error::SQLBannedCommand(_) => {}
// // Error::SQLInvalidCommand => {}
// // Error::SQLResultTooLong(_) => {}
// // Error::CodeHighlightningError(Help) => write!(f, "Code highlighter.\
// // <b>Usage</b><pre>/CODE\
// // #&lt;theme&gt;\
// // &lt;CODE&gt;\
// // #&lt;lang&gt;</pre>\
// // \
// // List of themes:\
// // .")
// Error::CodeHighlightningError(help) => write!(f, "{}", help.description)
// }
}
}
impl From<sqlite_error> for Error {
fn from(e: sqlite_error) -> Error {
return Error::SQLITE3Error(e);
Error::SQLITE3Error(e)
}
}
impl From<tg_error> for Error {
fn from(e: tg_error) -> Error {
return Error::TelegramError(e);
Error::TelegramError(e)
}
}
impl From<reqwest_error> for Error {
fn from(e: reqwest_error) -> Error {
return Error::ReqwestError(e);
Error::ReqwestError(e)
}
}
impl From<io_error> for Error {
fn from(e: io_error) -> Error {
return Error::IOError(e);
Error::IOError(e)
}
}
impl From<serde_error> for Error {
fn from(e: serde_error) -> Error {
return Error::JsonParseError(e);
Error::JsonParseError(e)
}
}
impl From<popen_error> for Error {
fn from(e: popen_error) -> Error {
return Error::PopenError(e);
Error::PopenError(e)
}
}
impl From<mystem_error> for Error {
fn from(e: mystem_error) -> Error {
return Error::MystemError(e);
Error::MystemError(e)
}
}

View File

@ -1,10 +1,15 @@
use crate::commands;
//use crate::commands::Command;
use crate::commands::{
Code, ConfTop, Execute, GlobalTop, Here, Markov, MarkovAll, Omedeto, Scheme, Sql, Top,
};
use crate::db;
use crate::errors;
use crate::utils;
use mystem::MyStem;
use telegram_bot::*;
include!("../assets/help_text.rs");
pub async fn handler(
api: Api,
message: Message,
@ -21,17 +26,151 @@ pub async fn handler(
title,
&message.from.id,
&message.from.first_name,
data
data.replace("\n", " ")
);
db::add_sentence(&message, mystem).await?;
match data.as_str() {
"/here" => commands::here(api, message).await?,
"/top" => commands::top(api, message).await?,
"/stat" => commands::top(api, message).await?,
"/markov_all" => commands::markov_all(api, message).await?,
"/markov" => commands::markov(api, message).await?,
"/omedeto" => commands::omedeto(api, message, mystem).await?,
_ => (),
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", ""),
}
.exec_with_result(&api, &message)
.await
} {
Ok(path) => {
let mut cnt_lines = 0;
for _ in s.lines() {
cnt_lines = cnt_lines + 1;
}
let mut cnt_chars = 0;
for _ in s.chars() {
cnt_chars = cnt_chars + 1;
}
let file = InputFileUpload::with_path(path.clone());
info!("lines: {}, chars: {}", cnt_lines, cnt_chars);
// api.send(message.chat.document(&file)).await?;
//
// // Send an image from disk
if cnt_chars > 4000 {
let _ = api
.send(message.text_reply(CODE_HELP).parse_mode(ParseMode::Html))
.await?;
return Ok(());
}
if cnt_lines < 81 {
api.send(message.chat.photo(&file)).await?;
} else {
api.send(message.chat.document(&file)).await?;
}
//debug!("{:#?}", formatter);
let _ = std::fs::remove_file(&path);
}
Err(_) => {
let _ = api
.send(message.text_reply(CODE_HELP).parse_mode(ParseMode::Html))
.await?;
}
}
}
s if s.contains("/here")
|| s.contains("@here")
|| s.contains("/хере")
|| s.contains("@хере")
|| s.contains("@all")
|| s.contains("\"руку")
|| s.contains("\"хере") =>
{
db::add_sentence(&message, mystem).await?;
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?;
}
},
"/top" | "/stat" => {
Top {
data: "".to_string(),
}
.exec(&api, &message)
.await?
}
"/global_top" | "/global_stat" => {
GlobalTop {
data: "".to_string(),
}
.exec(&api, &message)
.await?
}
"/conf_stat" | "/conf_top" => {
ConfTop {
data: "".to_string(),
}
.exec(&api, &message)
.await?
}
"/markov_all" => {
MarkovAll {
data: "".to_string(),
}
.exec(&api, &message)
.await?
}
"/markov" => {
if title != "PRIVATE" {
Markov {
data: "".to_string(),
}
.exec(&api, &message)
.await?
} else {
let _ = api
.send(
message
.text_reply("Allowed in groups only")
.parse_mode(ParseMode::Html),
)
.await?;
}
}
"/scheme" | "/schema" => {
Scheme {
data: "".to_string(),
}
.exec(&api, &message)
.await?
}
"/omedeto" => {
Omedeto {
data: "".to_string(),
}
.exec_mystem(&api, &message, mystem)
.await?
}
_ => db::add_sentence(&message, mystem).await?,
}
}
MessageKind::Photo { ref caption, .. } => {
@ -42,7 +181,7 @@ pub async fn handler(
title,
&message.from.id,
&message.from.first_name,
caption.clone().unwrap_or("NO_TITLE".to_string())
caption.clone().unwrap_or_else(|| "NO_TITLE".to_string())
);
utils::get_files(api, message, token).await?;
}
@ -55,7 +194,7 @@ pub async fn handler(
title,
&message.from.id,
&message.from.first_name,
caption.clone().unwrap_or("NO_TITLE".to_string())
caption.clone().unwrap_or_else(|| "NO_TITLE".to_string())
);
utils::get_files(api, message, token).await?;
}

View File

@ -1,4 +1,6 @@
#![allow(unreachable_code)]
use std::{env, process};
use tokio::time::{delay_for, Duration};
use futures::StreamExt;
use telegram_bot::*;
@ -16,7 +18,7 @@ use mystem::MyStem;
#[tokio::main]
async fn main() -> Result<(), errors::Error> {
env_logger::from_env(Env::default().default_filter_or("info")).init();
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
let mut mystem = match MyStem::new() {
Ok(mystem) => mystem,
Err(e) => {
@ -28,6 +30,10 @@ async fn main() -> Result<(), errors::Error> {
Ok(_) => {}
Err(e) => panic!("Database error: {:?}", e),
}
match db::load_stopwords() {
Ok(_) => {}
Err(e) => panic!("Database error: {:?}", e),
}
let token = match env::var("TELEGRAM_BOT_TOKEN") {
Ok(token) => token,
Err(_) => {
@ -44,13 +50,33 @@ async fn main() -> Result<(), errors::Error> {
me.first_name,
me.id
);
while let Some(update) = stream.next().await {
let update = update?;
if let UpdateKind::Message(message) = update.kind {
db::add_conf(message.clone()).await?;
db::add_user(message.clone()).await?;
handlers::handler(api.clone(), message, token.clone(), &mut mystem, me.clone()).await?;
loop {
while let Some(update) = stream.next().await {
match update {
Ok(u) => {
if let UpdateKind::Message(message) = u.kind {
db::add_conf(message.clone()).await?;
db::add_user(message.clone()).await?;
match handlers::handler(
api.clone(),
message,
token.clone(),
&mut mystem,
me.clone(),
)
.await
{
Ok(_) => {}
Err(e) => warn!("An error occurred handling command. {:?}", e),
}
}
}
Err(e) => {
warn!("Telegram API Error: {:?}", e);
}
};
}
delay_for(Duration::from_secs(2)).await;
}
Ok(())
}

View File

@ -13,15 +13,14 @@ pub(crate) fn get_title(message: &Message) -> String {
match &message.chat {
MessageChat::Supergroup(chat) => chat.title.clone(),
MessageChat::Group(chat) => chat.title.clone(),
MessageChat::Private(_) => format!("PRIVATE"),
MessageChat::Private(_) => "PRIVATE".to_string(),
_ => "PRIVATE".to_string(),
}
}
pub(crate) async fn create_dir(dir: &String) -> () {
match fs_create_dir(dir) {
Ok(_) => info!("Dir {} created.", dir),
Err(_) => (),
pub(crate) async fn create_dir(dir: &str) {
if fs_create_dir(dir).is_ok() {
info!("Dir {} created.", dir)
}
}