sidebot: catch up strikebot_updates.py
authorAndrea Cornell <anders@acorn.pw>
Wed, 2 Nov 2022 01:46:34 +0000 (21:46 -0400)
committerAndrea Cornell <anders@acorn.pw>
Wed, 2 Nov 2022 01:47:31 +0000 (21:47 -0400)
sidebot/sidebot/strikebot_updates.py

index 6e072dbb6ea3171e1513720b65f832ad71e14eba..6c90e5fb79b7a0c8797f04487a5f7e6e6929ddd0 100644 (file)
@@ -37,7 +37,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) -
 
        # flatten the update content to plain text
        tree = BeautifulSoup(payload_data["body_html"], "html.parser")
-       worklist = tree.contents
+       worklist = list(reversed(tree.contents))
        out = [[]]
        while worklist:
                el = worklist.pop()
@@ -45,7 +45,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) -
                        out[-1].append(el)
                elif el is SPACE:
                        out[-1].append(el)
-               elif el is NEW_LINE or el.name == "br" or el.name == "hr":
+               elif el is NEW_LINE or el.name in ["br", "hr"]:
                        if out[-1]:
                                out.append([])
                elif el.name in ["em", "strong", "del", "span", "sup", "code", "a", "th", "td"]:
@@ -88,7 +88,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) -
 
 def _parse_from_lines(lines: list[str], curr_count: Optional[int], bot_user: str) -> ParsedUpdate:
        command = next(
-               filter(None, (_parse_command(l, bot_user) for l in lines)),
+               (cmd for l in lines if (cmd := _parse_command(l, bot_user))),
                None
        )
        if lines:
@@ -136,7 +136,7 @@ def _parse_from_lines(lines: list[str], curr_count: Optional[int], bot_user: str
                                        if parts in partials:
                                                # missing any of last two digits
                                                typo = True
-                                       elif parts in [p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials]:
+                                       elif any(parts == p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials):
                                                # double paste
                                                typo = True