def __init__( self, token: typing.Union[str, rest_api.TokenStrategy], token_type: typing.Union[applications.TokenType, str, None] = None, public_key: typing.Union[bytes, str, None] = None, *, allow_color: bool = True, banner: typing.Optional[str] = "hikari", executor: typing.Optional[concurrent.futures.Executor] = None, force_color: bool = False, http_settings: typing.Optional[config_impl.HTTPSettings] = None, logs: typing.Union[None, int, str, typing.Dict[str, typing.Any]] = "INFO", max_rate_limit: float = 300.0, max_retries: int = 3, proxy_settings: typing.Optional[config_impl.ProxySettings] = None, rest_url: typing.Optional[str] = None, ) -> None: if isinstance(public_key, str): public_key = bytes.fromhex(public_key) if isinstance(token, str): token = token.strip() # Beautification and logging ux.init_logging(logs, allow_color, force_color) self.print_banner(banner, allow_color, force_color) # Settings and state self._close_event: typing.Optional[asyncio.Event] = None self._executor = executor self._http_settings = http_settings if http_settings is not None else config_impl.HTTPSettings() self._is_closing = False self._proxy_settings = proxy_settings if proxy_settings is not None else config_impl.ProxySettings() # Entity creation self._entity_factory = entity_factory_impl.EntityFactoryImpl(self) # RESTful API. self._rest = rest_impl.RESTClientImpl( cache=None, entity_factory=self._entity_factory, executor=self._executor, http_settings=self._http_settings, max_rate_limit=max_rate_limit, max_retries=max_retries, proxy_settings=self._proxy_settings, rest_url=rest_url, token=token, token_type=token_type, ) # IntegrationServer self._server = interaction_server_impl.InteractionServer( entity_factory=self._entity_factory, public_key=public_key, rest_client=self._rest, )
def __init__( self, token: str, *, allow_color: bool = True, banner: typing.Optional[str] = "hikari", chunking_limit: int = 200, enable_cache: bool = True, max_messages: int = 300, executor: typing.Optional[concurrent.futures.Executor] = None, force_color: bool = False, http_settings: typing.Optional[config.HTTPSettings] = None, intents: intents_.Intents = intents_.Intents.ALL_UNPRIVILEGED, logs: typing.Union[None, LoggerLevelT, typing.Dict[str, typing.Any]] = "INFO", max_rate_limit: float = 300, proxy_settings: typing.Optional[config.ProxySettings] = None, rest_url: typing.Optional[str] = None, ) -> None: # Beautification and logging ux.init_logging(logs, allow_color, force_color) self.print_banner(banner, allow_color, force_color) # Settings and state self._banner = banner self._closing_event = asyncio.Event() self._closed = False self._executor = executor self._http_settings = http_settings if http_settings is not None else config.HTTPSettings( ) self._intents = intents self._proxy_settings = proxy_settings if proxy_settings is not None else config.ProxySettings( ) self._token = token # Caching, chunking, and event subsystems. self._cache: cache.Cache self._chunker: chunker.GuildChunker self._events: event_dispatcher.EventDispatcher events_obj: event_manager_base.EventManagerBase if enable_cache: from hikari.impl import stateful_cache from hikari.impl import stateful_event_manager from hikari.impl import stateful_guild_chunker cache_obj = stateful_cache.StatefulCacheImpl( self, intents, max_messages) self._cache = cache_obj self._chunker = stateful_guild_chunker.StatefulGuildChunkerImpl( self, chunking_limit) events_obj = stateful_event_manager.StatefulEventManagerImpl( self, cache_obj, intents) self._raw_event_consumer = events_obj.consume_raw_event self._events = events_obj else: from hikari.impl import stateless_cache from hikari.impl import stateless_event_manager from hikari.impl import stateless_guild_chunker self._cache = stateless_cache.StatelessCacheImpl() self._chunker = stateless_guild_chunker.StatelessGuildChunkerImpl() events_obj = stateless_event_manager.StatelessEventManagerImpl( self, intents) self._raw_event_consumer = events_obj.consume_raw_event self._events = events_obj # Entity creation self._entity_factory = entity_factory_impl.EntityFactoryImpl(self) # Event creation self._event_factory = event_factory_impl.EventFactoryImpl(self) # Voice subsystem self._voice = voice_impl.VoiceComponentImpl(self, self._events) # RESTful API. self._rest = rest_impl.RESTClientImpl( connector_factory=rest_impl.BasicLazyCachedTCPConnectorFactory( self._http_settings), connector_owner=True, entity_factory=self._entity_factory, executor=self._executor, http_settings=self._http_settings, max_rate_limit=max_rate_limit, proxy_settings=self._proxy_settings, rest_url=rest_url, token=token, ) # We populate these on startup instead, as we need to possibly make some # HTTP requests to determine what to put in this mapping. self._shards: typing.Dict[int, shard.GatewayShard] = {} self.shards: typing.Mapping[ int, gateway_shard.GatewayShard] = types.MappingProxyType(self._shards)
def __init__( self, token: str, *, allow_color: bool = True, banner: typing.Optional[str] = "hikari", executor: typing.Optional[concurrent.futures.Executor] = None, force_color: bool = False, cache_settings: typing.Optional[config.CacheSettings] = None, http_settings: typing.Optional[config.HTTPSettings] = None, intents: intents_.Intents = intents_.Intents.ALL_UNPRIVILEGED, logs: typing.Union[None, int, str, typing.Dict[str, typing.Any]] = "INFO", max_rate_limit: float = 300, proxy_settings: typing.Optional[config.ProxySettings] = None, rest_url: typing.Optional[str] = None, ) -> None: # Beautification and logging ux.init_logging(logs, allow_color, force_color) self.print_banner(banner, allow_color, force_color) # Settings and state self._closing_event = asyncio.Event() self._closed = False self._is_alive = False self._executor = executor self._http_settings = http_settings if http_settings is not None else config.HTTPSettings() self._intents = intents self._proxy_settings = proxy_settings if proxy_settings is not None else config.ProxySettings() self._token = token # Caching cache_settings = cache_settings if cache_settings is not None else config.CacheSettings() self._cache = cache_impl.CacheImpl(self, cache_settings) # Event handling self._events = event_manager_impl.EventManagerImpl(self, cache=self._cache) # Entity creation self._entity_factory = entity_factory_impl.EntityFactoryImpl(self) # Event creation self._event_factory = event_factory_impl.EventFactoryImpl(self) # Voice subsystem self._voice = voice_impl.VoiceComponentImpl(self) # RESTful API. self._rest = rest_impl.RESTClientImpl( connector_factory=rest_impl.BasicLazyCachedTCPConnectorFactory(self._http_settings), connector_owner=True, entity_factory=self._entity_factory, executor=self._executor, http_settings=self._http_settings, max_rate_limit=max_rate_limit, proxy_settings=self._proxy_settings, rest_url=rest_url, token=token, ) # We populate these on startup instead, as we need to possibly make some # HTTP requests to determine what to put in this mapping. self._shards: typing.Dict[int, gateway_shard.GatewayShard] = {} self.shards: typing.Mapping[int, gateway_shard.GatewayShard] = types.MappingProxyType(self._shards)