4747 import aiohttp
4848 import asyncpg
4949 import mystbin
50- from discord .ext .commands .cog import Cog # type : ignore # stubs
50+ from discord .ext .commands .cog import Cog # pyright : ignore[reportMissingTypeStubs] # stubs
5151
5252 from .utils import LogHandler
5353
@@ -60,12 +60,12 @@ class Bot(commands.Bot):
6060 logging_queue : Queue [LogRecord ]
6161
6262 __slots__ = (
63- "session" ,
64- "pool" ,
63+ "_previous_websocket_events" ,
6564 "log_handler" ,
66- "mb_client" ,
6765 "logging_queue" ,
68- "_previous_websocket_events" ,
66+ "mb_client" ,
67+ "pool" ,
68+ "session" ,
6969 )
7070
7171 def __init__ (self ) -> None :
@@ -77,11 +77,15 @@ def __init__(self) -> None:
7777 self ._previous_websocket_events : deque [Any ] = deque (maxlen = 10 )
7878
7979 async def get_context (
80- self , message : discord .Message | discord .Interaction , / , * , cls : type [commands .Context [commands .Bot ]] | None = None
80+ self ,
81+ message : discord .Message | discord .Interaction ,
82+ / ,
83+ * ,
84+ cls : type [commands .Context [commands .Bot ]] | None = None ,
8185 ) -> Context :
8286 return await super ().get_context (message , cls = Context )
8387
84- async def add_cog (self , cog : Cog , / , * , override : bool = False ) -> None : # type : ignore
88+ async def add_cog (self , cog : Cog , / , * , override : bool = False ) -> None : # pyright : ignore[reportIncompatibleMethodOverride] # weird narrowing on Context generic
8589 # we patch this since we're a single guild bot.
8690 # it allows for guild syncing only.
8791 return await super ().add_cog (cog , override = override , guild = discord .Object (id = GUILD_ID ))
@@ -111,13 +115,12 @@ async def on_error(self, event_name: str, /, *args: Any, **kwargs: Any) -> None:
111115
112116 args_str = ["```py" ]
113117 for index , arg in enumerate (args ):
114- args_str .append (f"[{ index } ]: { arg !r} " )
115- args_str .append ("```" )
118+ args_str .extend ((f"[{ index } ]: { arg !r} " , "```" ))
116119 embed .add_field (name = "Args" , value = "\n " .join (args_str ), inline = False )
117120
118121 self .log_handler .error ("Event Error" , extra = {"embed" : embed })
119122
120- async def on_command_error (self , ctx : Context , error : commands .CommandError ) -> None : # type : ignore # weird narrowing
123+ async def on_command_error (self , ctx : Context , error : commands .CommandError ) -> None : # pyright : ignore[reportIncompatibleMethodOverride] # weird narrowing on Context generic
121124 assert ctx .command # wouldn't be here otherwise
122125
123126 if not isinstance (error , (commands .CommandInvokeError , commands .ConversionError )):
@@ -158,7 +161,7 @@ async def get_or_fetch_user(
158161 try :
159162 user = await guild .fetch_member (target_id )
160163 except discord .HTTPException :
161- return
164+ return None
162165
163166 if cache :
164167 cache [target_id ] = user
@@ -169,7 +172,7 @@ async def get_or_fetch_user(
169172 try :
170173 user = await self .fetch_user (target_id )
171174 except discord .HTTPException :
172- return
175+ return None
173176
174177 if cache :
175178 cache [target_id ] = user
@@ -182,11 +185,11 @@ async def start(self, token: str, *, reconnect: bool = True) -> None:
182185 finally :
183186 path = pathlib .Path ("logs/prev_events.log" )
184187
185- with path .open ("w+" , encoding = "utf-8" ) as f :
188+ with path .open ("w+" , encoding = "utf-8" ) as f : # noqa: ASYNC230 # this is okay as we're in cleanup phase
186189 for event in self ._previous_websocket_events :
187190 try :
188191 last_log = json .dumps (event , ensure_ascii = True , indent = 2 )
189- except Exception :
192+ except ( ValueError , TypeError ) :
190193 f .write (f"{ event } \n " )
191194 else :
192195 f .write (f"{ last_log } \n " )
0 commit comments