8 Commits

Author SHA1 Message Date
AB
282efe5be4 Add k8s deploy example 2021-08-23 01:06:11 +03:00
AB
f1dc1d0897 Add Dockerfile. 2021-08-23 00:58:25 +03: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
AB
ac2be9929a Rollback tokio 2021-08-19 18:40:12 +03:00
7432ce6398 Bump many libs 2021-08-19 18:08:19 +03: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
6 changed files with 97 additions and 16 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ memory.sqlite3
/voice
/.idea
Cargo.lock
k8s/k8s-deploy.yaml

View File

@ -1,6 +1,6 @@
[package]
name = "desubot"
version = "0.5.5"
version = "0.5.7"
authors = ["AB <ab@hexor.ru>"]
edition = "2018"
@ -12,7 +12,8 @@ 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 }

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
# syntax=docker/dockerfile:1
FROM rust:latest AS builder
WORKDIR /desubot
ADD ./ /desubot/
RUN cargo build --release
FROM ubuntu:latest
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

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

View File

@ -53,7 +53,12 @@ pub async fn handler(
}
}
}
s if s.contains("/here") || s.contains("@here") => {
s if s.contains("/here")
|| s.contains("@here")
|| s.contains("/хере")
|| s.contains("@хере")
|| s.contains("\"хере") =>
{
db::add_sentence(&message, mystem).await?;
Here {
data: "".to_string(),

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) => {
@ -44,18 +46,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?;
match handlers::handler(api.clone(), message, token.clone(), &mut mystem, me.clone())
.await
{
Ok(_) => {}
Err(e) => warn!("An error occurred handling command. {:?}", e),
}
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(())
}