Skip to content

Commit 2eccbf9

Browse files
committed
fix types and formatting due to missing gh actions at the time of pr
1 parent de3f7a4 commit 2eccbf9

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

modules/github.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import re
2727
from typing import TYPE_CHECKING
2828

29-
import aiohttp
3029
import discord
3130

3231
import core
3332

33+
3434
if TYPE_CHECKING:
3535
from bot import Bot
3636

@@ -55,10 +55,10 @@ def __init__(self, bot: Bot) -> None:
5555
self.highlight_timeout = 10
5656

5757
def _strip_content_path(self, url: str) -> str:
58-
file_path = url[len(GITHUB_BASE_URL):]
58+
file_path = url[len(GITHUB_BASE_URL) :]
5959
return file_path
6060

61-
async def format_highlight_block(self, url: str, line_adjustment: int = 10):
61+
async def format_highlight_block(self, url: str, line_adjustment: int = 10) -> dict[str, str | int] | None:
6262
try:
6363
highlighted_line = int(url.split("#L")[1]) # seperate the #L{n} highlight
6464
except IndexError:
@@ -76,7 +76,7 @@ async def format_highlight_block(self, url: str, line_adjustment: int = 10):
7676

7777
code = code.splitlines()
7878

79-
code_block_dict = {"lines": {}}
79+
code_block_dict: dict[str, dict[int, str]] = {"lines": {}}
8080
j = 0
8181
for i in code:
8282
# populate the dict
@@ -91,8 +91,8 @@ async def format_highlight_block(self, url: str, line_adjustment: int = 10):
9191
return None
9292

9393
bound_adj = line_adjustment # adjustment for upper and lower bound display
94-
_minBoundary = (highlighted_line - 1 - bound_adj)
95-
_maxBoundary = (highlighted_line - 1 + bound_adj)
94+
_minBoundary = highlighted_line - 1 - bound_adj
95+
_maxBoundary = highlighted_line - 1 + bound_adj
9696

9797
# loop through all the lines, and adjust the formatting
9898
msg = "```ansi\n"
@@ -101,14 +101,13 @@ async def format_highlight_block(self, url: str, line_adjustment: int = 10):
101101
currLineNum = str(key + 1)
102102
# insert a space if there is no following char before the first character...
103103
if key + 1 == highlighted_line:
104-
highlighted_msg_format = "\u001b[0;37m\u001b[4;31m{} {}\u001b[0;0m\n".format(
105-
currLineNum, line_list[key]
106-
)
104+
highlighted_msg_format = "\u001b[0;37m\u001b[4;31m{} {}\u001b[0;0m\n".format(currLineNum, line_list[key])
107105

108106
msg += highlighted_msg_format
109107
else:
110-
display_str = "{} {}\n" if line_list.get(
111-
key) is not None else "" # if we hit the end of the file, just write an empty string
108+
display_str = (
109+
"{} {}\n" if line_list.get(key) is not None else ""
110+
) # if we hit the end of the file, just write an empty string
112111
msg += display_str.format(currLineNum, line_list.get(key))
113112
key += 1
114113

@@ -118,7 +117,7 @@ async def format_highlight_block(self, url: str, line_adjustment: int = 10):
118117
"path": file_path,
119118
"min": _minBoundary if _minBoundary > 0 else highlighted_line, # Do not display negative numbers if <0
120119
"max": _maxBoundary,
121-
"msg": msg
120+
"msg": msg,
122121
}
123122
return github_dict
124123

@@ -142,20 +141,20 @@ async def on_message(self, message: discord.Message) -> None:
142141

143142
await message.add_reaction(self.code_highlight_emoji)
144143

145-
path = code_segment['path']
146-
_min = code_segment['min']
147-
_max = code_segment['max']
148-
code_fmt = code_segment['msg']
144+
path = code_segment["path"]
145+
_min = code_segment["min"]
146+
_max = code_segment["max"]
147+
code_fmt = code_segment["msg"]
149148

150-
def check(reaction, user):
151-
return reaction.emoji == self.code_highlight_emoji and user != self.bot.user \
152-
and message.id == reaction.message.id
149+
def check(reaction: discord.Reaction, user: discord.User) -> bool:
150+
return (
151+
reaction.emoji == self.code_highlight_emoji and user != self.bot.user and message.id == reaction.message.id
152+
)
153153

154154
try:
155155
await self.bot.wait_for("reaction_add", check=check, timeout=self.highlight_timeout)
156156
await message.channel.send(
157-
content="Showing lines `{}` - `{}` in: `{}`...\n{}".format(_min, _max, path, code_fmt),
158-
suppress_embeds=True
157+
content="Showing lines `{}` - `{}` in: `{}`...\n{}".format(_min, _max, path, code_fmt), suppress_embeds=True
159158
)
160159
except asyncio.TimeoutError:
161160
return

0 commit comments

Comments
 (0)