mirror of
https://github.com/maubot/rss.git
synced 2025-03-14 19:16:35 -04:00
Remote send_encoded flag, as encoded content is now a template variable that can be included upon user's choice
This commit is contained in:
parent
9f1d4a0e93
commit
4dfa74a63b
21
rss/bot.py
21
rss/bot.py
@ -420,7 +420,6 @@ class RSSBot(Plugin):
|
||||
user_id=sub.user_id,
|
||||
notification_template=Template(template),
|
||||
send_notice=sub.send_notice,
|
||||
send_encoded=sub.send_encoded,
|
||||
)
|
||||
sample_entry = Entry(
|
||||
feed_id=feed.id,
|
||||
@ -449,26 +448,6 @@ class RSSBot(Plugin):
|
||||
await self.dbm.set_send_notice(feed.id, evt.room_id, setting)
|
||||
send_type = "m.notice" if setting else "m.text"
|
||||
await evt.reply(f"Updates for feed ID {feed.id} will now be sent as `{send_type}`")
|
||||
|
||||
@rss.subcommand(
|
||||
"formatted", aliases=("f","encoded"), help="Set whether or not the bot should send formatted updates when available"
|
||||
)
|
||||
@command.argument("feed_id", "feed ID", parser=int)
|
||||
@BoolArgument("setting", "true/false", required=False)
|
||||
async def command_formatted(self, evt: MessageEvent, feed_id: int, setting: bool | None = None) -> None:
|
||||
if 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
|
||||
if setting is None:
|
||||
setting = await self.dbm.get_send_encoded(feed.id, evt.room_id)
|
||||
else:
|
||||
await self.dbm.set_send_encoded(feed.id, evt.room_id, setting)
|
||||
|
||||
send_type = "formatted" if setting else "plain text"
|
||||
await evt.reply(f"Updates for feed ID {feed.id} will be sent as {send_type}")
|
||||
|
||||
@rss.subcommand(
|
||||
"postall", aliases=("p",), help="Post all previously seen entries from the given feed to this room"
|
||||
|
27
rss/db.py
27
rss/db.py
@ -39,7 +39,6 @@ class Subscription:
|
||||
user_id: UserID
|
||||
notification_template: Template
|
||||
send_notice: bool
|
||||
send_encoded: bool
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Record | None) -> Subscription | None:
|
||||
@ -51,7 +50,6 @@ class Subscription:
|
||||
if not room_id or not user_id:
|
||||
return None
|
||||
send_notice = bool(row["send_notice"])
|
||||
send_encoded = bool(row["send_encoded"])
|
||||
tpl = Template(row["notification_template"])
|
||||
return cls(
|
||||
feed_id=feed_id,
|
||||
@ -59,7 +57,6 @@ class Subscription:
|
||||
user_id=user_id,
|
||||
notification_template=tpl,
|
||||
send_notice=send_notice,
|
||||
send_encoded=send_encoded
|
||||
)
|
||||
|
||||
|
||||
@ -84,7 +81,6 @@ class Feed:
|
||||
data.pop("room_id", None)
|
||||
data.pop("user_id", None)
|
||||
data.pop("send_notice", None)
|
||||
data.pop("send_encoded", None)
|
||||
data.pop("notification_template", None)
|
||||
return cls(**data, subscriptions=[])
|
||||
|
||||
@ -126,8 +122,7 @@ class DBManager:
|
||||
async def get_feeds(self) -> list[Feed]:
|
||||
q = """
|
||||
SELECT id, url, title, subtitle, link, next_retry, error_count,
|
||||
room_id, user_id, notification_template, send_notice,
|
||||
send_encoded
|
||||
room_id, user_id, notification_template, send_notice
|
||||
FROM feed INNER JOIN subscription ON feed.id = subscription.feed_id
|
||||
"""
|
||||
rows = await self.db.fetch(q)
|
||||
@ -179,8 +174,7 @@ class DBManager:
|
||||
) -> tuple[Subscription | None, Feed | None]:
|
||||
q = """
|
||||
SELECT id, url, title, subtitle, link, next_retry, error_count,
|
||||
room_id, user_id, notification_template, send_notice,
|
||||
send_encoded
|
||||
room_id, user_id, notification_template, send_notice
|
||||
FROM feed LEFT JOIN subscription ON feed.id = subscription.feed_id AND room_id = $2
|
||||
WHERE feed.id = $1
|
||||
"""
|
||||
@ -225,19 +219,17 @@ class DBManager:
|
||||
room_id: RoomID,
|
||||
user_id: UserID,
|
||||
template: str | None = None,
|
||||
send_notice: bool = True,
|
||||
send_encoded: bool = False
|
||||
send_notice: bool = True
|
||||
) -> None:
|
||||
q = """
|
||||
INSERT INTO subscription (
|
||||
feed_id, room_id, user_id, notification_template,
|
||||
send_notice, send_encoded)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
send_notice)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
"""
|
||||
template = template or "New post in $feed_title: [$title]($link)"
|
||||
await self.db.execute(
|
||||
q, feed_id, room_id, user_id, template, send_notice,
|
||||
send_encoded
|
||||
)
|
||||
|
||||
async def unsubscribe(self, feed_id: int, room_id: RoomID) -> None:
|
||||
@ -251,12 +243,3 @@ class DBManager:
|
||||
async def set_send_notice(self, feed_id: int, room_id: RoomID, send_notice: bool) -> None:
|
||||
q = "UPDATE subscription SET send_notice=$3 WHERE feed_id=$1 AND room_id=$2"
|
||||
await self.db.execute(q, feed_id, room_id, send_notice)
|
||||
|
||||
async def set_send_encoded(self, feed_id: int, room_id: RoomID, send_encoded: bool) -> None:
|
||||
q = "UPDATE subscription SET send_encoded=$3 WHERE feed_id=$1 AND room_id=$2"
|
||||
await self.db.execute(q, feed_id, room_id, send_encoded)
|
||||
|
||||
async def get_send_encoded(self, feed_id: int, room_id: RoomID) -> bool:
|
||||
q = "SELECT send_encoded FROM subscription WHERE feed_id=$1 and room_id=$2"
|
||||
row = await self.db.fetchrow(q, feed_id, room_id)
|
||||
return bool(row["send_encoded"])
|
||||
|
@ -76,4 +76,3 @@ async def upgrade_v3(conn: Connection) -> None:
|
||||
@upgrade_table.register(description="Add support for encoded content")
|
||||
async def upgrade_v4(conn: Connection) -> None:
|
||||
await conn.execute("ALTER TABLE entry ADD COLUMN content TEXT")
|
||||
await conn.execute("ALTER TABLE subscription ADD COLUMN send_encoded BOOLEAN DEFAULT false")
|
||||
|
Loading…
x
Reference in New Issue
Block a user