Check input for URLs and offer to add them to the chat.
(self, inp: str)
| 962 | return urls |
| 963 | |
| 964 | def check_for_urls(self, inp: str) -> List[str]: |
| 965 | """Check input for URLs and offer to add them to the chat.""" |
| 966 | if not self.detect_urls: |
| 967 | return inp |
| 968 | |
| 969 | # Exclude double quotes from the matched URL characters |
| 970 | url_pattern = re.compile(r'(https?://[^\s/$.?#].[^\s"]*[^\s,.])') |
| 971 | urls = list(set(url_pattern.findall(inp))) # Use set to remove duplicates |
| 972 | group = ConfirmGroup(urls) |
| 973 | for url in urls: |
| 974 | if url not in self.rejected_urls: |
| 975 | url = url.rstrip(".',\"") |
| 976 | if self.io.confirm_ask( |
| 977 | "Add URL to the chat?", subject=url, group=group, allow_never=True |
| 978 | ): |
| 979 | inp += "\n\n" |
| 980 | inp += self.commands.cmd_web(url, return_content=True) |
| 981 | else: |
| 982 | self.rejected_urls.add(url) |
| 983 | |
| 984 | return inp |
| 985 | |
| 986 | def keyboard_interrupt(self): |
| 987 | # Ensure cursor is visible on exit |