-
Notifications
You must be signed in to change notification settings - Fork 49
rss: Replace crashy double-formatting with standard format_token_replace #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
modules/rss.py
Outdated
# just in case the format starts keyerroring and you're not sure why | ||
self.log.trace("RSS Entry: " + str(entry)) | ||
try: | ||
format = channel.get_setting("rss-format", "$longtitle: $title by $author - $link").replace("$longtitle", feed_title_str).replace("$title", title).replace("$link", link).replace("$author", author).format(**entry) | ||
template = channel.get_setting("rss-format", "$longtitle: $title by $author - $link") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template = channel.get_setting("rss-format", "$longtitle: $title by $author - $link") | |
template = channel.get_setting("rss-format", "${longtitle}: ${title} by ${author} - ${link}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's also a breakage for existing configs, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think custom formatting really gets used tbh, but some way to detect/migrate it would be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could perform a sweep of the rss-format
configs at module load time and convert $variable
and {variable}
to ${variable}
and then set a bot config value to note that the migration has happened. I can't think of a nicer way to do this without majorly overcomplicating things.
The following should be sufficient for migration of old configs. Just place it inside the BaseModule subclass. import re
def _migrate_formats(self):
count = 0
migration_sub = re.compile(r"(?:\$|{)+(?P<variable>[^}\s]+)(?:})?")
old_formats = self.bot.database.execute_fetchall("""
SELECT channel_id, value FROM channel_settings
WHERE setting = 'rss-format'
""")
for channel_id, format in old_formats:
new_format = migration_re.sub(r"${\1}", format)
self.bot.database.execute("""
UPDATE channel_settings SET value = ?
WHERE setting = 'rss-format'
AND channel_id = ?
""", [new_format, channel_id])
count += 1
self.log.info("Successfully migrated %d rss-format settings" % count)
def on_load(self):
if self.bot.get_setting("rss-fmt-migration", False):
self.log.info("Attempting to migrate old rss-format settings")
self._migrate_formats()
self.bot.set_setting("rss-fmt-migration", True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working
No description provided.