#
# Copyright (C) 2021-2022 by TeamYukki@Github, < https://github.com/TeamYukki >.
#
# This file is part of < https://github.com/TeamYukki/YukkiMusicBot > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/TeamYukki/YukkiMusicBot/blob/master/LICENSE >
#
# All rights reserved.

import aiohttp
import requests

BASE = "https://batbin.me/"

class Paste(object):
    async def post(self, url: str, *args, **kwargs):
        async with aiohttp.ClientSession() as session:
            async with session.post(url, *args, **kwargs) as resp:
                try:
                    data = await resp.json()
                except Exception:
                    data = await resp.text()
            return data


    async def PasteBin(self, text):
        resp = await self.post(f"{BASE}api/v2/paste", data=text)
        if not resp["success"]:
            return
        link = BASE + resp["message"]
        return link


    async def paste(self, content: str):
        resp = await self.post(f"{BASE}api/v2/paste", data=content)
        if not resp["success"]:
            return
        return BASE + resp["message"]


    async def s_paste(self, message, extension="txt"):
        siteurl = "https://spaceb.in/api/v1/documents/"
        try:
            response = requests.post(
                siteurl, data={"content": message, "extension": extension}
            )
        except Exception as e:
            return {"error": str(e)}
        if response.ok:
            response = response.json()
            if response["error"] != "" and response["status"] < 400:
                return {"error": response["error"]}
            return {
                "url": f"https://spaceb.in/{response['payload']['id']}",
                "raw": f"{siteurl}{response['payload']['id']}/raw",
                "bin": "Spacebin",
            }
        return {"error": "Unable to reach spacebin."}
