Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3bc14ce343 | ||
|
e02bca8ad2 | ||
|
fe13b65016 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
target
|
target
|
||||||
.direnv
|
.direnv
|
||||||
*.db
|
*.db
|
||||||
|
deploy/**/config
|
27
deploy/k8s/deployment.yaml
Normal file
27
deploy/k8s/deployment.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: hangitbot
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: hangitbot
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: hangitbot
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: hangitbot
|
||||||
|
image: <Image>
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "64Mi"
|
||||||
|
cpu: "100m"
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: hangitbot
|
||||||
|
env:
|
||||||
|
- name: API_URL
|
||||||
|
value: https://tgapi.sense-t.eu.org/
|
||||||
|
|
13
deploy/k8s/kustomization.yaml
Normal file
13
deploy/k8s/kustomization.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# yaml-language-server: $schema=https://json.schemastore.org/kustomization.json
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
secretGenerator:
|
||||||
|
- name: hangitbot
|
||||||
|
files:
|
||||||
|
- config/DATABASE_URI
|
||||||
|
- config/TGBOT_TOKEN
|
||||||
|
images:
|
||||||
|
- name: <Image>
|
||||||
|
newName: ghcr.io/senseab/hangitbot
|
||||||
|
newTag: v0.0.1
|
@@ -18,7 +18,7 @@ use crate::{
|
|||||||
messages::{
|
messages::{
|
||||||
BOT_ABOUT, BOT_TEXT_HANGED, BOT_TEXT_HANGED_SELF, BOT_TEXT_IS_CHANNEL, BOT_TEXT_NO_TARGET,
|
BOT_ABOUT, BOT_TEXT_HANGED, BOT_TEXT_HANGED_SELF, BOT_TEXT_IS_CHANNEL, BOT_TEXT_NO_TARGET,
|
||||||
BOT_TEXT_TOP_GLOBAL, BOT_TEXT_TOP_GROUP, BOT_TEXT_TOP_NONE, BOT_TEXT_TOP_TEMPLATE,
|
BOT_TEXT_TOP_GLOBAL, BOT_TEXT_TOP_GROUP, BOT_TEXT_TOP_NONE, BOT_TEXT_TOP_TEMPLATE,
|
||||||
BOT_TEXT_TOP_TITLE,
|
BOT_TEXT_TOP_TITLE, BOT_TEXT_HANG_BOT, BOT_TEXT_HANG_ANONYMOUS, BOT_TEXT_HANG_CHANNEL,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,6 +106,18 @@ impl CommandHandler {
|
|||||||
|
|
||||||
match reply.from() {
|
match reply.from() {
|
||||||
Some(user) => {
|
Some(user) => {
|
||||||
|
if user.is_bot {
|
||||||
|
return self.send_text_reply(bot, reply, BOT_TEXT_HANG_BOT.to_string()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.is_anonymous() {
|
||||||
|
return self.send_text_reply(bot, reply, BOT_TEXT_HANG_ANONYMOUS.to_string()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.is_channel() {
|
||||||
|
return self.send_text_reply(bot, reply, BOT_TEXT_HANG_CHANNEL.to_string()).await
|
||||||
|
}
|
||||||
|
|
||||||
let is_self = match message.from() {
|
let is_self = match message.from() {
|
||||||
Some(f) => f.first_name == user.first_name,
|
Some(f) => f.first_name == user.first_name,
|
||||||
None => false,
|
None => false,
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
use migration::{Migrator, MigratorTrait};
|
use migration::{Migrator, MigratorTrait};
|
||||||
use models::prelude::*;
|
use models::prelude::*;
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait, ColumnTrait, ConnectionTrait, Database, DatabaseConnection,
|
prelude::BigDecimal, ActiveModelTrait, ColumnTrait, ConnectionTrait, Database,
|
||||||
DbErr, EntityTrait, QueryFilter, QueryOrder, QuerySelect, QueryTrait, Set, TransactionTrait, FromQueryResult, prelude::BigDecimal,
|
DatabaseConnection, DbErr, EntityTrait, FromQueryResult, QueryFilter, QueryOrder, QuerySelect,
|
||||||
|
QueryTrait, Set, TransactionTrait,
|
||||||
};
|
};
|
||||||
use teloxide::types::{Chat, ChatId};
|
use teloxide::types::{Chat, ChatId};
|
||||||
use wd_log::{log_debug_ln, log_error_ln, log_info_ln, log_warn_ln};
|
use wd_log::{log_debug_ln, log_error_ln, log_info_ln};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, FromQueryResult)]
|
#[derive(Debug, FromQueryResult)]
|
||||||
pub struct TopData {
|
pub struct TopData {
|
||||||
@@ -14,7 +14,6 @@ pub struct TopData {
|
|||||||
pub counts: BigDecimal,
|
pub counts: BigDecimal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
db: DatabaseConnection,
|
db: DatabaseConnection,
|
||||||
@@ -31,8 +30,9 @@ impl Controller {
|
|||||||
/// Do migrate
|
/// Do migrate
|
||||||
pub async fn migrate(&self) -> Result<(), DbErr> {
|
pub async fn migrate(&self) -> Result<(), DbErr> {
|
||||||
if let Err(err) = Migrator::install(&self.db).await {
|
if let Err(err) = Migrator::install(&self.db).await {
|
||||||
log_warn_ln!("{}", err)
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = Migrator::up(&self.db, None).await {
|
if let Err(err) = Migrator::up(&self.db, None).await {
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
@@ -81,35 +81,28 @@ impl Controller {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let query = Stats::find()
|
||||||
|
.select_only()
|
||||||
|
.column(StatsColumn::Name)
|
||||||
|
.column_as(StatsColumn::Counts.sum(), "counts")
|
||||||
|
.group_by(StatsColumn::Name)
|
||||||
|
.order_by_desc(StatsColumn::Counts.sum())
|
||||||
|
.limit(LIMIT);
|
||||||
|
|
||||||
let query = match chat.is_group() || chat.is_supergroup() {
|
let query = match chat.is_group() || chat.is_supergroup() {
|
||||||
true => {
|
true => query.filter(StatsColumn::GroupId.eq(chat.id.0)),
|
||||||
Stats::find()
|
false => query,
|
||||||
.filter(StatsColumn::GroupId.eq(chat.id.0))
|
|
||||||
.order_by_desc(StatsColumn::Counts)
|
|
||||||
.limit(LIMIT).into_model()
|
|
||||||
.all(&transcation)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
let query = Stats::find()
|
|
||||||
.select_only()
|
|
||||||
.column(StatsColumn::Name)
|
|
||||||
.column_as(StatsColumn::Counts.sum(), "counts")
|
|
||||||
.group_by(StatsColumn::Name)
|
|
||||||
.order_by_desc(StatsColumn::Counts.sum())
|
|
||||||
.limit(LIMIT);
|
|
||||||
|
|
||||||
log_debug_ln!(
|
|
||||||
"SQL: {:?}",
|
|
||||||
query.build(transcation.get_database_backend()).to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
query.into_model().all(&transcation).await
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match query {
|
log_debug_ln!(
|
||||||
Ok(query) => Some(query),
|
"SQL: {:?}",
|
||||||
|
query.build(transcation.get_database_backend()).to_string()
|
||||||
|
);
|
||||||
|
|
||||||
|
let result = query.into_model().all(&transcation).await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(result) => Some(result),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
log_error_ln!("{}", error);
|
log_error_ln!("{}", error);
|
||||||
None
|
None
|
||||||
|
@@ -34,3 +34,7 @@ pub const BOT_TEXT_HANGED_SELF: [&str; 3] = [
|
|||||||
BOT_TEXT_HANGED_SELF_2,
|
BOT_TEXT_HANGED_SELF_2,
|
||||||
BOT_TEXT_HANGED_SELF_3,
|
BOT_TEXT_HANGED_SELF_3,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub const BOT_TEXT_HANG_BOT: &'static str = "机器人是无法被吊死的……";
|
||||||
|
pub const BOT_TEXT_HANG_CHANNEL: &'static str = "这是个频道……";
|
||||||
|
pub const BOT_TEXT_HANG_ANONYMOUS: &'static str = "这是个幽灵……";
|
Reference in New Issue
Block a user