bug fix for bot channel etc.
This commit is contained in:
parent
e02bca8ad2
commit
3bc14ce343
@ -18,7 +18,7 @@ use crate::{
|
||||
messages::{
|
||||
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_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() {
|
||||
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() {
|
||||
Some(f) => f.first_name == user.first_name,
|
||||
None => false,
|
||||
|
@ -1,12 +1,12 @@
|
||||
use migration::{Migrator, MigratorTrait};
|
||||
use models::prelude::*;
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ColumnTrait, ConnectionTrait, Database, DatabaseConnection,
|
||||
DbErr, EntityTrait, QueryFilter, QueryOrder, QuerySelect, QueryTrait, Set, TransactionTrait, FromQueryResult, prelude::BigDecimal,
|
||||
prelude::BigDecimal, ActiveModelTrait, ColumnTrait, ConnectionTrait, Database,
|
||||
DatabaseConnection, DbErr, EntityTrait, FromQueryResult, QueryFilter, QueryOrder, QuerySelect,
|
||||
QueryTrait, Set, TransactionTrait,
|
||||
};
|
||||
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)]
|
||||
pub struct TopData {
|
||||
@ -14,7 +14,6 @@ pub struct TopData {
|
||||
pub counts: BigDecimal,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Controller {
|
||||
db: DatabaseConnection,
|
||||
@ -31,8 +30,9 @@ impl Controller {
|
||||
/// Do migrate
|
||||
pub async fn migrate(&self) -> Result<(), DbErr> {
|
||||
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 {
|
||||
Err(err)
|
||||
} else {
|
||||
@ -81,38 +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() {
|
||||
true => {
|
||||
Stats::find().select_only()
|
||||
.column(StatsColumn::Name)
|
||||
.column_as(StatsColumn::Counts.sum(), "counts")
|
||||
.filter(StatsColumn::GroupId.eq(chat.id.0))
|
||||
.group_by(StatsColumn::Name)
|
||||
.order_by_desc(StatsColumn::Counts.sum())
|
||||
.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
|
||||
}
|
||||
true => query.filter(StatsColumn::GroupId.eq(chat.id.0)),
|
||||
false => query,
|
||||
};
|
||||
|
||||
match query {
|
||||
Ok(query) => Some(query),
|
||||
log_debug_ln!(
|
||||
"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) => {
|
||||
log_error_ln!("{}", error);
|
||||
None
|
||||
|
@ -33,4 +33,8 @@ pub const BOT_TEXT_HANGED_SELF: [&str; 3] = [
|
||||
BOT_TEXT_HANGED_SELF_1,
|
||||
BOT_TEXT_HANGED_SELF_2,
|
||||
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 = "这是个幽灵……";
|
Loading…
Reference in New Issue
Block a user