Skip to content

Commit

Permalink
Added /start message
Browse files Browse the repository at this point in the history
  • Loading branch information
f213 committed Jul 12, 2023
1 parent 6fbd067 commit 54427b6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from telegram import Message, Update
from telegram.ext import Application, ContextTypes, MessageHandler
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler
from telegram.ext.filters import TEXT, BaseFilter

import text
Expand Down Expand Up @@ -28,14 +28,27 @@ async def log_message(message: Message | None, action: str | None = ''):
)


async def delete(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def delete(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Delete a message"""
message = update.message or update.edited_message

if message is not None:
await log_message(message, action='delete')
await message.delete()


async def introduce_myself(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if update.effective_chat is not None:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="""
Это бот, который чистит спам из телеграм-комментов. Чтобы он заработал — добавьте его как админа в дискуссионную группу канала. Не забудьте разрешить удалять сообщения.
По всем вопросам пишите [email protected]
""",
)


def delete_messages_that_match(*filters: BaseFilter) -> MessageHandler:
"""Sugar for quick adding delete message callbacks"""
return MessageHandler(callback=delete, filters=with_default_filters(*filters))
Expand All @@ -53,6 +66,8 @@ def delete_messages_that_match(*filters: BaseFilter) -> MessageHandler:

bot = Application.builder().token(bot_token).build()

bot.add_handler(CommandHandler('start', introduce_myself))

bot.add_handler(delete_messages_that_match(ContainsTelegramContact()))
bot.add_handler(delete_messages_that_match(ContainsLink()))
bot.add_handler(delete_messages_that_match(IsMessageOnBehalfOfChat()))
Expand All @@ -64,8 +79,10 @@ def delete_messages_that_match(*filters: BaseFilter) -> MessageHandler:

create_tables() # type: ignore
bot.add_handler(
MessageHandler(filters=TEXT,
callback=lambda update, context: log_message(update.message or update.edited_message)),
MessageHandler(
filters=TEXT,
callback=lambda update, context: log_message(update.message or update.edited_message),
),
)

if in_production():
Expand Down

0 comments on commit 54427b6

Please sign in to comment.