47
47
import aiohttp
48
48
import asyncpg
49
49
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
51
51
52
52
from .utils import LogHandler
53
53
@@ -60,12 +60,12 @@ class Bot(commands.Bot):
60
60
logging_queue : Queue [LogRecord ]
61
61
62
62
__slots__ = (
63
- "session" ,
64
- "pool" ,
63
+ "_previous_websocket_events" ,
65
64
"log_handler" ,
66
- "mb_client" ,
67
65
"logging_queue" ,
68
- "_previous_websocket_events" ,
66
+ "mb_client" ,
67
+ "pool" ,
68
+ "session" ,
69
69
)
70
70
71
71
def __init__ (self ) -> None :
@@ -77,11 +77,15 @@ def __init__(self) -> None:
77
77
self ._previous_websocket_events : deque [Any ] = deque (maxlen = 10 )
78
78
79
79
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 ,
81
85
) -> Context :
82
86
return await super ().get_context (message , cls = Context )
83
87
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
85
89
# we patch this since we're a single guild bot.
86
90
# it allows for guild syncing only.
87
91
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:
111
115
112
116
args_str = ["```py" ]
113
117
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} " , "```" ))
116
119
embed .add_field (name = "Args" , value = "\n " .join (args_str ), inline = False )
117
120
118
121
self .log_handler .error ("Event Error" , extra = {"embed" : embed })
119
122
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
121
124
assert ctx .command # wouldn't be here otherwise
122
125
123
126
if not isinstance (error , (commands .CommandInvokeError , commands .ConversionError )):
@@ -158,7 +161,7 @@ async def get_or_fetch_user(
158
161
try :
159
162
user = await guild .fetch_member (target_id )
160
163
except discord .HTTPException :
161
- return
164
+ return None
162
165
163
166
if cache :
164
167
cache [target_id ] = user
@@ -169,7 +172,7 @@ async def get_or_fetch_user(
169
172
try :
170
173
user = await self .fetch_user (target_id )
171
174
except discord .HTTPException :
172
- return
175
+ return None
173
176
174
177
if cache :
175
178
cache [target_id ] = user
@@ -182,11 +185,11 @@ async def start(self, token: str, *, reconnect: bool = True) -> None:
182
185
finally :
183
186
path = pathlib .Path ("logs/prev_events.log" )
184
187
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
186
189
for event in self ._previous_websocket_events :
187
190
try :
188
191
last_log = json .dumps (event , ensure_ascii = True , indent = 2 )
189
- except Exception :
192
+ except ( ValueError , TypeError ) :
190
193
f .write (f"{ event } \n " )
191
194
else :
192
195
f .write (f"{ last_log } \n " )
0 commit comments