sox/plugins/soteria_plugin.py

34 lines
1022 B
Python

from disnake.ext import plugins
import disnake
import soteria
plugin = plugins.Plugin()
sot = soteria.Client(cache=soteria.MemoryCache())
@plugin.slash_command(description="gets the 5 most recent BANGERS (posts) from Soteria")
async def get_posts(inter: disnake.CommandInteraction):
await inter.response.defer()
r = await sot.request('GET', '/posts/all', params={"limit": 5})
embed_list = []
for post in r:
user = await soteria.User.fetch(sot, post["author"])
embed = disnake.Embed(
description=post["content"],
color=disnake.Color.blue()
)
embed.set_author(
name=user.display_name if user.display_name else user.username,
url=f"https://soteria.social/{user.id}",
icon_url=soteria.Asset(client = sot, asset_id = user.avatar).url
)
embed_list.append(embed)
await inter.edit_original_response(embeds=embed_list)
await sot.close()
setup, teardown = plugin.create_extension_handlers()