예제 #1
0
    def handle_event(self, event: Dict[str, Any],
                     **kwargs: Any) -> Union[Response, Iterable[Response]]:
        if not self._bindings:
            return Response.none()

        # Get message content.
        # Replace markdown links by their textual representation.
        # Convert to lowercase.
        content: str = self._markdown_links\
            .sub(r'\1', event['message']['content'])\
            .lower()

        return [
            Response.build_reaction(message=event['message'], emoji=emoji)
            for pattern, emoji in self._bindings
            if randint(1, 6) == 3 and pattern.search(content) is not None
        ]
예제 #2
0
    def _announcements_add_group(
        self,
        group_id: str
    ) -> bool:
        """Add the given group to all announcement messages."""
        emoji: Optional[str] = self._get_emoji_from_group(group_id)
        if not emoji:
            return False
        to_insert: str = self._announcement_msg_table_row_fmt % (group_id, emoji)

        pattern: Pattern[str] = re.compile(r'\n*\*to be continued\*\n*')

        return self._do_for_all_announcement_messages([
            lambda msg: msg.update(content = pattern.sub(
                '\n' + to_insert + '\n*to be continued*\n\n', msg['content']
            )),
            lambda msg: self.client.send_response(
                Response.build_reaction(msg, cast(str, emoji))
            )
        ])
예제 #3
0
 def handle_event(self, event: Dict[str, Any],
                  **kwargs: Any) -> Union[Response, Iterable[Response]]:
     return Response.build_reaction(event['message'], 'question')