update to teloxide 17 and add parameter to enable the manga filter
This commit is contained in:
@@ -13,7 +13,7 @@ pub fn check_stiker(msg: Message) -> bool {
|
||||
None => return false,
|
||||
};
|
||||
let db = database::Database::get_database();
|
||||
db.media_is_banned(stiker.unique_id.as_str(), database::T_STIKER)
|
||||
db.media_is_banned(&stiker.unique_id.to_string(), database::T_STIKER)
|
||||
}
|
||||
|
||||
pub fn check_gif(msg: Message) -> bool {
|
||||
@@ -22,7 +22,7 @@ pub fn check_gif(msg: Message) -> bool {
|
||||
None => return false,
|
||||
};
|
||||
let db = database::Database::get_database();
|
||||
db.media_is_banned(gif.unique_id.as_str(), database::T_GIF)
|
||||
db.media_is_banned(&gif.unique_id.to_string(), database::T_GIF)
|
||||
}
|
||||
|
||||
pub fn check_photo(msg: Message) -> bool {
|
||||
@@ -30,7 +30,7 @@ pub fn check_photo(msg: Message) -> bool {
|
||||
Some(s) => {
|
||||
let db = database::Database::get_database();
|
||||
for p in s {
|
||||
if db.media_is_banned(p.file.unique_id.as_str(), database::T_PHOTO) {
|
||||
if db.media_is_banned(&p.file.unique_id.to_string(), database::T_PHOTO) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ fn insert_ban_stiker(msg: Message) -> anyhow::Result<()> {
|
||||
Some(s) => {
|
||||
let db = database::Database::get_database();
|
||||
match db.add_media(
|
||||
s.file.unique_id.as_str(),
|
||||
&s.file.unique_id.to_string(),
|
||||
msg.chat.id.to_string().as_str(),
|
||||
database::T_STIKER,
|
||||
) {
|
||||
@@ -77,7 +77,7 @@ fn insert_ban_gif(msg: Message) -> anyhow::Result<()> {
|
||||
Some(s) => {
|
||||
let db = database::Database::get_database();
|
||||
match db.add_media(
|
||||
s.file.unique_id.as_str(),
|
||||
&s.file.unique_id.to_string(),
|
||||
msg.chat.id.to_string().as_str(),
|
||||
database::T_GIF,
|
||||
) {
|
||||
@@ -95,7 +95,7 @@ fn insert_ban_photo(msg: Message) -> anyhow::Result<()> {
|
||||
let db = database::Database::get_database();
|
||||
for p in s {
|
||||
match db.add_media(
|
||||
p.file.unique_id.as_str(),
|
||||
&p.file.unique_id.to_string(),
|
||||
msg.chat.id.to_string().as_str(),
|
||||
database::T_PHOTO,
|
||||
) {
|
||||
@@ -111,7 +111,7 @@ fn insert_ban_photo(msg: Message) -> anyhow::Result<()> {
|
||||
|
||||
async fn is_admin(msg: Message, bot: Bot) -> bool {
|
||||
match bot
|
||||
.get_chat_member(msg.chat.id, msg.from().unwrap().id)
|
||||
.get_chat_member(msg.chat.id, msg.from.unwrap().id)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
use std::collections::LinkedList;
|
||||
use std::sync::RwLock;
|
||||
#[cfg(not(test))]
|
||||
use std::fs;
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
const ALLOW_PATH: &str = "/opt/mini_admin_bot/allow_users";
|
||||
#[cfg(not(debug_assertions))]
|
||||
const POLE_PATH: &str = "/opt/mini_admin_bot/allow_pole";
|
||||
#[cfg(not(debug_assertions))]
|
||||
const MANGA_PATH: &str = "/opt/mini_admin_bot/anti_manga";
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
const ALLOW_PATH: &str = "allow_users";
|
||||
#[cfg(debug_assertions)]
|
||||
const POLE_PATH: &str = "allow_pole";
|
||||
#[cfg(debug_assertions)]
|
||||
const MANGA_PATH: &str = "anti_manga";
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn read_ids<'a>(path: &str) -> LinkedList<String> {
|
||||
@@ -37,6 +41,7 @@ fn read_ids<'a>(path: &str) -> LinkedList<String> {
|
||||
pub struct GroupPermissions {
|
||||
aproved_groups: RwLock<LinkedList<String>>,
|
||||
party_groups: RwLock<LinkedList<String>>,
|
||||
manga_filtered_groups: RwLock<LinkedList<String>>,
|
||||
}
|
||||
|
||||
impl GroupPermissions {
|
||||
@@ -44,6 +49,7 @@ impl GroupPermissions {
|
||||
Self {
|
||||
aproved_groups: RwLock::new(read_ids(ALLOW_PATH)),
|
||||
party_groups: RwLock::new(read_ids(POLE_PATH)),
|
||||
manga_filtered_groups: RwLock::new(read_ids(MANGA_PATH)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +60,10 @@ impl GroupPermissions {
|
||||
pub fn compar_party(&self, id: &String) -> bool {
|
||||
self.party_groups.read().unwrap().contains(id)
|
||||
}
|
||||
|
||||
pub fn compar_manga_filtered(&self, id: &String) -> bool {
|
||||
self.manga_filtered_groups.read().unwrap().contains(id)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,11 +5,16 @@ use crate::telegram_utils;
|
||||
pub async fn take_actions(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
_ = bot.delete_message(msg.chat.id, msg.id).await;
|
||||
_ = bot.send_message(msg.chat.id, format!("Los mensajes con ficheros ejecutables no están permitidos\nAlerta para el usuario {}.\nSi consideras que ha sido un error ponte en contacto con un administrador", telegram_utils::get_alias(&msg))).await;
|
||||
let user = match msg.from() {
|
||||
let user = match msg.from {
|
||||
Some(user) => user,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let mut permissions = msg.chat.permissions().unwrap_or(ChatPermissions::empty());
|
||||
let mut permissions = bot
|
||||
.get_chat(msg.chat.id)
|
||||
.await
|
||||
.unwrap()
|
||||
.permissions()
|
||||
.unwrap_or(ChatPermissions::empty());
|
||||
permissions.remove(ChatPermissions::SEND_OTHER_MESSAGES);
|
||||
permissions.insert(ChatPermissions::SEND_MESSAGES);
|
||||
let restrict = bot.restrict_chat_member(msg.chat.id, user.id, permissions);
|
||||
|
||||
@@ -75,7 +75,7 @@ pub async fn run() {
|
||||
)
|
||||
.branch(
|
||||
dptree::filter(move |msg: Message| {
|
||||
is_photo(msg.clone()) && p2.compar_party(&msg.chat.id.to_string())
|
||||
is_photo(msg.clone()) && p2.compar_manga_filtered(&msg.chat.id.to_string())
|
||||
})
|
||||
.endpoint(|msg: Message, bot: Bot| spoiler_mangas::check_image(msg, bot)),
|
||||
)
|
||||
@@ -154,7 +154,7 @@ fn is_photo(msg: Message) -> bool {
|
||||
}
|
||||
|
||||
fn is_channel_user(msg: Message) -> bool {
|
||||
match msg.from() {
|
||||
match msg.from {
|
||||
Some(u) => u.is_channel(),
|
||||
None => false,
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ fn check_user_points(msg: &Message, rw: Rewards) -> bool {
|
||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||
let ret = data.check_user_pole(
|
||||
&msg.chat.id.to_string(),
|
||||
&msg.from().unwrap().id.to_string(),
|
||||
&msg.from.clone().unwrap().id.to_string(),
|
||||
&get_actual_day(),
|
||||
);
|
||||
check_group_points(msg, rw) && (ret == 0)
|
||||
@@ -93,7 +93,7 @@ pub async fn exe_pole(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
if pole_conditions(msg.clone()) {
|
||||
do_pole(
|
||||
&msg.chat.id.to_string(),
|
||||
&*msg.from().unwrap().id.to_string(),
|
||||
&msg.from.clone().unwrap().id.to_string(),
|
||||
&get_alias(&msg),
|
||||
);
|
||||
bot.send_message(msg.chat.id, format!("{} ha hecho la pole", get_alias(&msg)))
|
||||
@@ -101,7 +101,7 @@ pub async fn exe_pole(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
} else if plata_conditions(msg.clone()) {
|
||||
do_plata(
|
||||
&msg.chat.id.to_string(),
|
||||
&*msg.from().unwrap().id.to_string(),
|
||||
&msg.from.clone().unwrap().id.to_string(),
|
||||
&get_alias(&msg),
|
||||
);
|
||||
bot.send_message(
|
||||
@@ -112,7 +112,7 @@ pub async fn exe_pole(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
} else if bronce_conditions(msg.clone()) {
|
||||
do_fail(
|
||||
&msg.chat.id.to_string(),
|
||||
&*msg.from().unwrap().id.to_string(),
|
||||
&msg.from.clone().unwrap().id.to_string(),
|
||||
&get_alias(&msg),
|
||||
);
|
||||
bot.send_message(msg.chat.id, format!("{} buen fail", get_alias(&msg)))
|
||||
|
||||
@@ -124,12 +124,12 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
id = match id {
|
||||
Some(i) => {
|
||||
if i.1 > p.width {
|
||||
Some((p.clone().file.id, p.clone().width))
|
||||
Some((p.clone().file.id.to_string(), p.clone().width))
|
||||
} else {
|
||||
Some(i)
|
||||
}
|
||||
}
|
||||
None => Some((p.clone().file.id, p.clone().width)),
|
||||
None => Some((p.clone().file.id.to_string(), p.clone().width)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,10 @@ pub async fn check_image(msg: Message, bot: Bot) -> anyhow::Result<()> {
|
||||
bot.delete_message(msg.chat.id, msg.id).await?;
|
||||
let response = match id {
|
||||
Some(i) => bot
|
||||
.send_photo(msg.chat.id, teloxide::types::InputFile::file_id(i.0))
|
||||
.send_photo(
|
||||
msg.chat.id,
|
||||
teloxide::types::InputFile::file_id(teloxide::types::FileId(i.0)),
|
||||
)
|
||||
.has_spoiler(true),
|
||||
None => match msg.photo().unwrap().iter().max_by_key(|p| p.width) {
|
||||
Some(f) => bot
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub fn get_alias(msg: &teloxide::prelude::Message) -> String {
|
||||
match &msg.from().unwrap().username {
|
||||
Some(alias) => format!("@{}",alias),
|
||||
None => format!("{}",&*msg.from().unwrap().first_name),
|
||||
match &msg.from.clone().unwrap().username {
|
||||
Some(alias) => format!("@{}", alias),
|
||||
None => format!("{}", &*msg.from.clone().unwrap().first_name),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user