@@ -176,42 +176,40 @@ async def on_message(self, message: discord.Message) -> None:
176176
177177 Listener to retrieve issue(s) from a GitHub repository using automatic linking if matching <org>/<repo>#<issue>.
178178 """
179- # Ignore bots
180- if message .author .bot :
179+ # Ignore bots and DMs
180+ if message .author .bot or not message . guild :
181181 return
182182
183183 issues = [
184184 FoundIssue (* match .group ("org" , "repo" , "number" ))
185185 for match in AUTOMATIC_REGEX .finditer (self .remove_codeblocks (message .content ))
186186 ]
187- links = []
188187
189- if issues :
190- # Block this from working in DMs
191- if not message .guild :
192- return
188+ if not issues :
189+ return
193190
194- log .trace (f"Found { issues = } " )
195- # Remove duplicates
196- issues = list (dict .fromkeys (issues ))
191+ links = list [IssueState ]()
192+ log .trace (f"Found { issues = } " )
193+ # Remove duplicates
194+ issues = list (dict .fromkeys (issues ))
197195
198- if len (issues ) > MAXIMUM_ISSUES :
199- embed = discord .Embed (
200- title = random .choice (ERROR_REPLIES ),
201- color = Colours .soft_red ,
202- description = f"Too many issues/PRs! (maximum of { MAXIMUM_ISSUES } )"
203- )
204- await message .channel .send (embed = embed , delete_after = 5 )
205- return
196+ if len (issues ) > MAXIMUM_ISSUES :
197+ embed = discord .Embed (
198+ title = random .choice (ERROR_REPLIES ),
199+ color = Colours .soft_red ,
200+ description = f"Too many issues/PRs! (maximum of { MAXIMUM_ISSUES } )"
201+ )
202+ await message .channel .send (embed = embed , delete_after = 5 )
203+ return
206204
207- for repo_issue in issues :
208- result = await self .fetch_issue (
209- int (repo_issue .number ),
210- repo_issue .repository ,
211- repo_issue .organisation or "python-discord"
212- )
213- if isinstance (result , IssueState ):
214- links .append (result )
205+ for repo_issue in issues :
206+ result = await self .fetch_issue (
207+ int (repo_issue .number ),
208+ repo_issue .repository ,
209+ repo_issue .organisation or "python-discord"
210+ )
211+ if isinstance (result , IssueState ):
212+ links .append (result )
215213
216214 if not links :
217215 return
0 commit comments