-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathkeyboardBot.py
124 lines (113 loc) · 4.29 KB
/
keyboardBot.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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(
api_id=0, # Your api_id. You can get it from https://my.telegram.org/
api_hash="API_HASH", # Your api_hash. You can get it from https://my.telegram.org/
database_encryption_key="1234echobot$", # Your database encryption key
token="1088394097:AAQX2DnWiw4ihwiJUhIHOGog8gGOI", # Your bot token. You can get it from https://t.me/botfather
files_directory="BotDB", # Path where to store TDLib files
workers=2, # Number of workers
td_verbosity=2, # TDLib verbosity level
td_log=types.LogStreamFile("tdlib.log", 104857600), # Set TDLib log file path
)
@client.on_message()
async def start(c: Client, message: types.Message):
if message.text == "/start":
text = "Hello {}!\n".format(await message.mention("html"))
text += "Here is some bot commands:\n\n"
text += "- /keyboard - show keyboard\n"
text += "- /inline - show inline keyboard\n"
text += "- /remove - remove keyboard\n"
text += "- /force - force reply"
await message.reply_text(
text,
reply_markup=types.ReplyMarkupInlineKeyboard(
[
[
types.InlineKeyboardButton(
text="GitHub",
type=types.InlineKeyboardButtonTypeUrl(
"https://github.com/pytdbot/client"
),
)
]
]
),
)
@client.on_message()
async def commands(c: Client, message: types.Message):
if message.text == "/inline":
await message.reply_text(
"This is a Inline keyboard",
reply_markup=types.ReplyMarkupInlineKeyboard(
[
[
types.InlineKeyboardButton(
text="OwO",
type=types.InlineKeyboardButtonTypeCallback(b"OwO"),
),
types.InlineKeyboardButton(
text="UwU",
type=types.InlineKeyboardButtonTypeCallback(b"UwU"),
),
],
]
),
)
elif message.text == "/keyboard":
await message.reply_text(
"This is a keyboard",
reply_markup=types.ReplyMarkupShowKeyboard(
[
[
types.KeyboardButton(
"OwO", type=types.KeyboardButtonTypeText()
),
types.KeyboardButton(
"UwU", type=types.KeyboardButtonTypeText()
),
],
],
one_time=True,
resize_keyboard=True,
),
)
elif message.text == "/remove":
await message.reply_text(
"Keyboards removed",
reply_markup=types.ReplyMarkupRemoveKeyboard(),
)
elif message.text == "/force":
await message.reply_text(
"This is a force reply",
reply_markup=types.ReplyMarkupForceReply(),
)
elif message.text:
if "/start" not in message.text:
await message.reply_text('You said "{}"'.format(message.text))
@client.on_updateNewCallbackQuery()
async def callback_query(c: Client, message: types.UpdateNewCallbackQuery):
if message.payload.data:
await c.editTextMessage(
message.chat_id,
message.message_id,
"You pressed {}".format(message.payload.data.decode()),
reply_markup=types.ReplyMarkupInlineKeyboard(
[
[
types.InlineKeyboardButton(
text="GitHub",
type=types.InlineKeyboardButtonTypeUrl(
"https://github.com/pytdbot/client"
),
)
]
]
),
)
# Run the client
client.run()