Add truth getter
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
This commit is contained in:
parent
3109f645e6
commit
8f5a9d741a
1 changed files with 33 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue