-
Notifications
You must be signed in to change notification settings - Fork 1
/
unsplash.py
69 lines (56 loc) · 2.31 KB
/
unsplash.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
# feel free to use this in any pyrogram library userbot plugin you'll face no errors
import asyncio
import json
import aiohttp
from pyrogram import Client, enums, filters
from pyrogram.types import Message
from utils.misc import modules_help, prefix
# taken from pyrogram documentation if not works kindly inform me :)
class AioHttp:
async def get_json(link):
async with aiohttp.ClientSession() as session:
async with session.get(link) as resp:
return await resp.json()
async def get_json(link):
async with aiohttp.ClientSession() as session:
async with session.get(link) as resp:
return await resp.json()
async def get_url(self, link):
async with aiohttp.ClientSession() as session:
async with session.get(link) as resp:
return resp.url
@Client.on_message(filters.command("unsplash", prefix) & filters.me)
async def unsplash(client: Client, message: Message):
if len(message.command) > 1 and isinstance(message.command[1], str):
keyword = message.command[1]
if len(message.command) > 2 and int(message.command[2]) < 10:
await message.edit(
"<b>Getting Pictures</b>", parse_mode=enums.ParseMode.HTML
)
await message.edit(
"<b>Getting Picture</b>", parse_mode=enums.ParseMode.HTML
)
count = int(message.command[2])
images = []
while len(images) is not count:
img = await AioHttp().get_url(
f"https://source.unsplash.com/1600x900/?{keyword}"
)
if img not in images:
images.append(img)
for img in images:
await client.send_photo(message.chat.id, str(img))
await message.delete()
return
else:
await message.edit("<b>Getting Picture</b>", parse_mode=enums.ParseMode.HTML)
img = await AioHttp().get_url(
f"https://source.unsplash.com/1600x900/?{keyword}"
)
await asyncio.gather(
message.delete(), client.send_photo(message.chat.id, str(img))
)
modules_help["unsplash"] = {
"unsplash": f"[keyword]*",
"unsplash": f"[keyword]* [number of results you want]*",
}