Merge 96749dcb696847121088ee5e69937fcd09a81205 into 81ec8ed86494fae5f1dd49628c316158067ffeab

This commit is contained in:
ikkemaniac 2025-02-15 18:52:00 -08:00 committed by GitHub
commit 2a451c0294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -337,6 +337,25 @@ class RSSBot(Plugin):
async def rss(self) -> None:
pass
@rss.subcommand("latest", aliases=("l",), help="Get latest item for each feed.")
async def get_latest(self, evt: MessageEvent) -> None:
subs = await self.dbm.get_feeds()
subscriptions = await self.dbm.get_feeds_by_room(evt.room_id)
#feed, subscriber
if not subs:
return
self.log.info(f"Polling {len(subs)} feeds")
for feed in subs:
entries = await self.dbm.get_entries(feed.id, 1)
for old_entry in entries:
for s in feed.subscriptions:
if s.room_id == evt.room_id:
su =s
await self._send(feed, old_entry, su)
self.log.info(f"Finished polling {len(subs)} feeds")
@rss.subcommand("subscribe", aliases=("s", "sub"), help="Subscribe this room to a feed.")
@command.argument("url", "feed URL", pass_raw=True)
async def subscribe(self, evt: MessageEvent, url: str) -> None:

View File

@ -143,8 +143,19 @@ class DBManager:
return [(Feed.from_row(row), row["user_id"]) for row in rows]
async def get_entries(self, feed_id: int) -> list[Entry]:
return await self.get_entries(feed_id=feed_id,limit=0)
async def get_entries(self, feed_id: int, limit: int=0, orderDesc: bool=True) -> list[Entry]:
q = "SELECT feed_id, id, date, title, summary, link FROM entry WHERE feed_id = $1"
return [Entry.from_row(row) for row in await self.db.fetch(q, feed_id)]
if limit == 0:
return [Entry.from_row(row) for row in await self.db.fetch(q, feed_id)]
elif orderDesc:
q += " order by id DESC"
elif not orderDesc:
q += " order by id ASC"
q += " limit $2"
return [Entry.from_row(row) for row in await self.db.fetch(q, feed_id, limit)]
async def add_entries(self, entries: list[Entry], override_feed_id: int | None = None) -> None:
if not entries: