Captain Ezio commited on
Commit
9dbe1e7
·
1 Parent(s): 07091ae

Update utils.py

Browse files
Files changed (1) hide show
  1. Powers/plugins/utils.py +13 -8
Powers/plugins/utils.py CHANGED
@@ -1,4 +1,5 @@
1
  import re
 
2
  from io import BytesIO
3
  from os import remove
4
 
@@ -287,12 +288,15 @@ async def github(_, m: Message):
287
 
288
 
289
  pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
290
- BASE = "https://batbin.me/"
291
-
 
 
 
292
 
293
  def paste(content: str):
294
- resp = resp_post(f"{BASE}api/v2/paste", data=content)
295
- if resp.status_code != 200:
296
  return
297
  resp = resp.json()
298
  return BASE + resp["result"]['key']
@@ -311,7 +315,8 @@ async def paste_func(_, message: Message):
311
  return await m.edit("Only text and documents are supported")
312
 
313
  if r.text:
314
- content = {'content':f'{r.text}'}
 
315
  if r.document:
316
  if r.document.file_size > 40000:
317
  return await m.edit("You can only paste files smaller than 40KB.")
@@ -320,17 +325,17 @@ async def paste_func(_, message: Message):
320
  return await m.edit("Only text files can be pasted.")
321
 
322
  doc = await message.reply_to_message.download()
323
-
324
  async with aiofiles.open(doc, mode="r") as f:
325
  fdata = await f.read()
326
  content = {'content':fdata}
327
 
328
  remove(doc)
329
- link = paste(content)
330
  if not link:
331
  await m.reply_text("Failed to post!")
332
  return
333
- kb = [[InlineKeyboardButton(text="Paste Link ", url=link)]]
334
  await m.delete()
335
  try:
336
  await message.reply_text("Here's your paste", reply_markup=InlineKeyboardMarkup(kb))
 
1
  import re
2
+ import json
3
  from io import BytesIO
4
  from os import remove
5
 
 
288
 
289
 
290
  pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
291
+ BASE = "https://pasty.lus.pm/"
292
+ headers = {
293
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36",
294
+ "content-type": "application/json",
295
+ }
296
 
297
  def paste(content: str):
298
+ resp = resp_post(f"{BASE}api/v1/pastes", data=content, headers=headers)
299
+ if resp.ok:
300
  return
301
  resp = resp.json()
302
  return BASE + resp["result"]['key']
 
315
  return await m.edit("Only text and documents are supported")
316
 
317
  if r.text:
318
+ content = {'content':json.dumps(f'{r.text}')}
319
+ exe = "txt"
320
  if r.document:
321
  if r.document.file_size > 40000:
322
  return await m.edit("You can only paste files smaller than 40KB.")
 
325
  return await m.edit("Only text files can be pasted.")
326
 
327
  doc = await message.reply_to_message.download()
328
+ exe = doc.rsplit(".".1)[-1]
329
  async with aiofiles.open(doc, mode="r") as f:
330
  fdata = await f.read()
331
  content = {'content':fdata}
332
 
333
  remove(doc)
334
+ link = paste(content) + f".{exe}"
335
  if not link:
336
  await m.reply_text("Failed to post!")
337
  return
338
+ kb = [[InlineKeyboardButton(text="📍 Paste 📍", url=link)]]
339
  await m.delete()
340
  try:
341
  await message.reply_text("Here's your paste", reply_markup=InlineKeyboardMarkup(kb))