group blacklist
This commit is contained in:
parent
325c0b8207
commit
df99275455
@ -7,6 +7,7 @@ secretGenerator:
|
||||
files:
|
||||
- config/DATABASE_URI
|
||||
- config/TGBOT_TOKEN
|
||||
- config/GROUP_BANNED
|
||||
images:
|
||||
- name: <Image>
|
||||
newName: ghcr.io/senseab/hangitbot
|
||||
|
@ -75,14 +75,21 @@
|
||||
description = lib.mdDoc "Custom telegram api URI";
|
||||
};
|
||||
|
||||
groupBanned = mkOption {
|
||||
type = types.listOf types.int;
|
||||
default = [];
|
||||
description = lib.mdDoc "GroupID blacklisted";
|
||||
};
|
||||
|
||||
extraOptions = mkOption {
|
||||
type = types.str;
|
||||
description = lib.mdDoc "Extra option for bot.";
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
args = "${cfg.extraOptions} ${if isString cfg.tgUri then "--api-uri ${escapeShellArg cfg.tgUri}" else ""}";
|
||||
args = "${cfg.extraOptions} ${if cfg?tgUri then "--api-uri ${escapeShellArg cfg.tgUri}" else ""} ${if cfg?groupBanned then concatStringsSep " " (lists.concatMap (group: ["-b ${group}"]) cfg.groupBanned) else ""}";
|
||||
in mkIf cfg.enable {
|
||||
systemd.services.hangitbot = {
|
||||
wantedBy = ["multi-uesr.target"];
|
||||
|
@ -24,4 +24,8 @@ pub struct Args {
|
||||
/// Api Server URL
|
||||
#[clap(long, value_parser, env = "API_URL", default_value=DEFAULT_API_URL)]
|
||||
pub api_url: String,
|
||||
|
||||
/// GroupID blacklisted
|
||||
#[clap(short = 'b', long, value_parser, env = "GROUP_BANNED", value_delimiter = ',', num_args = 1..)]
|
||||
pub group_banned: Vec<i64>
|
||||
}
|
||||
|
18
src/main.rs
18
src/main.rs
@ -19,7 +19,7 @@ use teloxide::{
|
||||
};
|
||||
use utils::message_handler;
|
||||
use wd_log::{
|
||||
log_debug_ln, log_error_ln, log_info_ln, log_panic, set_level, set_prefix, DEBUG, INFO,
|
||||
log_debug_ln, log_error_ln, log_info_ln, log_panic, set_level, set_prefix, DEBUG, INFO, log_warn_ln,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@ -56,7 +56,11 @@ async fn main() {
|
||||
.branch(
|
||||
Update::filter_message()
|
||||
.branch(dptree::entry().filter_command::<Commands>().endpoint(
|
||||
|db: Controller, bot: Bot, message: Message, cmd: Commands| async move {
|
||||
|db: Controller, black_list: Vec<i64>, bot: Bot, message: Message, cmd: Commands| async move {
|
||||
if black_list.contains(&message.chat.id.0) {
|
||||
log_warn_ln!("banned group dectected: {:?}", message.chat.id);
|
||||
return Ok(());
|
||||
}
|
||||
let r = match cmd {
|
||||
Commands::Help => help_handler(&bot, &message).await,
|
||||
Commands::About => about_handler(&bot, &message).await,
|
||||
@ -75,8 +79,12 @@ async fn main() {
|
||||
))
|
||||
.branch(
|
||||
dptree::filter(|msg: Message| msg.chat.is_group() || msg.chat.is_supergroup())
|
||||
.endpoint(|db: Controller, msg: Message, me: Me| async move {
|
||||
let r = message_handler(&db, msg, &me).await;
|
||||
.endpoint(|db: Controller, message: Message, me: Me, black_list: Vec<i64>| async move {
|
||||
if black_list.contains(&message.chat.id.0) {
|
||||
log_warn_ln!("banned group dectected: {:?}", message.chat.id);
|
||||
return Ok(());
|
||||
}
|
||||
let r = message_handler(&db, message, &me).await;
|
||||
match r {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => {
|
||||
@ -99,7 +107,7 @@ async fn main() {
|
||||
));
|
||||
|
||||
Dispatcher::builder(bot, handler)
|
||||
.dependencies(dptree::deps![db_controller, me])
|
||||
.dependencies(dptree::deps![db_controller, me, args.group_banned])
|
||||
.default_handler(|upd| async move { log_debug_ln!("unhandled update: {:?}", upd) })
|
||||
.enable_ctrlc_handler()
|
||||
.build()
|
||||
|
Loading…
Reference in New Issue
Block a user