@@ -90,7 +90,8 @@ def __init__(
9090 # TODO: fill in scopes= argument once we figure out what it's used for :x
9191 )
9292 self .database : asyncpg .Pool [asyncpg .Record ] = pool
93- self .pool : PoolTypedWithAny = pool # type: ignore # asyncpg typehinting crutch, read `utils.database` for more
93+ # asyncpg typehinting crutch, read `utils.database` for more
94+ self .pool : PoolTypedWithAny = pool # pyright: ignore[reportAttributeAccessIssue]
9495 self .session : ClientSession = session
9596 self .extensions : tuple [str , ...] = EXTENSIONS
9697
@@ -119,6 +120,10 @@ def __init__(
119120 # print(auth_url) # noa: T201
120121
121122 def print_bot_oauth (self ) -> None :
123+ """Print a link for me (developer) to click and authorize the bot scopes for the bot account.
124+
125+ Required for proper work of Twitch Eventsub events and API requests.
126+ """
122127 scopes = "%20" .join (
123128 [
124129 "user:read:chat" ,
@@ -135,14 +140,16 @@ def print_bot_oauth(self) -> None:
135140 print (f"🤖🤖🤖 BOT OAUTH LINK: 🤖🤖🤖\n { link } " ) # noqa: T201
136141
137142 def print_broadcaster_oauth (self ) -> None :
138- """
143+ """Print a link for streamers to click and authorize the scopes for the bot.
144+
145+ Required for proper work of Twitch Eventsub events and API requests.
139146
140147 Notes
141148 -----
142149 * Currently my developer console has localhost as a callback: http://localhost:4343/oauth/callback
143150 But if we ever switch to multi-streams setup then I already have some things set up with
144151 * https://parrot-thankful-trivially.ngrok-free.app/oauth/callback (in developer console)
145- * ngrok http --url=parrot-thankful-trivially.ngrok-free.app 80 (in my/vps terminal)
152+ * ` ngrok http --url=parrot-thankful-trivially.ngrok-free.app 80` (in my/vps terminal)
146153 Look ngrok dashboard for more.
147154
148155 With it a user needs to go to a link like this:
@@ -172,7 +179,8 @@ async def setup_hook(self) -> None:
172179 for the first time (or after adding extra scopes):
173180 1. Uncomment three first lines in this function;
174181 2. Run the bot;
175- 3. Click generated links using proper accounts (i.e. broadcaster = the browser with streamer account logged in);
182+ 3. Click generated links using proper accounts:
183+ (i.e. broadcaster = the browser with streamer account logged in);
176184 4. The bot will update the tokens in the database automatically;
177185 5. Comment the lines back. In normal state, they should be commented.
178186
@@ -188,10 +196,9 @@ async def setup_hook(self) -> None:
188196 self .check_if_online .start ()
189197
190198 async def create_eventsub_subscriptions (self ) -> None :
191- """
192- Subscribe to all EventSub subscriptions that are required for the bot to work.
193- The function also includes (in code) a table showcasing which subscriptions/scopes are required for what.
199+ """Subscribe to all EventSub subscriptions that are required for the bot to work.
194200
201+ The function also includes (in code) a table showcasing which subscriptions/scopes are required for what.
195202 For more links:
196203
197204 TwitchDev Docs
@@ -261,7 +268,7 @@ async def add_token(self, token: str, refresh: str) -> twitchio.authentication.V
261268 return resp
262269
263270 @override
264- async def load_tokens (self , path : str | None = None ) -> None :
271+ async def load_tokens (self , _ : str | None = None ) -> None : # _ is `path`
265272 # We don't need to call this manually, it is called in .login() from .start() internally...
266273
267274 rows : list [LoadTokensQueryRow ] = await self .pool .fetch ("""SELECT * from ttv_tokens""" )
@@ -328,9 +335,9 @@ async def event_command_error(self, payload: commands.CommandErrorPayload) -> No
328335 }
329336 await ctx .send (guard_mapping .get (error .guard .__qualname__ , str (error )))
330337 case twitchio .HTTPException ():
331- # log.error("%s", error.__class__.__name__, exc_info=error)
332338 await ctx .send (
333- f"{ error .extra .get ('error' , 'Error' )} { error .extra .get ('status' , 'XXX' )} : "
339+ f"{ error .extra .get ('error' , 'Error' )} "
340+ f"{ error .extra .get ('status' , 'XXX' )} : "
334341 f"{ error .extra .get ('message' , 'Unknown' )} { const .STV .dankFix } " ,
335342 )
336343 case commands .MissingRequiredArgument ():
@@ -406,19 +413,26 @@ def error_ping(self) -> str:
406413 return config .ERROR_PING
407414
408415 async def aluerie_stream (self ) -> twitchio .Stream | None :
416+ """Shortcut to get @Aluerie's stream."""
409417 return next (iter (await self .fetch_streams (user_ids = [const .UserID .Aluerie ])), None )
410418
411419 @lueloop (count = 1 )
412420 async def check_if_online (self ) -> None :
421+ """Check if aluerie is online - used to make my own (proper) online event instead of twitchio's."""
413422 await asyncio .sleep (1.0 ) # just in case;
414423 if await self .aluerie_stream ():
415424 self .aluerie_online = True
416425 self .dispatch ("aluerie_online" )
417426
418427 async def event_stream_online (self , _ : twitchio .StreamOnline ) -> None :
428+ """Instead of the twitchio event - dispatch my own online event.
429+
430+ The difference is that my event accounts for the state of my stream when the bot restarts.
431+ """
419432 self .aluerie_online = True
420433 self .dispatch ("aluerie_online" )
421434
422435 async def event_stream_offline (self , _ : twitchio .StreamOffline ) -> None :
436+ """Instead of the twitchio event - dispatch my own offline event."""
423437 self .aluerie_online = False
424438 self .dispatch ("aluerie_offline" )
0 commit comments