-
Notifications
You must be signed in to change notification settings - Fork 9
/
example.py
61 lines (50 loc) · 1.55 KB
/
example.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
from hydrogram import Client
from hydrogram.helpers import ikb
from hydrogram.types import CallbackQuery, Message
from Abg import * # type: ignore
app = Client(
name='Abg',
api_id=6,
api_hash='eb06d4abfb49dc3eeb1aeb98ae0f581e',
bot_token="TOKEN",
in_memory=True,
)
@app.on_cmd("start")
async def start(self: Client, ctx: Message):
"""
Sends a Hello World message with an inline button that triggers the hello callback.
"""
await ctx.reply_text(
"Hello World",
reply_markup=ikb([[("Hello", "hello")]])
)
@app.on_cb("hello")
async def hello(_: Client, q: CallbackQuery):
"""
Called when the user presses the "Hello" button in the start command.
"""
await q.answer("Hello From Abg", show_alert=True)
@app.on_cmd("del", group_only=True)
@app.adminsOnly(
permissions=["can_delete_messages", "can_restrict_members"],
is_both=True,
)
async def del_msg(self: Client, m: Message):
"""
Deletes a message from the chat.
If the message is a reply to another message, it deletes that message too.
"""
if m.reply_to_message:
# Delete the replied message
await self.delete_messages(
chat_id=m.chat.id,
message_ids=[m.reply_to_message.id],
)
# Delete the command message
await m.delete()
else:
# If the message is not a reply, reply with an error message
await m.reply_text(text="You need to reply to a message to delete it.", quote=True)
if __name__ == "__main__":
print("Running...")
app.run()