This repository was archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
74 lines (64 loc) · 2.95 KB
/
bot.py
File metadata and controls
74 lines (64 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import asyncio
import logging
import json
from aiogram import Bot, Dispatcher, types, F
from aiogram.types import FSInputFile
from aiogram.filters import Command
logging.basicConfig(level=logging.INFO)
bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher()
@dp.message(F.text, Command("start"))
async def cmd_start(message: types.Message):
await message.answer("Привет! Я бот, который отправляет файлы из ответов из других чатов, даже приватных. Просто отправь мне свой ответ с функцией 'Ответить в другом чате' (Или перешли такое) на сообщение , которое ты хочешь получить, и я отправлю его тебе.")
@dp.message(F.text)
async def cmd_start(message: types.Message):
json_data = message.model_dump_json()
data = json.loads(json_data)
file2 = data["external_reply"]
try:
file3 = file2["animation"]
file4 = file3["file_id"]
await message.answer("Загружаю гифку")
print(file4)
file = await bot.get_file(file4)
await bot.download_file(file.file_path, "file.gif")
text_file = FSInputFile("file.gif")
await message.answer_animation(text_file)
except:
try:
file3 = file2["voice"]
file4 = file3["file_id"]
await message.answer("Загружаю голосовое сообщение")
print(file4)
file = await bot.get_file(file4)
await bot.download_file(file.file_path, "file.ogg")
text_file = FSInputFile("file.ogg")
await message.answer_voice(text_file)
except:
try:
file3 = file2["video"]
file4 = file3["file_id"]
await message.answer("Загружаю видео")
print(file4)
file = await bot.get_file(file4)
await bot.download_file(file.file_path, "file.mp4")
text_file = FSInputFile("file.mp4")
await message.answer_video(text_file)
except:
try:
file3 = file2["photo"]
print(file3)
file4 = file3[-1]["file_id"]
await message.answer("Загружаю фото")
print(file4)
file = await bot.get_file(file4)
await bot.download_file(file.file_path, "file.jpg")
text_file = FSInputFile("file.jpg")
await message.answer_photo(text_file)
except:
await message.answer("Не могу обработать этот тип данных")
async def main():
await bot.delete_webhook()
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())