-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathechobot.py
80 lines (64 loc) · 2.45 KB
/
echobot.py
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
75
76
77
78
79
80
from pytdbot import Client, types
import logging
logging.basicConfig(
level=logging.INFO,
format="[%(levelname)s][p %(process)d %(threadName)s][%(created)f][%(filename)s:%(lineno)d][%(funcName)s] %(message)s",
)
client = Client(
token="1088394097:AAQX2DnWiw4ihwiJUhIHOGog8gGOI", # Your bot token
api_id=0,
api_hash="API_HASH",
files_directory="BotDB", # Path where to store TDLib files
database_encryption_key="1234echobot$",
td_verbosity=2, # TDLib verbosity level
td_log=types.LogStreamFile("tdlib.log", 104857600), # Set TDLib log file path
)
@client.on_updateNewMessage()
async def print_message(_: Client, message: types.Message):
print(message)
@client.on_message()
async def echo(_: Client, message: types.Message):
if isinstance(message.content, types.MessageText):
await message.reply_text(message.text, entities=message.entities)
elif isinstance(message.content, types.MessageAnimation):
await message.reply_animation(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
elif isinstance(message.content, types.MessageAudio):
await message.reply_audio(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
elif isinstance(message.content, types.MessageDocument):
await message.reply_document(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
elif isinstance(message.content, types.MessagePhoto):
await message.reply_photo(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
elif isinstance(message.content, types.MessageSticker):
await message.reply_sticker(message.remote_file_id)
elif isinstance(message.content, types.MessageVideo):
await message.reply_video(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
elif isinstance(message.content, types.MessageVoiceNote):
await message.reply_voice(
message.remote_file_id,
caption=message.caption,
caption_entities=message.entities,
)
else:
await message.reply_text("Oops! i don't know how to handle this message.")
# Run the client
client.run()