mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Add status to mp3 gen
This commit is contained in:
parent
14e2648648
commit
0df2d162ae
1 changed files with 26 additions and 5 deletions
|
@ -1373,7 +1373,11 @@ class OtherCog(commands.Cog):
|
||||||
_url = text_pre[4:].strip()
|
_url = text_pre[4:].strip()
|
||||||
_msg = await interaction.followup.send("Downloading text...")
|
_msg = await interaction.followup.send("Downloading text...")
|
||||||
try:
|
try:
|
||||||
response = await _self.http.get(_url, headers={"User-Agent": "Mozilla/5.0"})
|
response = await _self.http.get(
|
||||||
|
_url,
|
||||||
|
headers={"User-Agent": "Mozilla/5.0"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
await _msg.edit(content=f"Failed to download text. Status code: {response.status_code}")
|
await _msg.edit(content=f"Failed to download text. Status code: {response.status_code}")
|
||||||
return
|
return
|
||||||
|
@ -1386,15 +1390,32 @@ class OtherCog(commands.Cog):
|
||||||
except (ConnectionError, httpx.HTTPError, httpx.NetworkError) as e:
|
except (ConnectionError, httpx.HTTPError, httpx.NetworkError) as e:
|
||||||
await _msg.edit(content="Failed to download text. " + str(e))
|
await _msg.edit(content="Failed to download text. " + str(e))
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
await _msg.edit(content="Text downloaded; Converting to MP3...")
|
|
||||||
else:
|
else:
|
||||||
_msg = await interaction.followup.send("Converting text to MP3...")
|
_msg = await interaction.followup.send("Converting text to MP3... (0 seconds elapsed)")
|
||||||
|
|
||||||
|
async def assurance_task():
|
||||||
|
while True:
|
||||||
|
await asyncio.sleep(5.5)
|
||||||
|
await _msg.edit(
|
||||||
|
content=f"Converting text to MP3... ({time.time() - start_time:.1f} seconds elapsed)"
|
||||||
|
)
|
||||||
|
|
||||||
|
task = self.bot.loop.create_task(assurance_task())
|
||||||
try:
|
try:
|
||||||
mp3, size = await _bot.loop.run_in_executor(None, _convert, text_pre)
|
mp3, size = await asyncio.wait_for(
|
||||||
|
_bot.loop.run_in_executor(None, _convert, text_pre),
|
||||||
|
timeout=300
|
||||||
|
)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
task.cancel()
|
||||||
|
await _msg.edit(content="Failed to convert text to MP3 - Timeout. Try shorter/less complex text.")
|
||||||
|
return
|
||||||
except (Exception, IOError) as e:
|
except (Exception, IOError) as e:
|
||||||
|
task.cancel()
|
||||||
await _msg.edit(content="failed. " + str(e))
|
await _msg.edit(content="failed. " + str(e))
|
||||||
raise e
|
raise e
|
||||||
|
task.cancel()
|
||||||
|
del task
|
||||||
if size >= ctx.guild.filesize_limit - 1500:
|
if size >= ctx.guild.filesize_limit - 1500:
|
||||||
await _msg.edit(
|
await _msg.edit(
|
||||||
content=f"MP3 is too large ({size / 1024 / 1024}Mb vs "
|
content=f"MP3 is too large ({size / 1024 / 1024}Mb vs "
|
||||||
|
|
Loading…
Reference in a new issue