handle interaction and replies in starboard
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 6s

This commit is contained in:
Nexus 2024-05-05 13:30:39 +01:00
parent bc26acda2c
commit 64b2045d63
Signed by: nex
GPG key ID: 0FA334385D0B689F
2 changed files with 40 additions and 1 deletions

View file

@ -1,4 +1,5 @@
import logging import logging
import textwrap
import discord import discord
import json import json
@ -62,6 +63,44 @@ class Starboard(commands.Cog):
) )
] ]
) )
if message.reference:
try:
ref_message = await self.get_or_fetch_message(message.reference.channel_id, message.reference.message_id)
except discord.HTTPException:
pass
else:
text = message.content.splitlines()[0]
v = f"[{ref_message.author.mention}'s message: ]({ref_message.jump_url})"
l = 1024 - len(v)
t = textwrap.shorten(text, l, placeholder="...")
v = f"[{ref_message.author.display_name}'s message: {t}]({ref_message.jump_url})"
embed.add_field(
name="Replying to",
value=v
)
elif message.interaction:
if message.interaction.type == discord.InteractionType.application_command:
real_author: discord.User = await discord.utils.get_or_fetch(
self.bot,
"user",
int(message.interaction.data["user"]["id"])
)
real_author = await discord.utils.get_or_fetch(
message.guild,
"member",
real_author.id,
default=real_author
) or message.author
embed.set_author(
name=real_author.display_name,
icon_url=real_author.display_avatar.url,
url=real_author.jump_url
)
embed.add_field(
name="Interaction",
value=f"Command `/{message.interaction.data['name']}` of {message.author.mention}"
)
if message.content: if message.content:
embed.description = message.content embed.description = message.content
elif message.embeds: elif message.embeds:

View file

@ -99,7 +99,7 @@ logging.basicConfig(
markup=True, markup=True,
console=Console(width=cols, height=lns), console=Console(width=cols, height=lns),
), ),
FileHandler(filename=CONFIG["logging"].get("file", "jimmy.log"), mode="a", encoding="utf-8", errors="replace"), FileHandler(filename=CONFIG["logging"].get("file", "jimmy.log"), encoding="utf-8", errors="replace"),
], ],
) )
for logger in CONFIG["logging"].get("suppress", []): for logger in CONFIG["logging"].get("suppress", []):