From 0d6ddce776e7be5fa60a7f1f338288d443033f31 Mon Sep 17 00:00:00 2001 From: faint <46868845+ficcialfaint@users.noreply.github.com> Date: Sat, 24 Jun 2023 04:04:04 +0300 Subject: [PATCH 1/2] it's done --- MoMMI/Modules/github.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/MoMMI/Modules/github.py b/MoMMI/Modules/github.py index 7de4084..2e5110f 100755 --- a/MoMMI/Modules/github.py +++ b/MoMMI/Modules/github.py @@ -3,7 +3,7 @@ import re import asyncio import subprocess -from typing import Match, Tuple, List, Optional, Any, Set, Dict, DefaultDict, cast, Union +from typing import Match, Tuple, List, Optional, Any, Set, Dict, DefaultDict, cast, Union, Iterator from urllib.parse import quote, quote_plus from collections import defaultdict import aiohttp @@ -24,6 +24,7 @@ REG_PATH = re.compile(r"\[(?:(\S+)\/\/)?(.+?)(?:(?::|#L)(\d+)(?:-L?(\d+))?)?\]", re.I) REG_ISSUE = re.compile(r"\[(?:(\S+)#|#)?([0-9]+)\]") REG_COMMIT = re.compile(r"\[(?:(\S+)@)?([0-9a-f]{40})\]", re.I) +REG_CODE_MARKDOWN = re.compile(r"(? None: # handling of stuff like [2000] and [world.dm] +def ignore_message_code_markdown(message: Message, expression: re.Pattern, iterator: Iterator[Match[str]]) -> \ + Iterator[Match[str]]: + for k in expression.finditer(''.join(REG_CODE_MARKDOWN.findall(message.content))): + for i in iterator: + if i.group(0) != k.group(0): + yield i + + @always_command("github_issue") async def issue_command(channel: MChannel, match: Match, message: Message) -> None: try: @@ -349,7 +358,7 @@ async def issue_command(channel: MChannel, match: Match, message: Message) -> No for repo_config in cfg: repo = repo_config["repo"] - for match in REG_ISSUE.finditer(message.content): + for match in ignore_message_code_markdown(message, REG_ISSUE, REG_ISSUE.finditer(message.content)): #logger.debug("did match") prefix = match.group(1) @@ -367,7 +376,7 @@ async def issue_command(channel: MChannel, match: Match, message: Message) -> No if messages >= GITHUB_ISSUE_MAX_MESSAGES: return - for match in REG_COMMIT.finditer(message.content): + for match in ignore_message_code_markdown(message, REG_COMMIT, REG_COMMIT.finditer(message.content)): prefix = match.group(1) if not is_repo_valid_for_command(repo_config, channel, prefix): From b0c6a1c0d9e5e794a039835e83cff54e87626fff Mon Sep 17 00:00:00 2001 From: faint <46868845+ficcialfaint@users.noreply.github.com> Date: Sun, 25 Jun 2023 09:54:27 +0300 Subject: [PATCH 2/2] =?UTF-8?q?Changed=20function=E2=80=99s=20return=20typ?= =?UTF-8?q?e=20hint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MoMMI/Modules/github.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MoMMI/Modules/github.py b/MoMMI/Modules/github.py index 2e5110f..5c4ddf6 100755 --- a/MoMMI/Modules/github.py +++ b/MoMMI/Modules/github.py @@ -335,8 +335,7 @@ async def issue_auto_label(type: str, message: Any, meta: str) -> None: # handling of stuff like [2000] and [world.dm] -def ignore_message_code_markdown(message: Message, expression: re.Pattern, iterator: Iterator[Match[str]]) -> \ - Iterator[Match[str]]: +def ignore_message_code_markdown(message: Message, expression: re.Pattern, iterator: Iterator[Match[str]]) -> re.Match: for k in expression.finditer(''.join(REG_CODE_MARKDOWN.findall(message.content))): for i in iterator: if i.group(0) != k.group(0):