bitbot icon indicating copy to clipboard operation
bitbot copied to clipboard

[Important] Bot crashes when parsing the URL of certain RSS feeds

Open TehPeGaSuS opened this issue 1 year ago • 1 comments

Today my bot started crashing after someone adding a "feature request" on UnrealIRCd bugtracker (powered by Mantis).

Here's what i could gather from trace.log:

2023-06-13T18:57:42.049 [TRACE] executed query in 0.041364ms: "SELECT value FROM channel_settings WHERE channel_id=? AND setting=?" (params: [7, 'rss-shorten'])
2023-06-13T18:57:42.050 [TRACE] RSS Entry: {'title': '0006281: Allow commas in "port" or multiplie "port" lines in listen{} blocks', 'title_detail': {'type': 'text/plain', 'language': None, 'base': '', 'value': '0006281: Allow commas in "port" or multiplie "port" lines in listen{} blocks'}, 'authors': [{}], 'author': '', 'links': [{'rel': 'alternate', 'type': 'text/html', 'href': 'https://bugs.unrealircd.org/view.php?id=6281'}], 'link': 'https://bugs.unrealircd.org/view.php?id=6281', 'summary': 'I think the "port" option for listen{} blocks should allow commas or multiple "port" lines<br />\n<br />\nRather than having:<br />\nlisten {<br />\n    ip *;<br />\n    port 6660-6669;<br />\n    options { clientsonly; }<br />\n}<br />\nlisten {<br />\n    ip *;<br />\n    port 9000;<br />\n    options { clientsonly;  }<br />\n}<br />\n<br />\nwe should be able to do:<br />\nlisten {<br />\n    ip *;<br />\n    port 6660-6669, 7000;<br />\n    options { clientsonly; }<br />\n }', 'summary_detail': {'type': 'text/html', 'language': None, 'base': '', 'value': 'I think the "port" option for listen{} blocks should allow commas or multiple "port" lines<br />\n<br />\nRather than having:<br />\nlisten {<br />\n    ip *;<br />\n    port 6660-6669;<br />\n    options { clientsonly; }<br />\n}<br />\nlisten {<br />\n    ip *;<br />\n    port 9000;<br />\n    options { clientsonly;  }<br />\n}<br />\n<br />\nwe should be able to do:<br />\nlisten {<br />\n    ip *;<br />\n    port 6660-6669, 7000;<br />\n    options { clientsonly; }<br />\n }'}, 'tags': [{'term': 'ircd', 'scheme': None, 'label': None}], 'published': 'Tue, 13 Jun 2023 01:23:00 +0200', 'published_parsed': time.struct_time(tm_year=2023, tm_mon=6, tm_mday=12, tm_hour=23, tm_min=23, tm_sec=0, tm_wday=0, tm_yday=163, tm_isdst=0), 'id': 'https://bugs.unrealircd.org/view.php?id=6281', 'guidislink': False, 'comments': 'https://bugs.unrealircd.org/view.php?id=6281#bugnotes'}
2023-06-13T18:57:42.050 [TRACE] executed query in 0.060702ms: "SELECT value FROM channel_settings WHERE channel_id=? AND setting=?" (params: [7, 'rss-format'])
2023-06-13T18:57:42.050 [CRITICAL] Unhandled exception: Replacement index 0 out of range for positional args tuple
Traceback (most recent call last):
  File "/home/bitbot/bitbot/bitbotd", line 157, in <module>
    bot.run()
  File "/home/bitbot/bitbot/src/IRCBot.py", line 284, in run
    self._event_loop()
  File "/home/bitbot/bitbot/src/IRCBot.py", line 315, in _event_loop
    self._check()
  File "/home/bitbot/bitbot/src/IRCBot.py", line 433, in _check
    poll_timeout.call()
  File "/home/bitbot/bitbot/src/Timers.py", line 124, in call
    timer.callback(timer)
  File "/home/bitbot/bitbot/modules/rss.py", line 116, in _timer
    output = self._format_entry(server, channel, feed_title, entry,
  File "/home/bitbot/bitbot/modules/rss.py", line 44, in _format_entry
    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)
IndexError: Replacement index 0 out of range for positional args tuple

TehPeGaSuS avatar Jun 13 '23 17:06 TehPeGaSuS

That's because {} in the entry is inserted by .replace("$longtitle", feed_title_str), and .format() tries to interpret it.

Bitbot should probably remove .format() altogether and use to string.Template. See #370 as an example, you'd just need to merge the variables and entry dictionaries to remove the .format().

progval avatar Jun 13 '23 17:06 progval