This repository was archived by the owner on Apr 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
50 lines (36 loc) · 1.51 KB
/
Copy pathexample.py
File metadata and controls
50 lines (36 loc) · 1.51 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
from ICQBot import ICQBot, Dispatcher, executor
from ICQBot.messages import ReceivedMessage
from ICQBot.messages.callback import Callback
from ICQBot.ext.keyboards import InlineKeyboardMarkup, Button
bot = ICQBot("TOKEN")
dp = Dispatcher(bot)
# to repeat a message
@dp.message_handler()
async def test(message: ReceivedMessage):
# print(message)
return await message.reply(message.text)
# to ban an user
@dp.message_handler(commands=["/ban"])
async def ban(message: ReceivedMessage):
payload = message.payloads[-1].payload
user_to_ban = payload.user_id # type: ignore
return print(await bot.removeMembers(message.chat_id, user_to_ban))
# Keyboard
@dp.message_handler(commands="/start")
async def start(message: ReceivedMessage):
keyboard = InlineKeyboardMarkup()
keyboard.addButton(Button(text="Hello", callbackData="World"))
keyboard.addRow()
keyboard.addButton(Button(text="Bye", callbackData="Ok"), row=1)
return await message.reply("Ola", inline_keyboard_markup=keyboard)
# callback handlers
@dp.callback_query_handler(context="callbackData", value="World")
async def answer_world(callback: Callback):
await bot.sendText(callback.message_data.chat_id, "Nyahello")
return await callback.answer(f"Hello {callback.callbackData}")
@dp.callback_query_handler(context="callbackData", value="Ok")
async def answer_ok(callback: Callback):
await bot.sendText(callback.message_data.chat_id, "Orayo")
return await callback.answer("No")
if __name__ == "__main__":
executor(dp)