Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
85c5c96392 | |||
1d78a05807 | |||
e43d7aacf9 | |||
7b1a293891 | |||
a2e8128bb6 | |||
be47f5be68 | |||
81ae171b02 |
@ -102,7 +102,7 @@ class CommandsCog(commands.Cog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@view_group.command(name="subscriptions")
|
@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."""
|
"""List Subscriptions from this server."""
|
||||||
|
|
||||||
await inter.response.defer()
|
await inter.response.defer()
|
||||||
@ -126,7 +126,10 @@ class CommandsCog(commands.Cog):
|
|||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
api = API(self.bot.api_token, session)
|
api = API(self.bot.api_token, session)
|
||||||
return await api.get_subscriptions(
|
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
|
embed = Followup(f"Subscriptions in {inter.guild.name}").info()._embed
|
||||||
@ -142,7 +145,7 @@ class CommandsCog(commands.Cog):
|
|||||||
await pagination.send()
|
await pagination.send()
|
||||||
|
|
||||||
@view_group.command(name="tracked-content")
|
@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"""
|
"""List Tracked Content from this server, or a given sub"""
|
||||||
|
|
||||||
await inter.response.defer()
|
await inter.response.defer()
|
||||||
@ -161,7 +164,10 @@ class CommandsCog(commands.Cog):
|
|||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
api = API(self.bot.api_token, session)
|
api = API(self.bot.api_token, session)
|
||||||
return await api.get_tracked_content(
|
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
|
embed = Followup(f"Tracked Content in {inter.guild.name}").info()._embed
|
||||||
|
@ -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}")
|
||||||
|
12
src/feed.py
12
src/feed.py
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user