message_id to tracked content request

This commit is contained in:
Corban-Lee Jones 2024-07-11 23:35:22 +01:00
parent 65586d7859
commit e2432a083d

View File

@ -133,42 +133,42 @@ class TaskCog(commands.Cog):
log.debug("item '%s' older than subscription threshold '%s', skipping", item.pub_date, sub.published_threshold) log.debug("item '%s' older than subscription threshold '%s', skipping", item.pub_date, sub.published_threshold)
continue continue
log.debug("before")
blocked = any(self.filter_item(_filter, item) for _filter in filters) blocked = any(self.filter_item(_filter, item) for _filter in filters)
log.debug("after")
mutated_item = item.create_mutated_copy(sub.mutators) mutated_item = item.create_mutated_copy(sub.mutators)
for channel in channels: for channel in channels:
successful_track = await self.mark_tracked_item(api, sub, item, channel.id, blocked) await self.track_and_send(api, sub, feed, item, mutated_item, channel, blocked)
if successful_track and not blocked:
await channel.send(embed=await mutated_item.to_embed(sub, feed, api.session))
def filter_item(self, _filter: dict, item: RSSItem) -> bool: def filter_item(self, _filter: dict, item: RSSItem) -> bool:
""" """
Returns `True` if item should be ignored due to filters. Returns `True` if item should be ignored due to filters.
""" """
log.debug("checking filter") match_found = match_text(_filter, item.title) or match_text(_filter, item.description)
log.debug("filter match found? '%s'", match_found)
return match_found
async def track_and_send(self, api: API, sub: Subscription, feed: RSSFeed, item: RSSItem, mutated_item: RSSItem, channel: TextChannel, blocked: bool):
message_id = -1
try: try:
match_found = match_text(_fliter, item.title) or match_text(_filter, item.description) message = await channel.send(embed=await mutated_item.to_embed(sub, feed, api.session))
log.debug("filter match found? '%s'", match_found) message_id = message.id
return match_found except Forbidden as error:
except Exception as error:
log.error(error) log.error(error)
input("[paused] >") finally:
return False await self.mark_tracked_item(api, sub, item, channel.id, message_id, blocked)
async def mark_tracked_item(self, api: API, sub: Subscription, item: RSSItem, channel_id: int, blocked: bool): async def mark_tracked_item(self, api: API, sub: Subscription, item: RSSItem, channel_id: int, message_id: int, blocked: bool):
try: try:
log.debug("marking as tracked 'blocked: %s'", blocked) log.debug("marking as tracked")
await api.create_tracked_content( await api.create_tracked_content(
guid=item.guid, guid=item.guid,
title=item.title, title=item.title,
url=item.link, url=item.link,
subscription=sub.id, subscription=sub.id,
channel_id=channel_id, channel_id=channel_id,
message_id=message_id,
blocked=blocked blocked=blocked
) )
return True return True