v1.1.0: enkel globaal filter (config) in plaats van per-subscription

- match_filter is nu instance-config (geldt voor ALLE feeds), niet per
  subscription: !rss set-filter <regex> zet het globale filter en slaat
  config op; !rss subscriptions toont het globale filter
- v7-migratie: per-subscription kolom match_filter verwijderd
- filter scant titel + HTML-ontdaan summary
This commit is contained in:
eddy 2026-09-05 17:19:10 +02:00
commit 676f999cce
5 changed files with 31 additions and 38 deletions

View file

@ -126,7 +126,7 @@ class RSSBot(Plugin):
self.log.exception("Fatal error while polling feeds")
async def _send(self, feed: Feed, entry: Entry, sub: Subscription) -> EventID | None:
match_filter = sub.match_filter or self.config["match_filter"]
match_filter = self.config["match_filter"]
if match_filter:
haystack = f"{entry.title}\n{html.unescape(re.sub(r'<[^>]+>', '', entry.summary))}"
if not re.search(match_filter, haystack):
@ -407,37 +407,30 @@ class RSSBot(Plugin):
await evt.reply(f"Subscribed to {feed_info}")
@rss.subcommand(
"set-filter", aliases=("f", "filter"), help="Set match filter (whitelist regex) for a specific feed."
"set-filter", aliases=("f", "filter"), help="Set the global match filter (whitelist regex) for all feeds."
)
@command.argument("feed_id", "feed ID", parser=int)
@command.argument("match_filter", "match filter", pass_raw=True)
async def set_filter(self, evt: MessageEvent, feed_id: int, match_filter: str) -> None:
async def set_filter(self, evt: MessageEvent, match_filter: str) -> None:
if evt.sender in self.config["admins"]:
pass
elif not self.config["allow_filter"]:
await evt.reply("This bot does not allow non-admin users to set title filters")
await evt.reply("This bot does not allow non-admin users to set the match filter")
return
elif not await self.can_manage(evt):
return
sub, feed = await self.dbm.get_subscription(feed_id, evt.room_id)
if not sub:
await evt.reply("This room is not subscribed to that feed")
return
try:
re.compile(match_filter)
except re.error:
await evt.reply(f"Filter is not a valid regular expression")
return
await self.dbm.update_match_filter(feed.id, evt.room_id, match_filter)
self.config["match_filter"] = match_filter
self.config.save()
if match_filter:
await evt.reply(
f"Feed {feed_id} will now only send posts matching: `{match_filter}`"
f"Global filter updated: only posts matching `{match_filter}` will be sent"
)
else:
await evt.reply(
f"Removed match filter from feed {feed_id} "
f"(falling back to default: `{self.config['match_filter']}`)"
)
await evt.reply("Global filter removed (all posts will be sent)")
@rss.subcommand(
"unsubscribe", aliases=("u", "unsub"), help="Unsubscribe this room from a feed."
@ -512,13 +505,11 @@ class RSSBot(Plugin):
await evt.reply(f"Updates for feed ID {feed.id} will now be sent as `{send_type}`")
@staticmethod
def _format_subscription(feed: Feed, subscriber: str, match_filter: str) -> str:
def _format_subscription(feed: Feed, subscriber: str) -> str:
msg = (
f"* {feed.id} - [{feed.title}]({feed.url}) "
f"(subscribed by [{subscriber}](https://matrix.to/#/{subscriber}))"
)
if match_filter:
msg += f" (only posts matching: {match_filter})"
if feed.error_count > 1:
msg += f" \n ⚠️ The last {feed.error_count} attempts to fetch the feed have failed!"
return msg
@ -530,15 +521,22 @@ class RSSBot(Plugin):
)
async def command_subscriptions(self, evt: MessageEvent) -> None:
subscriptions = await self.dbm.get_feeds_by_room(evt.room_id)
match_filter = self.config["match_filter"]
if len(subscriptions) == 0:
await evt.reply("There are no RSS subscriptions in this room")
return
filter_line = (
f"**Global filter:** `{match_filter}`"
if match_filter
else "**Global filter:** none (all posts are sent)"
)
await evt.reply(
"**Subscriptions in this room:**\n\n"
+ "\n".join(
self._format_subscription(feed, subscriber, match_filter)
for feed, subscriber, match_filter in subscriptions
self._format_subscription(feed, subscriber)
for feed, subscriber in subscriptions
)
+ f"\n\n{filter_line}"
)
@event.on(EventType.ROOM_TOMBSTONE)