Skip to content

Commit

Permalink
Fixing screencapture
Browse files Browse the repository at this point in the history
Signed-off-by: baalajimaestro <[email protected]>
  • Loading branch information
baalajimaestro committed Dec 15, 2018
1 parent 4807795 commit 2d3d00f
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions userbot/modules/screencapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,39 @@
import os
import requests
from telethon import TelegramClient, events
from userbot import bot
from userbot import bot,SCREEN_SHOT_LAYER_ACCESS_KEY


@bot.on(events.NewMessage(pattern=r".screencapture (.*)", outgoing=True))
@bot.on(events.MessageEdited(pattern=r".screencapture (.*)", outgoing=True))
async def _(event):
if not e.text[0].isalpha() and e.text[0] not in ('/','#','@','!'):
if event.fwd_from:
return
if SCREEN_SHOT_LAYER_ACCESS_KEY is None:
await event.edit("Need to get an API key from https://screenshotlayer.com/product \nModule stopping!")
return
await event.edit("Processing ...")
sample_url = "https://api.screenshotlayer.com/api/capture?access_key={}&url={}"
sample_url = "https://api.screenshotlayer.com/api/capture?access_key={}&url={}&fullpage={}&format={}&viewport={}"
input_str = event.pattern_match.group(1)
response_api = requests.get(sample_url.format(SCREEN_SHOT_LAYER_ACCESS_KEY, input_str), stream=True)
temp_file_name = "screenshotlayer.jpg"
with open(temp_file_name, "wb") as fd:
for chunk in response_api.iter_content(chunk_size=128):
fd.write(chunk)
try:
await bot.send_file(
event.chat_id,
temp_file_name,
caption=input_str,
force_document=True,
reply_to=event.message.reply_to_msg_id
)
await event.delete()
except:
response_api = requests.get(sample_url.format(Config.SCREEN_SHOT_LAYER_ACCESS_KEY, input_str, "1", "PNG", "2560x1440"), stream=True)
contentType = response_api.headers['content-type']
if "image" in contentType:
temp_file_name = "screencapture.png"
with open(temp_file_name, "wb") as fd:
for chunk in response_api.iter_content(chunk_size=128):
fd.write(chunk)
try:
await borg.send_file(
event.chat_id,
temp_file_name,
caption=input_str,
force_document=True,
reply_to=event.message.reply_to_msg_id
)
await event.delete()
except:
await event.edit(response_api.text)
os.remove(temp_file_name)
else:
await event.edit(response_api.text)
os.remove(temp_file_name)

0 comments on commit 2d3d00f

Please sign in to comment.