alert when cached

This commit is contained in:
Nexus 2023-12-04 15:44:27 +00:00
parent 6db65b26a8
commit 75f0774bb0
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -2446,7 +2446,6 @@ class OtherCog(commands.Cog):
@commands.message_command(name="Transcribe") @commands.message_command(name="Transcribe")
async def transcribe_message(self, ctx: discord.ApplicationContext, message: discord.Message): async def transcribe_message(self, ctx: discord.ApplicationContext, message: discord.Message):
"""Transcribes a message."""
await ctx.defer() await ctx.defer()
if not message.attachments: if not message.attachments:
return await ctx.respond("No attachments found.") return await ctx.respond("No attachments found.")
@ -2465,6 +2464,7 @@ class OtherCog(commands.Cog):
file_hash = file_hash.hexdigest() file_hash = file_hash.hexdigest()
cache = Path.home() / ".cache" / "lcc-bot" / ("%s-transcript.txt" % file_hash) cache = Path.home() / ".cache" / "lcc-bot" / ("%s-transcript.txt" % file_hash)
cached = False
if not cache.exists(): if not cache.exists():
client = openai.OpenAI(api_key=config.OPENAI_KEY) client = openai.OpenAI(api_key=config.OPENAI_KEY)
with tempfile.NamedTemporaryFile("wb+", suffix=".mp4") as f: with tempfile.NamedTemporaryFile("wb+", suffix=".mp4") as f:
@ -2487,12 +2487,21 @@ class OtherCog(commands.Cog):
cache.write_text(text) cache.write_text(text)
else: else:
text = cache.read_text() text = cache.read_text()
cached = True
paginator = commands.Paginator("", "", 4096) paginator = commands.Paginator("", "", 4096)
for line in text.splitlines(): for line in text.splitlines():
paginator.add_line(textwrap.shorten(line, 4096)) paginator.add_line(textwrap.shorten(line, 4096))
embeds = list(map(lambda p: discord.Embed(description=p), paginator.pages)) embeds = list(map(lambda p: discord.Embed(description=p), paginator.pages))
return await ctx.respond(embeds=embeds or [discord.Embed(description="No text found.")]) await ctx.respond(embeds=embeds or [discord.Embed(description="No text found.")])
if await self.bot.is_owner(ctx.user):
await ctx.respond(
("Cached response ({})" if cached else "Uncached response ({})").format(
file_hash
),
ephemeral=True
)
def setup(bot): def setup(bot):