2828import datetime
2929import logging
3030from collections import deque
31- from typing import TYPE_CHECKING , Any , cast
31+ from typing import TYPE_CHECKING , Any , TypeVar , cast
3232from urllib .parse import unquote_plus
3333
3434from aiohttp import web
5454__all__ = ("AiohttpAdapter" ,)
5555
5656
57+ BT = TypeVar ("BT" , bound = "Client" )
5758logger : logging .Logger = logging .getLogger (__name__ )
5859
5960
60- class AiohttpAdapter (BaseAdapter , web .Application ):
61+ class AiohttpAdapter (BaseAdapter [ BT ] , web .Application ):
6162 """The AiohttpAdapter for OAuth and Webhook based EventSub.
6263
6364 This adapter uses ``aiohttp`` which is a base dependency and should be installed and available with Twitchio.
@@ -113,6 +114,9 @@ class AiohttpAdapter(BaseAdapter, web.Application):
113114 E.g. ``http://localhost:4343/oauth/callback`` or ``https://mydomain.org/oauth/callback``.
114115 ssl_context: SSLContext | None
115116 An optional :class:`SSLContext` passed to the adapter. If SSL is setup via a front-facing web server such as NGINX, you should leave this as None.
117+ client: :class:`~twitchio.Client` | None
118+ An optional :class:`~twitchio.Client` or any derivative such as :class:`~twitchio.ext.commands.Bot` to set for this
119+ adapter. When ``None`` the client will be set automatically after initalization. Defaults to ``None``.
116120
117121 Examples
118122 --------
@@ -141,7 +145,7 @@ def __init__(self) -> None:
141145 super().__init__(adapter=adapter)
142146 """
143147
144- client : Client
148+ client : BT
145149
146150 def __init__ (
147151 self ,
@@ -154,8 +158,13 @@ def __init__(
154158 oauth_path : str | None = None ,
155159 redirect_path : str | None = None ,
156160 ssl_context : SSLContext | None = None ,
161+ client : BT | None = None ,
157162 ) -> None :
158163 super ().__init__ ()
164+
165+ if client :
166+ self .client = client
167+
159168 self ._runner : web .AppRunner | None = None
160169
161170 self ._host : str = host or "localhost"
@@ -194,7 +203,7 @@ def __init__(
194203 self ._responded : deque [str ] = deque (maxlen = 5000 )
195204 self ._running : bool = False
196205
197- def __init_subclass__ (cls : type [AiohttpAdapter ]) -> None :
206+ def __init_subclass__ (cls : type [AiohttpAdapter [ BT ] ]) -> None :
198207 return
199208
200209 def __repr__ (self ) -> str :
0 commit comments