import random
import re
from aiogram import Dispatcher, types
import logging
from aiogram.client.bot import Bot
from aiogram.types import URLInputFile
from aiogram.utils import markdown
from aiohttp import ClientSession
API_TOKEN = 'token'
logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
love_stickers = [
'CAACAgIAAxkBAAEFQ7pizysrJvNe6B7HPXoLnVSkSyOyMQACtRoAAoSCSUoS5hJgrzXqjykE',
'CAACAgIAAxkBAAEFQ7xizyszfazbUw4hQmIR9ypmMFBpEAACLQADnCV8P6B0CYdsqU1pKQQ',
'CAACAgQAAxkBAAEFQ75izys-prd3iJgiRFsT1kuvkdonVwACoQwAAgpqkVE3sQNzBDJf4SkE',
'CAACAgIAAxkBAAEFQ8BizytQkIqGYWA1CZfhxpmdnsoXyQACERQAAutckUsM2SH4Fi-09CkE',
'CAACAgIAAxkBAAEFQ8Jizy5Om5WMSSx3gt41afU3yLuFawACVxsAApOGkUngKiyb-tdiDykE',
'CAACAgIAAxkBAAEFQ8Nizy5OYd2Fb9XXngU9N-R4cxbN9gAC3RcAAl3FkUlm50d_D0UwUikE',
'CAACAgIAAxkBAAEFQ8Rizy5OpM_TrplX020-hJ-9Yeq-nAACYB0AAgXzkUmAsaDDDOgkrCkE',
'CAACAgIAAxkBAAEFQ8Vizy5O-83AwU8u26y9hbrcS59FQQACyhwAAvqCkEkMeQ5b9wAB3t8pBA',
]
async def remove_emoji_from_string(string):
emoji = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
u"\U00002500-\U00002BEF" # chinese char
u"\U00002702-\U000027B0"
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
u"\U0001f926-\U0001f937"
u"\U00010000-\U0010ffff"
u"\u2640-\u2642"
u"\u2600-\u2B55"
u"\u200d"
u"\u23cf"
u"\u23e9"
u"\u231a"
u"\ufe0f" # dingbats
u"\u3030"
"]+", re.UNICODE)
string = re.sub(emoji, '', string)
string = re.sub(r"^\s+", "", string) # удаление пробелов в начале строки
string = re.sub(r"\s+$", "", string) # удаление пробелов в конце строки
string = re.sub(r'[^\w\s]', '', string) # удаление знаков препинания
string = re.sub(r'\s+', ' ', string) # удаление повторяющихся пробелов
return string
@dp.message(commands=['start', 'help'])
async def start(message: types.Message):
await message.reply(
f"Привет!", parse_mode='HTML')
@dp.message()
async def words_handler(message: types.Message):
text = await remove_emoji_from_string(message.text.lower())
if text == "я тебя люблю":
await message.answer("Я тоже тебя люблю!")
sticker_id = random.choice(love_stickers)
await bot.send_sticker(message.from_user.id, sticker_id)
elif text == "фото":
myphotos = await get_my_photo()
image = URLInputFile(random.choice(myphotos), filename='my_photo.jpg')
await bot.send_photo(message.from_user.id, photo=image)
else:
await message.answer("Прости, я тебя не понимаю \nНо я тебя люблю!")
return
async def get_my_photo():
"""get photos from imgur album"""
session = ClientSession()
headers = {'Authorization': "Client-ID clientid"}
response = await session.get('https://api.imgur.com/3/album/album_id/images', headers=headers)
data = await response.json()
images = data['data']
images_list = []
for image in images:
images_list.append(image['link'])
await session.close()
return images_list
if __name__ == '__main__':
dp.run_polling(bot)