Compare commits

...

7 Commits

Author SHA1 Message Date
85c5c96392 fix TypeError with empty title, desc, pub_date rssItems
All checks were successful
Build and Push Docker Image / build (push) Successful in 8s
Build and Push Docker Image / build (pull_request) Successful in 8s
2024-09-10 10:49:22 +01:00
1d78a05807 task group and exception checker 2024-09-10 10:44:50 +01:00
e43d7aacf9 search option for view commands
All checks were successful
Build and Push Docker Image / build (push) Successful in 7s
2024-08-21 17:20:48 +01:00
7b1a293891 Merge pull request 'v0.2.0' (#20) from staging into master
All checks were successful
Build and Push Docker Image / build (push) Successful in 10s
Reviewed-on: https://gitea.corbz.dev/corbz/PYRSS-Bot/pulls/20
2024-08-19 21:06:52 +00:00
a2e8128bb6 Merge branch 'dev' into staging
All checks were successful
Build and Push Docker Image / build (push) Successful in 8s
Build and Push Docker Image / build (pull_request) Successful in 8s
2024-08-19 22:05:08 +01:00
be47f5be68 Merge branch 'master' into staging
All checks were successful
Build and Push Docker Image / build (push) Successful in 8s
2024-08-19 22:01:29 +01:00
81ae171b02 Merge pull request 'v0.1.1' (#16) from staging into master
All checks were successful
Build and Push Docker Image / build (push) Successful in 9s
Reviewed-on: https://gitea.corbz.dev/corbz/PYRSS-Bot/pulls/16
2024-08-17 19:53:40 +00:00
3 changed files with 37 additions and 17 deletions

View File

@ -102,7 +102,7 @@ class CommandsCog(commands.Cog):
)
@view_group.command(name="subscriptions")
async def cmd_list_subs(self, inter: Interaction):
async def cmd_list_subs(self, inter: Interaction, search: str = ""):
"""List Subscriptions from this server."""
await inter.response.defer()
@ -126,7 +126,10 @@ class CommandsCog(commands.Cog):
async with aiohttp.ClientSession() as session:
api = API(self.bot.api_token, session)
return await api.get_subscriptions(
guild_id=inter.guild.id, page=page, page_size=pagesize
guild_id=inter.guild.id,
page=page,
page_size=pagesize,
search=search
)
embed = Followup(f"Subscriptions in {inter.guild.name}").info()._embed
@ -142,7 +145,7 @@ class CommandsCog(commands.Cog):
await pagination.send()
@view_group.command(name="tracked-content")
async def cmd_list_tracked(self, inter: Interaction):
async def cmd_list_tracked(self, inter: Interaction, search: str = ""):
"""List Tracked Content from this server, or a given sub"""
await inter.response.defer()
@ -161,7 +164,10 @@ class CommandsCog(commands.Cog):
async with aiohttp.ClientSession() as session:
api = API(self.bot.api_token, session)
return await api.get_tracked_content(
subscription__guild_id=inter.guild_id, page=page, page_size=pagesize
subscription__guild_id=inter.guild_id,
page=page,
page_size=pagesize,
search=search
)
embed = Followup(f"Tracked Content in {inter.guild.name}").info()._embed

View File

@ -65,13 +65,24 @@ class TaskCog(commands.Cog):
"""
self.subscription_task.cancel()
@app_commands.command(name="debug-trigger-task")
async def debug_trigger_task(self, inter):
group = app_commands.Group(
name="task",
description="Commands for tasks",
guild_only=True
)
@group.command(name="trigger")
async def cmd_trigger_task(self, inter):
await inter.response.defer()
start_time = perf_counter()
await self.subscription_task()
end_time = perf_counter()
await inter.followup.send(f"completed in {end_time - start_time:.4f} seconds")
try:
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)
async def subscription_task(self):
@ -199,7 +210,7 @@ class TaskCog(commands.Cog):
continue
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:
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)
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
log.debug("track and send func %s, %s", item.guid, item.title)
@ -243,7 +254,8 @@ class TaskCog(commands.Cog):
if not blocked:
try:
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
except Forbidden:
log.error(f"Forbidden to send to channel {channel.id}")

View File

@ -51,13 +51,13 @@ class RSSItem:
RSSItem
"""
guid = entry.get('id', None) or entry.get("guid", None)
link = entry.get('link', None)
title = entry.get('title', None)
description = entry.get('description', None)
guid = entry.get('id', None) or entry.get("guid")
link = entry.get('link', "")
title = entry.get('title', "")
description = entry.get('description', "")
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")
thumb_image_url = entry.get("media_thumbnail", [{}])[0].get("url")
@ -128,6 +128,8 @@ class RSSItem:
discord.Embed
"""
log.debug("Creating embed of item: %s", self.guid)
# Replace HTML with Markdown, and shorten text.
title = shorten(markdownify(self.title, strip=["img", "a"]), 256)
desc = shorten(markdownify(self.description, strip=["img"]), 4096)