Add support for images in starboard, limit starboard to admins, closes #18
This commit is contained in:
parent
3f3bbd9032
commit
a59976544f
1 changed files with 27 additions and 0 deletions
|
@ -12,6 +12,14 @@ from jarvis.utils import build_embed
|
|||
from jarvis.utils.db import DBManager
|
||||
from jarvis.utils.field import Field
|
||||
|
||||
supported_images = [
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/webp",
|
||||
"image/svg",
|
||||
]
|
||||
|
||||
|
||||
class StarboardCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
|
@ -24,6 +32,7 @@ class StarboardCog(commands.Cog):
|
|||
description="Lists all Starboards",
|
||||
guild_ids=[418094694325813248, 578757004059738142],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _list(self, ctx):
|
||||
starboards = [
|
||||
x for x in self.db.jarvis.starboard.find({"guild": ctx.guild.id})
|
||||
|
@ -56,6 +65,7 @@ class StarboardCog(commands.Cog):
|
|||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _create(self, ctx, name: str, target: TextChannel):
|
||||
if target not in ctx.guild.channels:
|
||||
await ctx.send(
|
||||
|
@ -98,6 +108,7 @@ class StarboardCog(commands.Cog):
|
|||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _delete(self, ctx, name: str):
|
||||
deleted = self.db.jarvis.starboard.delete_one(
|
||||
{
|
||||
|
@ -131,6 +142,7 @@ class StarboardCog(commands.Cog):
|
|||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _move(self, ctx, name: str, target: TextChannel):
|
||||
exists = self.db.jarvis.starboard.find_one(
|
||||
{
|
||||
|
@ -171,6 +183,7 @@ class StarboardCog(commands.Cog):
|
|||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _rename(self, ctx, name: str, new: str):
|
||||
old_exists = self.db.jarvis.starboard.find_one(
|
||||
{"name": name, "guild": ctx.guild.id}
|
||||
|
@ -222,6 +235,7 @@ class StarboardCog(commands.Cog):
|
|||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _star_add(
|
||||
self,
|
||||
ctx: SlashContext,
|
||||
|
@ -264,11 +278,22 @@ class StarboardCog(commands.Cog):
|
|||
|
||||
content = message.content
|
||||
|
||||
attachments = message.attachments
|
||||
image_url = None
|
||||
if attachments:
|
||||
for attachment in attachments:
|
||||
if attachment.content_type in supported_images:
|
||||
image_url = attachment.url
|
||||
break
|
||||
if not content and image_url:
|
||||
content = "\u200b"
|
||||
|
||||
embed = build_embed(
|
||||
title="Click Here to view context",
|
||||
description=content,
|
||||
fields=[],
|
||||
url=message.jump_url,
|
||||
timestamp=message.created_at,
|
||||
)
|
||||
embed.set_author(
|
||||
name=message.author.name,
|
||||
|
@ -278,6 +303,8 @@ class StarboardCog(commands.Cog):
|
|||
embed.set_footer(
|
||||
text=message.guild.name + " | " + message.channel.name
|
||||
)
|
||||
if image_url:
|
||||
embed.set_image(url=image_url)
|
||||
|
||||
star = await target.send(embed=embed)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue