message_id to tracked content request
This commit is contained in:
parent
65586d7859
commit
e2432a083d
@ -133,42 +133,42 @@ class TaskCog(commands.Cog):
|
||||
log.debug("item '%s' older than subscription threshold '%s', skipping", item.pub_date, sub.published_threshold)
|
||||
continue
|
||||
|
||||
log.debug("before")
|
||||
blocked = any(self.filter_item(_filter, item) for _filter in filters)
|
||||
log.debug("after")
|
||||
mutated_item = item.create_mutated_copy(sub.mutators)
|
||||
|
||||
for channel in channels:
|
||||
successful_track = await self.mark_tracked_item(api, sub, item, channel.id, blocked)
|
||||
|
||||
if successful_track and not blocked:
|
||||
await channel.send(embed=await mutated_item.to_embed(sub, feed, api.session))
|
||||
await self.track_and_send(api, sub, feed, item, mutated_item, channel, blocked)
|
||||
|
||||
def filter_item(self, _filter: dict, item: RSSItem) -> bool:
|
||||
"""
|
||||
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:
|
||||
match_found = match_text(_fliter, item.title) or match_text(_filter, item.description)
|
||||
log.debug("filter match found? '%s'", match_found)
|
||||
return match_found
|
||||
except Exception as error:
|
||||
message = await channel.send(embed=await mutated_item.to_embed(sub, feed, api.session))
|
||||
message_id = message.id
|
||||
except Forbidden as error:
|
||||
log.error(error)
|
||||
input("[paused] >")
|
||||
return False
|
||||
finally:
|
||||
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:
|
||||
log.debug("marking as tracked 'blocked: %s'", blocked)
|
||||
log.debug("marking as tracked")
|
||||
await api.create_tracked_content(
|
||||
guid=item.guid,
|
||||
title=item.title,
|
||||
url=item.link,
|
||||
subscription=sub.id,
|
||||
channel_id=channel_id,
|
||||
message_id=message_id,
|
||||
blocked=blocked
|
||||
)
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user