def __init__(self, *args, **kwargs): if "connector" in kwargs: warnings.warn( "If login() is called (or the bot is started), the connector will be overwritten " "with an internal one" ) super().__init__(*args, **kwargs) self.http_session: Optional[aiohttp.ClientSession] = None self.api_client = api.APIClient(loop=self.loop) self._connector = None self._resolver = None self._guild_available = asyncio.Event() statsd_url = constants.Stats.statsd_host if DEBUG_MODE: # Since statsd is UDP, there are no errors for sending to a down port. # For this reason, setting the statsd host to 127.0.0.1 for development # will effectively disable stats. statsd_url = "127.0.0.1" self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot")
def __init__(self, *args, redis_session: RedisSession, **kwargs): if "connector" in kwargs: warnings.warn( "If login() is called (or the bot is started), the connector will be overwritten " "with an internal one") super().__init__(*args, **kwargs) self.http_session: Optional[aiohttp.ClientSession] = None self.redis_session = redis_session self.api_client = api.APIClient(loop=self.loop) self.filter_list_cache = defaultdict(dict) self._connector = None self._resolver = None self._statsd_timerhandle: asyncio.TimerHandle = None self._guild_available = asyncio.Event() statsd_url = constants.Stats.statsd_host if constants.DEBUG_MODE: # Since statsd is UDP, there are no errors for sending to a down port. # For this reason, setting the statsd host to 127.0.0.1 for development # will effectively disable stats. statsd_url = LOCALHOST self.stats = AsyncStatsClient(self.loop, LOCALHOST) self._connect_statsd(statsd_url)
async def login(self, *args, **kwargs) -> None: """Re-create the connector and set up sessions before logging into Discord.""" # Use asyncio for DNS resolution instead of threads so threads aren't spammed. self._resolver = aiohttp.AsyncResolver() # Use AF_INET as its socket family to prevent HTTPS related problems both locally # and in production. self._connector = aiohttp.TCPConnector( resolver=self._resolver, family=socket.AF_INET, ) # Client.login() will call HTTPClient.static_login() which will create a session using # this connector attribute. self.http.connector = self._connector self.http_session = aiohttp.ClientSession(connector=self._connector) self.api_client = api.APIClient(connector=self._connector) if self.redis_session.closed: # If the RedisSession was somehow closed, we try to reconnect it # here. Normally, this shouldn't happen. await self.redis_session.connect() # Build the FilterList cache await self.cache_filter_list_data() await self.stats.create_socket() await super().login(*args, **kwargs)
def __init__(self, *args, **kwargs): # Use asyncio for DNS resolution instead of threads so threads aren't spammed. # Use AF_INET as its socket family to prevent HTTPS related problems both locally # and in production. self.connector = aiohttp.TCPConnector( resolver=aiohttp.AsyncResolver(), family=socket.AF_INET, ) super().__init__(*args, connector=self.connector, **kwargs) self.http_session: Optional[aiohttp.ClientSession] = None self.api_client = api.APIClient(loop=self.loop, connector=self.connector)
def __init__(self, *args, **kwargs): if "connector" in kwargs: warnings.warn( "If login() is called (or the bot is started), the connector will be overwritten " "with an internal one") super().__init__(*args, **kwargs) self.http_session: Optional[aiohttp.ClientSession] = None self.api_client = api.APIClient(loop=self.loop) self._connector = None self._resolver = None self._guild_available = asyncio.Event()