Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
telegram_bot_antispammer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иванова Мария Кирилловна
telegram_bot_antispammer
Commits
fd84b41f
Commit
fd84b41f
authored
Mar 06, 2025
by
Иванова Мария Кирилловна
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update bot.py
parent
af057b09
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
8 deletions
+38
-8
bot.py
bot.py
+38
-8
No files found.
bot.py
View file @
fd84b41f
...
...
@@ -397,15 +397,46 @@ async def handle_message(message: Message):
# Обработчик сообщений
@dp.message
(
lambda
message
:
message
.
reply_to_message
and
'/spam'
in
message
.
text
.
lower
())
async
def
delete_spam
(
message
:
types
.
Message
):
try
:
#
@dp.message(lambda message: message.reply_to_message and '/spam' in message.text.lower())
#
async def delete_spam(message: types.Message):
#
try:
# Удаляем сообщение с подписью /spam
await
message
.
delete
()
#
await message.delete()
# Удаляем сообщение, на которое был дан ответ
await
message
.
reply_to_message
.
delete
()
except
Exception
as
e
:
logger
.
error
(
"Deleting error:
%
s"
,
e
)
# await message.reply_to_message.delete()
# except Exception as e:
# logger.error("Deleting error: %s", e)
from
aiogram
import
types
import
asyncio
@dp.message
(
Command
(
"spam"
))
async
def
report_spam
(
message
:
types
.
Message
):
if
not
message
.
reply_to_message
:
await
message
.
reply
(
"Эту команду нужно использовать в ответ на сообщение."
)
return
spam_message
=
message
.
reply_to_message
# Получаем список администраторов чата
chat_admins
=
await
bot
.
get_chat_administrators
(
message
.
chat
.
id
)
# Фильтруем только тех, у кого роль "Модератор"
moderators
=
[
f
"@{admin.user.username}"
for
admin
in
chat_admins
if
admin
.
user
.
username
and
not
admin
.
user
.
is_bot
and
admin
.
custom_title
and
"модератор"
in
admin
.
custom_title
.
lower
()
]
if
not
moderators
:
moderators_text
=
"Нет доступных модераторов"
else
:
moderators_text
=
', '
.
join
(
moderators
)
# Оповещение с пингом модераторов
warning_text
=
f
"⚠️ Внимание, замечен спам! {moderators_text}
\n\n
"
warning
=
await
spam_message
.
reply
(
warning_text
)
# Удаляем своё сообщение
await
message
.
delete
()
async
def
main
():
...
...
@@ -416,4 +447,3 @@ async def main():
if
__name__
==
"__main__"
:
SPAM_KEYWORDS
=
preprocess_spam_keywords
(
SPAM_KEYWORDS
)
asyncio
.
run
(
main
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment