@dp.message_handler(text='Текст')
async def test(message: types.Message):
await bot.send_message(message.from_user.id,reply_markup=keybord)
@dp.message_handler(content_type=['text'])
async def test(message: types.Message):
if message.text = "Текст":
await bot.send_message(message.from_user.id,reply_markup=keybord)
await bot.send_message(message.from_user.id,reply_markup=keybord)
await message.answer("Хмм", reply_markup=keybord )
import asyncio
from contextlib import suppress
from aiogram import types
from aiogram.utils.exceptions import (MessageToEditNotFound, MessageCantBeEdited, MessageCantBeDeleted,
MessageToDeleteNotFound)
async def delete_message(message: types.Message, sleep_time: int = 0):
await asyncio.sleep(sleep_time)
with suppress(MessageCantBeDeleted, MessageToDeleteNotFound):
await message.delete()
msg = await message.reply("Я удалюсь через 30 секунд")
asyncio.create_task(delete_message(msg, 30)
@bot.message_handler(content_types=['text'])
def start_message(message):
text = message.text.lower()
print(text)
if text == 'monday_1' :
m1 = open('photo01.jpg', 'rb')
bot.send_photo(message.chat.id, m1)
if text == 'monday_2':
m2 = open('photo02.jpg', 'rb')
bot.send_photo(message.chat.id, m2)
import time as tm
spams = {}
msgs = 4 # Messages in
max = 5 # Seconds
ban = 300 # Seconds
def is_spam(user_id):
try:
usr = spams[user_id]
usr["messages"] += 1
except:
spams[user_id] = {"next_time": int(tm.time()) + max, "messages": 1, "banned": 0}
usr = spams[user_id]
if usr["banned"] >= int(tm.time()):
return True
else:
if usr["next_time"] >= int(tm.time()):
if usr["messages"] >= msgs:
spams[user_id]["banned"] = tm.time() + ban
# text = """You're banned for {} minutes""".format(ban/60)
# bot.send_message(user_id, text)
# User is banned! alert him...
return True
else:
spams[user_id]["messages"] = 1
spams[user_id]["next_time"] = int(tm.time()) + max
return False
@dp.message_handler()
async def echo_message(msg: types.Message):
await bot.send_message(msg.from_user.id, msg.text)
@dp.message_handler(content_types=ContentType.ANY)
async def unknown_message(msg: types.Message):
message_text = text(emojize('Я не знаю, что с этим делать :astonished:'),
italic('\nЯ просто напомню,'), 'что есть',
code('команда'), '/help')
await msg.reply(message_text, parse_mode=ParseMode.MARKDOWN)