Skip to content

Commit

Permalink
Some new features I guess
Browse files Browse the repository at this point in the history
  • Loading branch information
tookender committed Oct 6, 2023
1 parent e2625fc commit 889674e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
password: ${{ secrets.SSH_PASSWORD }}
port: 22
script: |
cd Korii-Bot
cd personal/Korii-Bot
git pull
docker build -t korii-bot .
docker stop korii-bot
docker rm korii-bot
docker run --name korii-bot -d korii-bot
sudo docker build -t korii-bot .
sudo docker stop korii-bot
sudo docker rm korii-bot
sudo docker run --name korii-bot -d korii-bot
3 changes: 2 additions & 1 deletion extensions/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from .ping import PingCog
from .source import SourceCog
from .embed import EmbedCog
from .download import DownloadCog


class Utility(ConfigCog, InfoCog, NeofetchCog, PingCog, SourceCog, EmbedCog):
class Utility(ConfigCog, InfoCog, NeofetchCog, PingCog, SourceCog, EmbedCog, DownloadCog):
pass


Expand Down
68 changes: 68 additions & 0 deletions extensions/utility/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import time
import discord
from discord import app_commands
from discord.ext import commands

from bot import Korii
import aiohttp
import humanfriendly


class DownloadCog(commands.Cog):
def __init__(self, bot: Korii):
self.bot = bot

@app_commands.command()
async def download(self, interaction: discord.Interaction, url: str):
response = await self.bot.session.post(
"https://cobalt.tools/api/json",
json=dict(
url=url,
vCodec="h264",
vQuality="720",
aFormat="mp3",
isAudiOnly=False,
isTTFullAudio=False,
isAUdioMuted=False,
dubLang=False,
disableMetadata=False,
),
headers={"Content-Type": "application/json", "Accept": "application/json"},
)

status = response.status
json = await response.json()

if status != 200:
return await interaction.response.send_message(f"❌ | {json['text']}", ephemeral=True)

await interaction.response.send_message("▶️ | downloading...", ephemeral=True)

start = time.time()

url = json["url"]
video = await self.bot.session.get(url)
video_data = await video.read()
filename = aiohttp.parse_content_disposition(video.headers["Content-Disposition"])[1]["filename"]

if video.ok is False:
json = await video.json()
return await interaction.response.send_message(f"❌ | {json['text']}", ephemeral=True)

await interaction.edit_original_response(content="▶️ | uploading...")

expiry = "1"

form = aiohttp.FormData()
form.add_field("file", video_data, filename=filename)
form.add_field("expires", expiry)

hresp = await self.bot.session.post("https://0x0.st", data=form)

text = await hresp.text()

end = time.time()
took = end - start
formatted_took = humanfriendly.format_timespan(int(took))

await interaction.edit_original_response(content=f"✅ | process took {formatted_took}, file expires in {expiry} hour(s): {text}")
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ discord.py
python-dateutil
pynacl
discord.py[voice]
gtts
gtts
humanfriendly

0 comments on commit 889674e

Please sign in to comment.