Captain Ezio commited on
Commit
84a7ead
·
1 Parent(s): c0d93de

Update utils.py

Browse files
Files changed (1) hide show
  1. Powers/plugins/utils.py +19 -13
Powers/plugins/utils.py CHANGED
@@ -4,6 +4,7 @@ from io import BytesIO
4
  from os import remove
5
 
6
  import aiofiles
 
7
  from gpytranslate import Translator
8
  from pyrogram import enums, filters
9
  from pyrogram.errors import MessageTooLong
@@ -248,9 +249,23 @@ async def github(_, m: Message):
248
  return
249
 
250
 
251
- # paste here
252
  pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
253
- BASE = "https://pasty.lus.pm/"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
 
256
  @Gojo.on_message(command("paste"))
@@ -281,17 +296,8 @@ async def paste_func(_, message: Message):
281
  content = await f.read()
282
 
283
  remove(doc)
284
- resp = await post(f"{BASE}api/v2/pastes", data=content)
285
- if not resp["id"]:
286
- return await message.reply_text(
287
- f"Failed to paste contact to report it",
288
- reply_markup=InlineKeyboardMarkup(
289
- [[InlineKeyboardButton("Report it here",
290
- url=f"https://{SUPPORT_CHANNEL}.t.me"
291
- )]]
292
- )
293
- ,)
294
- link = f"{BASE}{resp['id']}"
295
  kb = [[InlineKeyboardButton(text="Paste Link ", url=link)]]
296
  try:
297
  await m.delete()
 
4
  from os import remove
5
 
6
  import aiofiles
7
+ from aiohttp import ClientSession
8
  from gpytranslate import Translator
9
  from pyrogram import enums, filters
10
  from pyrogram.errors import MessageTooLong
 
249
  return
250
 
251
 
252
+ session = ClientSession()
253
  pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
254
+ BASE = "https://batbin.me/"
255
+
256
+ async def post(url: str, *args, **kwargs):
257
+ async with session.post(url, *args, **kwargs) as resp:
258
+ try:
259
+ data = await resp.json()
260
+ except Exception:
261
+ data = await resp.text()
262
+ return data
263
+
264
+ async def paste(content: str):
265
+ resp = await post(f"{BASE}api/v2/paste", data=content)
266
+ if not resp["success"]:
267
+ return
268
+ return BASE + resp["message"]
269
 
270
 
271
  @Gojo.on_message(command("paste"))
 
296
  content = await f.read()
297
 
298
  remove(doc)
299
+
300
+ link = await paste(content)
 
 
 
 
 
 
 
 
 
301
  kb = [[InlineKeyboardButton(text="Paste Link ", url=link)]]
302
  try:
303
  await m.delete()