From 8f5a9d741a3608b56c4adf2c22383d68fab893d7 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 7 Jun 2024 20:11:43 +0100 Subject: [PATCH] Add truth getter --- src/cogs/ollama.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index 3c0c248..44bb20c 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -1,5 +1,6 @@ import asyncio import base64 +import datetime import functools import io import json @@ -1162,6 +1163,38 @@ class Ollama(commands.Cog): async with ctx.channel.typing(): await self.generate_truth(ctx, "tate", latest) + @commands.command() + @commands.guild_only() + async def truth(self, ctx: commands.Context, *, truth_id: str): + """ + Fetches a specific truth post by ID. + """ + async with httpx.AsyncClient() as client: + r = CONFIG["truth"].get("api", "https://bots.nexy7574.co.uk/jimmy/v2/api") + username = CONFIG["truth"].get("username", "1") + password = CONFIG["truth"].get("password", "2") + response = await client.get( + "%s/truth/%s" % (r, truth_id), + timeout=60, + auth=(username, password), + ) + response.raise_for_status() + truth_json = response.json() + truth = TruthPayload.model_validate(truth_json) + embed = discord.Embed( + title="Truth:", + description=truth.content, + colour=0x6559FF, + timestamp=datetime.datetime.fromtimestamp(truth.timestamp, tz=datetime.timezone.utc), + ) + if truth.extra: + embed.add_field( + name="Extra Data", + value="```json\n%s```" % json.dumps(truth.extra, indent=2, default=repr), + ) + embed.set_author(name=truth.author) + await ctx.reply(embed=embed) + def setup(bot): bot.add_cog(Ollama(bot))