Allow HTML in RSS messages

This commit is contained in:
Tulir Asokan 2020-05-21 01:10:25 +03:00
parent adae757081
commit 391db1405f
2 changed files with 11 additions and 19 deletions

View File

@ -1,5 +1,5 @@
# rss - A maubot plugin to subscribe to RSS/Atom feeds. # rss - A maubot plugin to subscribe to RSS/Atom feeds.
# Copyright (C) 2019 Tulir Asokan # Copyright (C) 2020 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -78,7 +78,7 @@ class RSSBot(Plugin):
"feed_subtitle": feed.subtitle, "feed_subtitle": feed.subtitle,
"feed_link": feed.link, "feed_link": feed.link,
**entry._asdict(), **entry._asdict(),
}), msgtype=MessageType.NOTICE) }), msgtype=MessageType.NOTICE, allow_html=True)
async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None: async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None:
spam_sleep = self.config["spam_sleep"] spam_sleep = self.config["spam_sleep"]
@ -148,19 +148,11 @@ class RSSBot(Plugin):
def find_entries(cls, feed_id: int, entries: List[Any]) -> List[Entry]: def find_entries(cls, feed_id: int, entries: List[Any]) -> List[Entry]:
return [Entry( return [Entry(
feed_id=feed_id, feed_id=feed_id,
id=getattr( id=(getattr(entry, "id") or
entry, hashlib.sha1(" ".join([getattr(entry, "title", ""),
"id", getattr(entry, "description", ""),
hashlib.sha1( getattr(entry, "link", "")]).encode("utf-8")
" ".join( ).hexdigest()),
[
getattr(entry, "title", ""),
getattr(entry, "description", ""),
getattr(entry, "link", ""),
]
).encode("utf-8")
).hexdigest(),
),
date=cls.get_date(entry), date=cls.get_date(entry),
title=getattr(entry, "title", ""), title=getattr(entry, "title", ""),
summary=getattr(entry, "description", ""), summary=getattr(entry, "description", ""),
@ -187,8 +179,8 @@ class RSSBot(Plugin):
if type(state_level) != int: if type(state_level) != int:
state_level = 50 state_level = 50
if user_level < state_level: if user_level < state_level:
await evt.reply( await evt.reply("You don't have the permission to "
"You don't have the permission to manage the subscriptions of this room.") "manage the subscriptions of this room.")
return False return False
return True return True

View File

@ -1,5 +1,5 @@
# rss - A maubot plugin to subscribe to RSS/Atom feeds. # rss - A maubot plugin to subscribe to RSS/Atom feeds.
# Copyright (C) 2019 Tulir Asokan # Copyright (C) 2020 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -130,7 +130,7 @@ class Database:
if room_id else None, if room_id else None,
Feed(feed_id, url, title, subtitle, link, [])) Feed(feed_id, url, title, subtitle, link, []))
except (ValueError, StopIteration): except (ValueError, StopIteration):
return (None, None) return None, None
def update_room_id(self, old: RoomID, new: RoomID) -> None: def update_room_id(self, old: RoomID, new: RoomID) -> None:
self.db.execute(self.subscription.update() self.db.execute(self.subscription.update()