Merge branch 'staging' into dev
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s

This commit is contained in:
Corban-Lee Jones 2024-09-10 11:00:51 +01:00
commit ab472e1979
2 changed files with 27 additions and 13 deletions

View File

@ -65,13 +65,24 @@ class TaskCog(commands.Cog):
""" """
self.subscription_task.cancel() self.subscription_task.cancel()
@app_commands.command(name="debug-trigger-task") group = app_commands.Group(
async def debug_trigger_task(self, inter): name="task",
description="Commands for tasks",
guild_only=True
)
@group.command(name="trigger")
async def cmd_trigger_task(self, inter):
await inter.response.defer() await inter.response.defer()
start_time = perf_counter() start_time = perf_counter()
await self.subscription_task()
end_time = perf_counter() try:
await inter.followup.send(f"completed in {end_time - start_time:.4f} seconds") await self.subscription_task()
except Exception as error:
await inter.followup.send(str(error))
finally:
end_time = perf_counter()
await inter.followup.send(f"completed in {end_time - start_time:.4f} seconds")
@tasks.loop(time=subscription_task_times) @tasks.loop(time=subscription_task_times)
async def subscription_task(self): async def subscription_task(self):
@ -199,7 +210,7 @@ class TaskCog(commands.Cog):
continue continue
blocked = any(self.filter_item(_filter, item) for _filter in filters) blocked = any(self.filter_item(_filter, item) for _filter in filters)
mutated_item = item.create_mutated_copy(sub.mutators) mutated_item = item.create_mutated_copy(sub.mutators) if sub.mutators else None
for channel in channels: for channel in channels:
await self.track_and_send(sub, feed, item, mutated_item, channel, blocked) await self.track_and_send(sub, feed, item, mutated_item, channel, blocked)
@ -225,7 +236,7 @@ class TaskCog(commands.Cog):
log.debug("filter match found? '%s'", match_found) log.debug("filter match found? '%s'", match_found)
return match_found return match_found
async def track_and_send(self, sub: Subscription, feed: RSSFeed, item: RSSItem, mutated_item: RSSItem, channel: TextChannel, blocked: bool): async def track_and_send(self, sub: Subscription, feed: RSSFeed, item: RSSItem, mutated_item: RSSItem | None, channel: TextChannel, blocked: bool):
message_id = -1 message_id = -1
log.debug("track and send func %s, %s", item.guid, item.title) log.debug("track and send func %s, %s", item.guid, item.title)
@ -243,7 +254,8 @@ class TaskCog(commands.Cog):
if not blocked: if not blocked:
try: try:
log.debug("sending '%s', exists '%s'", item.guid, result[1]) log.debug("sending '%s', exists '%s'", item.guid, result[1])
message = await channel.send(embed=await mutated_item.to_embed(sub, feed, self.api.session)) sendable_item = mutated_item or item
message = await channel.send(embed=await sendable_item.to_embed(sub, feed, self.api.session))
message_id = message.id message_id = message.id
except Forbidden: except Forbidden:
log.error(f"Forbidden to send to channel {channel.id}") log.error(f"Forbidden to send to channel {channel.id}")

View File

@ -51,13 +51,13 @@ class RSSItem:
RSSItem RSSItem
""" """
guid = entry.get('id', None) or entry.get("guid", None) guid = entry.get('id', None) or entry.get("guid")
link = entry.get('link', None) link = entry.get('link', "")
title = entry.get('title', None) title = entry.get('title', "")
description = entry.get('description', None) description = entry.get('description', "")
pub_date = entry.get('published_parsed', None) pub_date = entry.get('published_parsed', None)
pub_date = datetime(*pub_date[0:6], tzinfo=timezone.utc) pub_date = datetime(*pub_date[0:6] if pub_date else None, tzinfo=timezone.utc)
content_image_url = entry.get("media_content", [{}])[0].get("url") content_image_url = entry.get("media_content", [{}])[0].get("url")
thumb_image_url = entry.get("media_thumbnail", [{}])[0].get("url") thumb_image_url = entry.get("media_thumbnail", [{}])[0].get("url")
@ -128,6 +128,8 @@ class RSSItem:
discord.Embed discord.Embed
""" """
log.debug("Creating embed of item: %s", self.guid)
# Replace HTML with Markdown, and shorten text. # Replace HTML with Markdown, and shorten text.
title = shorten(markdownify(self.title, strip=["img", "a"]), 256) title = shorten(markdownify(self.title, strip=["img", "a"]), 256)
desc = shorten(markdownify(self.description, strip=["img"]), 4096) desc = shorten(markdownify(self.description, strip=["img"]), 4096)