Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
064565ff00 | ||
|
90fdef4363 | ||
|
df99275455 | ||
|
325c0b8207 |
@@ -7,7 +7,8 @@ secretGenerator:
|
|||||||
files:
|
files:
|
||||||
- config/DATABASE_URI
|
- config/DATABASE_URI
|
||||||
- config/TGBOT_TOKEN
|
- config/TGBOT_TOKEN
|
||||||
|
- config/GROUP_BANNED
|
||||||
images:
|
images:
|
||||||
- name: <Image>
|
- name: <Image>
|
||||||
newName: ghcr.io/senseab/hangitbot
|
newName: ghcr.io/senseab/hangitbot
|
||||||
newTag: v0.0.3
|
newTag: v0.1.2
|
||||||
|
@@ -75,14 +75,21 @@
|
|||||||
description = lib.mdDoc "Custom telegram api URI";
|
description = lib.mdDoc "Custom telegram api URI";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
groupBanned = mkOption {
|
||||||
|
type = types.listOf types.int;
|
||||||
|
default = [];
|
||||||
|
description = lib.mdDoc "GroupID blacklisted";
|
||||||
|
};
|
||||||
|
|
||||||
extraOptions = mkOption {
|
extraOptions = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = lib.mdDoc "Extra option for bot.";
|
description = lib.mdDoc "Extra option for bot.";
|
||||||
|
default = "";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
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 {
|
in mkIf cfg.enable {
|
||||||
systemd.services.hangitbot = {
|
systemd.services.hangitbot = {
|
||||||
wantedBy = ["multi-uesr.target"];
|
wantedBy = ["multi-uesr.target"];
|
||||||
|
@@ -24,4 +24,8 @@ pub struct Args {
|
|||||||
/// Api Server URL
|
/// Api Server URL
|
||||||
#[clap(long, value_parser, env = "API_URL", default_value=DEFAULT_API_URL)]
|
#[clap(long, value_parser, env = "API_URL", default_value=DEFAULT_API_URL)]
|
||||||
pub api_url: String,
|
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>
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ use teloxide::{
|
|||||||
},
|
},
|
||||||
RequestError,
|
RequestError,
|
||||||
};
|
};
|
||||||
use wd_log::{log_error_ln, log_debug_ln};
|
use wd_log::{log_debug_ln, log_error_ln};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db_controller::Controller,
|
db_controller::Controller,
|
||||||
@@ -23,7 +23,7 @@ pub async fn inline_menu(db: &Controller, bot: &Bot, q: InlineQuery) -> Result<(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|n| {
|
.map(|n| {
|
||||||
InlineQueryResult::Article(InlineQueryResultArticle::new(
|
InlineQueryResult::Article(InlineQueryResultArticle::new(
|
||||||
n.name.clone(),
|
format!("{},{}", n.id, n.name),
|
||||||
format!("{} {}", BOT_TEXT_INLINE_HANG, n.name),
|
format!("{} {}", BOT_TEXT_INLINE_HANG, n.name),
|
||||||
InputMessageContent::Text(InputMessageContentText::new(hangit_text(
|
InputMessageContent::Text(InputMessageContentText::new(hangit_text(
|
||||||
n.name.clone(),
|
n.name.clone(),
|
||||||
@@ -37,15 +37,23 @@ pub async fn inline_menu(db: &Controller, bot: &Bot, q: InlineQuery) -> Result<(
|
|||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
results.push(InlineQueryResult::Article(InlineQueryResultArticle::new(
|
log_debug_ln!("{:?}", results);
|
||||||
name.clone(),
|
|
||||||
format!("{} {}", BOT_TEXT_INLINE_HANG, name),
|
if results.is_empty() {
|
||||||
InputMessageContent::Text(InputMessageContentText::new(hangit_text(
|
results.push(InlineQueryResult::Article(InlineQueryResultArticle::new(
|
||||||
name,
|
format!("{},{}", 0, name),
|
||||||
!IS_SELF,
|
format!("{} {}", BOT_TEXT_INLINE_HANG, name.clone()),
|
||||||
!NEED_ESCAPE,
|
InputMessageContent::Text(InputMessageContentText::new(hangit_text(
|
||||||
))),
|
name.clone(),
|
||||||
)));
|
!IS_SELF,
|
||||||
|
!NEED_ESCAPE,
|
||||||
|
))),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if name.starts_with("@") {
|
||||||
|
results = vec![]
|
||||||
|
}
|
||||||
|
|
||||||
bot.answer_inline_query(&q.id, results).send().await?;
|
bot.answer_inline_query(&q.id, results).send().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -53,8 +61,16 @@ pub async fn inline_menu(db: &Controller, bot: &Bot, q: InlineQuery) -> Result<(
|
|||||||
|
|
||||||
pub async fn inline_anwser(db: &Controller, a: ChosenInlineResult) -> Result<(), RequestError> {
|
pub async fn inline_anwser(db: &Controller, a: ChosenInlineResult) -> Result<(), RequestError> {
|
||||||
log_debug_ln!("{:#?}", a);
|
log_debug_ln!("{:#?}", a);
|
||||||
|
|
||||||
if let Err(err) = db.hangit(&a.result_id, ChatId(0)).await {
|
let mut c: Vec<&str> = a.result_id.split(",").collect();
|
||||||
|
c.remove(0);
|
||||||
|
let result_id = c.concat();
|
||||||
|
|
||||||
|
if result_id == "@" {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(err) = db.hangit(&result_id, ChatId(0)).await {
|
||||||
log_error_ln!("{:?}", err);
|
log_error_ln!("{:?}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/main.rs
18
src/main.rs
@@ -19,7 +19,7 @@ use teloxide::{
|
|||||||
};
|
};
|
||||||
use utils::message_handler;
|
use utils::message_handler;
|
||||||
use wd_log::{
|
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]
|
#[tokio::main]
|
||||||
@@ -56,7 +56,11 @@ async fn main() {
|
|||||||
.branch(
|
.branch(
|
||||||
Update::filter_message()
|
Update::filter_message()
|
||||||
.branch(dptree::entry().filter_command::<Commands>().endpoint(
|
.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 {
|
let r = match cmd {
|
||||||
Commands::Help => help_handler(&bot, &message).await,
|
Commands::Help => help_handler(&bot, &message).await,
|
||||||
Commands::About => about_handler(&bot, &message).await,
|
Commands::About => about_handler(&bot, &message).await,
|
||||||
@@ -75,8 +79,12 @@ async fn main() {
|
|||||||
))
|
))
|
||||||
.branch(
|
.branch(
|
||||||
dptree::filter(|msg: Message| msg.chat.is_group() || msg.chat.is_supergroup())
|
dptree::filter(|msg: Message| msg.chat.is_group() || msg.chat.is_supergroup())
|
||||||
.endpoint(|db: Controller, msg: Message, me: Me| async move {
|
.endpoint(|db: Controller, message: Message, me: Me, black_list: Vec<i64>| async move {
|
||||||
let r = message_handler(&db, msg, &me).await;
|
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 {
|
match r {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -99,7 +107,7 @@ async fn main() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
Dispatcher::builder(bot, handler)
|
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) })
|
.default_handler(|upd| async move { log_debug_ln!("unhandled update: {:?}", upd) })
|
||||||
.enable_ctrlc_handler()
|
.enable_ctrlc_handler()
|
||||||
.build()
|
.build()
|
||||||
|
Reference in New Issue
Block a user