formatting existing plugins

pull/16/head
Shrimadhav U K 2018-08-07 21:16:00 +05:30
parent efee4e55b2
commit 2a58f1aa25
No known key found for this signature in database
GPG Key ID: 599767107164B031
7 changed files with 74 additions and 25 deletions

21
stdplugins/exec.py Normal file
View File

@ -0,0 +1,21 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import subprocess
@borg.on(events.NewMessage(pattern=r"\.exec (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
input_str = event.pattern_match.group(1)
input_command = input_str.split(" ")
try:
t_response = subprocess.check_output(input_command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
await event.edit("Status : FAIL", exc.returncode, exc.output)
else:
x_reponse = t_response.decode("UTF-8")
await event.edit(x_reponse)

View File

@ -10,4 +10,4 @@ async def _(event):
if event.fwd_from:
return
chat = await event.get_input_chat()
await event.edit("-100" + str(chat.channel_id))
await event.edit(event.chat_id)

View File

@ -10,9 +10,7 @@ async def _(event):
if event.fwd_from:
return
if event.reply_to_msg_id:
message_id = event.reply_to_msg_id
previous_message = await borg.get_messages(event.chat_id, limit=1, max_id=message_id+1, min_id=message_id-1)
await event.edit(previous_message[0].stringify())
previous_message = await event.get_reply_message()
await event.edit(previous_message.stringify())
else:
await event.edit(event.stringify())

View File

@ -17,6 +17,6 @@ async def _(event):
input_str = event.pattern_match.group(1)
response_api = requests.get(sample_url.format(input_str, APP_ID)).json()
if response_api["cod"] == 200:
await event.edit(json.dumps(response_api["main"]))
await event.edit(input_str + "\n `" + json.dumps(response_api["main"]) + "`\n")
else:
await event.edit(response_api["message"])

View File

@ -12,19 +12,23 @@ ACCESS_KEY = os.environ.get("SCREEN_SHOT_LAYER_ACCESS_KEY")
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
sample_url = "https://api.screenshotlayer.com/api/capture?access_key={}&url={}"
input_str = event.pattern_match.group(1)
response_api = requests.get(sample_url.format(ACCESS_KEY, input_str), stream=True)
if "invalid_access_key" not in response_api.text:
temp_file_name = "screenshotlayer.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=False)
await event.delete()
except:
await event.edit(response_api.text)
os.remove(temp_file_name)
else:
temp_file_name = "screenshotlayer.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)

View File

@ -10,6 +10,13 @@ from datetime import datetime
current_date_time = "./DOWNLOADS/"
def progress(current, total):
percent = str((current / total) * 100)
await event.edit(
"Upload Progress: {}".format(percent)
)
@borg.on(events.NewMessage(pattern=r".download (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
@ -19,16 +26,19 @@ async def _(event):
os.makedirs(current_date_time)
if event.reply_to_msg_id:
start = datetime.now()
downloaded_file_name = await borg.download_media(await event.get_reply_message(), current_date_time)
downloaded_file_name = await borg.download_media(
await event.get_reply_message(),
current_date_time
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Downloaded to {} in {} seconds.".format(downloaded_file_name, ms))
elif input_str:
url, file_name = input_str.split("|")
r = requests.get(url, stream=True)
await event.edit("Processing ...")
required_file_name = current_date_time + "" + file_name
start = datetime.now()
r = requests.get(url, stream=True)
with open(required_file_name, "wb") as fd:
for chunk in r.iter_content(chunk_size=128):
fd.write(chunk)
@ -46,7 +56,14 @@ async def _(event):
input_str = event.pattern_match.group(1)
if os.path.exists(input_str):
start = datetime.now()
await borg.send_file(event.chat_id, input_str, force_document=True, use_cache=False)
await borg.send_file(
event.chat_id,
input_str,
force_document=True,
use_cache=False,
reply_to=event.message.reply_to_msg_id,
progress_callback=progress
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Uploaded in {} seconds.".format(ms))

View File

@ -5,6 +5,7 @@
from telethon import events
import urbandict
@borg.on(events.NewMessage(pattern="^.ud (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
@ -14,9 +15,17 @@ async def _(event):
try:
mean = urbandict.define(str)
if len(mean) > 0:
await event.edit('Text: **'+str+'**\n\nMeaning: **'+mean[0]['def']+'**\n\n'+'Example: \n__'+mean[0]['example']+'__')
await event.edit(
'Text: **' +
str +
'**\n\nMeaning: **' +
mean[0]['def'] +
'**\n\n' +
'Example: \n__' +
mean[0]['example'] +
'__'
)
else:
await event.edit("No result found for **"+str+"**")
await event.edit("No result found for **" + str + "**")
except:
await event.edit("No result found for **"+str+"**")
await event.edit("No result found for **" + str + "**")