This repository was archived by the owner on Nov 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcat.py
More file actions
57 lines (51 loc) · 1.87 KB
/
cat.py
File metadata and controls
57 lines (51 loc) · 1.87 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
from config import BANNED_USERS
from pyrogram import filters
from pyrogram.types import (
CallbackQuery,
InlineKeyboardButton,
InlineKeyboardMarkup,
InputMediaPhoto,
Message,
)
def buttons(url: str) -> InlineKeyboardMarkup:
keyboard = InlineKeyboardMarkup(
[
[InlineKeyboardButton(text="🔗 Link 🔗", url=url)],
[
InlineKeyboardButton(text="🔄 Refresh 🔄", callback_data="refresh_cat"),
InlineKeyboardButton(text="🗑️ Close 🗑️", callback_data="close"),
],
]
)
return keyboard
@app.on_message(filters.command("cat") & ~BANNED_USERS)
async def cat(c, m: Message):
r = await utils.TheApi.request.get("https://api.thecatapi.com/v1/images/search")
if r.status_code == 200:
data = r.json()
cat_url = data[0]["url"]
if cat_url.endswith(".gif"):
await m.reply_animation(
cat_url, caption="meow", reply_markup=buttons(cat_url)
)
else:
await m.reply_photo(cat_url, caption="meow", reply_markup=buttons(cat_url))
else:
await m.reply_text("Failed to fetch cat picture 🙀")
@app.on_callback_query(filters.regex("refresh_cat") & ~BANNED_USERS)
async def refresh_cat(c, m: CallbackQuery):
r = utils.TheApi.request.get("https://api.thecatapi.com/v1/images/search")
if r.status_code == 200:
data = r.json()
cat_url = data[0]["url"]
if cat_url.endswith(".gif"):
await m.edit_message_animation(
cat_url, caption="meow", reply_markup=buttons(cat_url)
)
else:
await m.edit_message_media(
InputMediaPhoto(media=cat_url, caption="meow"),
reply_markup=buttons(cat_url),
)
else:
await m.edit_message_text("Failed to refresh cat picture 🙀")