@@ -53,10 +53,10 @@ def __init__(self, *args, **kwargs):
5353 self .setup_cogs ()
5454 FredHelpEmbed .setup ()
5555 self .owo = False
56- self .web_session : aiohttp .ClientSession = ...
56+ self .web_session : aiohttp .ClientSession = ... # type: ignore
5757 self .loop = asyncio .get_event_loop ()
5858 self .executor = ThreadPoolExecutor ()
59- self .error_channel = int ( chan ) if ( chan := config .Misc .fetch ("error_channel" )) else 748229790825185311
59+ self .error_channel : int = int ( config .Misc .fetch ("error_channel" )) or 748229790825185311 # type: ignore
6060
6161 async def start (self , * args , ** kwargs ):
6262 async with aiohttp .ClientSession () as session :
@@ -146,7 +146,10 @@ async def on_error(self, event_method: str, *args, **kwargs):
146146 # error_embed = nextcord.Embed(colour=nextcord.Colour.red(), title=error_meta, description=full_error)
147147 # error_embed.set_author(name=fred_str)
148148
149- await self .get_channel (self .error_channel ).send (f"**{ fred_str } **\n { error_meta } \n ```py\n { full_error } ```" )
149+ error_channel = self .get_partial_messageable (self .error_channel )
150+ if error_channel is None :
151+ raise RuntimeError ("Error channel unreachable! Value: " + str (self .error_channel ))
152+ await error_channel .send (f"**{ fred_str } **\n { error_meta } \n ```py\n { full_error } ```" )
150153
151154 async def githook_send (self , data : dict ):
152155 self .logger .info ("Handling GitHub payload" , extra = {"data" : data })
@@ -156,7 +159,7 @@ async def githook_send(self, data: dict):
156159 self .logger .info ("Non-supported Payload received" )
157160 else :
158161 self .logger .info ("GitHub payload was supported, sending an embed" )
159- channel = self .get_channel (config .Misc .fetch ("githook_channel" ))
162+ channel = self .get_partial_messageable (config .Misc .fetch ("githook_channel" )) # type: ignore
160163 await channel .send (content = None , embed = embed )
161164
162165 async def _send_safe_direct_message_internal (
@@ -189,21 +192,19 @@ async def _send_safe_direct_message_internal(
189192 return False
190193
191194 try :
195+ dm_channel = user .dm_channel or await user .create_dm ()
192196
193- if not user .dm_channel :
194- await user .create_dm ()
195-
196- if not embed :
197+ if not embed and content is not None :
197198 embed = createembed .DM (content )
198199 content = None
199200
200- await self .safe_send (user . dm_channel , content , embed = embed , ** kwargs )
201+ await self .safe_send (dm_channel , content , embed = embed , ** kwargs )
201202 return True
202203 except Exception : # noqa
203204 self .logger .error (f"DMs: Failed to DM, reason: \n { traceback .format_exc ()} " )
204205 return False
205206
206- async def send_safe_direct_message (self , user : nextcord .User , content = None , ** kwargs ) -> bool :
207+ async def send_safe_direct_message (self , user : nextcord .User | nextcord . Member , content = None , ** kwargs ) -> bool :
207208 user_meta = config .Users .create_if_missing (user )
208209 try :
209210 return await self ._send_safe_direct_message_internal (user , content , user_meta = user_meta , ** kwargs )
@@ -213,18 +214,18 @@ async def send_safe_direct_message(self, user: nextcord.User, content=None, **kw
213214
214215 @staticmethod
215216 async def safe_send (
216- chan : nextcord .TextChannel | nextcord .DMChannel ,
217+ to : nextcord .PartialMessageable | nextcord .abc . Messageable ,
217218 content : Optional [str ],
218219 * ,
219220 files : Optional [list [nextcord .File ]] = None ,
220221 ** kwargs ,
221222 ) -> nextcord .Message :
222223 if content is not None and len (content ) > 2000 :
223- files = files or []
224+ files : list [ nextcord . File ] = files or []
224225 files .append (text2file (content , filename = "long-message.txt" ))
225226 content = "Message too long, converted to text file!"
226227
227- return await chan .send (content , files = files , ** kwargs )
228+ return await to .send (content = content , files = files , ** kwargs )
228229
229230 async def reply_to_msg (
230231 self ,
@@ -268,7 +269,8 @@ def check(message2: nextcord.Message):
268269 return (message2 .author == message .author ) and (message2 .channel == message .channel )
269270
270271 try :
271- response : nextcord .Message = await self .wait_for ("message" , timeout = 120.0 , check = check )
272+ maybe_response = self .wait_for ("message" , timeout = 120.0 , check = check )
273+ response : nextcord .Message = await maybe_response
272274 except asyncio .TimeoutError :
273275 await self .reply_to_msg (message , "Timed out and aborted after 120 seconds." )
274276 raise asyncio .TimeoutError
@@ -317,7 +319,7 @@ async def on_message(self, message: nextcord.Message):
317319 if not removed :
318320 before , space , after = message .content .partition (" " )
319321 # if the prefix is the only thing before the space then this isn't a command
320- if before .startswith (self .command_prefix ) and len (before ) > 1 :
322+ if before .startswith (str ( self .command_prefix ) ) and len (before ) > 1 :
321323 self .logger .info ("Processing commands" )
322324 await self .process_commands (message )
323325 else :
0 commit comments