Skip to content

Commit

Permalink
Merge pull request #143 from nekokatt/task/remove-constants
Browse files Browse the repository at this point in the history
Removed constants module mess.
  • Loading branch information
Nekokatt authored Sep 8, 2020
2 parents 70396cd + c907544 commit b4c5042
Show file tree
Hide file tree
Showing 42 changed files with 250 additions and 293 deletions.
1 change: 0 additions & 1 deletion hikari/api/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from hikari import users
from hikari import voices


_KeyT = typing.TypeVar("_KeyT", bound=typing.Hashable)
_ValueT = typing.TypeVar("_ValueT")

Expand Down
1 change: 0 additions & 1 deletion hikari/api/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from hikari import guilds
from hikari import snowflakes


_VoiceConnectionT = typing.TypeVar("_VoiceConnectionT", bound="VoiceConnection")


Expand Down
8 changes: 4 additions & 4 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
from hikari import files
from hikari import guilds
from hikari import snowflakes
from hikari import urls
from hikari.utilities import attr_extensions
from hikari.utilities import constants
from hikari.utilities import routes

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -360,7 +360,7 @@ def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[
return None

return routes.CDN_TEAM_ICON.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
team_id=self.id,
hash=self.icon_hash,
size=size,
Expand Down Expand Up @@ -486,7 +486,7 @@ def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[
return None

return routes.CDN_APPLICATION_ICON.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
application_id=self.id,
hash=self.icon_hash,
size=size,
Expand Down Expand Up @@ -531,7 +531,7 @@ def format_cover_image(self, *, ext: str = "png", size: int = 4096) -> typing.Op
return None

return routes.CDN_APPLICATION_COVER.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
application_id=self.id,
hash=self.cover_image_hash,
size=size,
Expand Down
4 changes: 2 additions & 2 deletions hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
from hikari import permissions
from hikari import snowflakes
from hikari import undefined
from hikari import urls
from hikari import users
from hikari.utilities import attr_extensions
from hikari.utilities import constants
from hikari.utilities import routes

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -488,7 +488,7 @@ def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[
return None

return routes.CDN_CHANNEL_ICON.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
channel_id=self.id,
hash=self.icon_hash,
size=size,
Expand Down
10 changes: 6 additions & 4 deletions hikari/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import attr

from hikari.utilities import attr_extensions
from hikari.utilities import constants
from hikari.utilities import data_binding

_BASICAUTH_TOKEN_PREFIX: typing.Final[str] = "Basic" # nosec
_PROXY_AUTHENTICATION_HEADER: typing.Final[str] = "Proxy-Authentication"


@attr_extensions.with_copy
@attr.s(slots=True, kw_only=True, repr=False, weakref_slot=False)
Expand All @@ -56,7 +58,7 @@ def header(self) -> str:
"""Generate the header value and return it."""
raw_token = f"{self.username}:{self.password}".encode("ascii")
token_part = base64.b64encode(raw_token).decode("ascii")
return f"{constants.BASICAUTH_TOKEN_PREFIX} {token_part}"
return f"{_BASICAUTH_TOKEN_PREFIX} {token_part}"

def __str__(self) -> str:
return self.header
Expand Down Expand Up @@ -101,11 +103,11 @@ def all_headers(self) -> typing.Optional[data_binding.Headers]:
if self.headers is None:
if self.auth is None:
return None
return {constants.PROXY_AUTHENTICATION_HEADER: self.auth}
return {_PROXY_AUTHENTICATION_HEADER: self.auth}

if self.auth is None:
return self.headers
return {**self.headers, constants.PROXY_AUTHENTICATION_HEADER: self.auth}
return {**self.headers, _PROXY_AUTHENTICATION_HEADER: self.auth}


@attr_extensions.with_copy
Expand Down
1 change: 0 additions & 1 deletion hikari/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
if typing.TYPE_CHECKING:
import concurrent.futures


AsyncReaderT = typing.TypeVar("AsyncReaderT", bound=files.AsyncReader)


Expand Down
8 changes: 5 additions & 3 deletions hikari/emojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@

from hikari import files
from hikari import snowflakes
from hikari import urls
from hikari.utilities import attr_extensions
from hikari.utilities import constants
from hikari.utilities import routes

if typing.TYPE_CHECKING:
from hikari import traits
from hikari import users

_TWEMOJI_PNG_BASE_URL: typing.Final[str] = "https://github.com/twitter/twemoji/raw/master/assets/72x72/"


@attr.s(eq=True, hash=True, init=True, kw_only=True, slots=True, weakref_slot=False)
class Emoji(files.WebResource, abc.ABC):
Expand Down Expand Up @@ -161,7 +163,7 @@ def url(self) -> str:
-------
https://github.com/twitter/twemoji/raw/master/assets/72x72/1f004.png
"""
return constants.TWEMOJI_PNG_BASE_URL + self.filename
return _TWEMOJI_PNG_BASE_URL + self.filename

@property
@typing.final
Expand Down Expand Up @@ -269,7 +271,7 @@ def is_mentionable(self) -> bool:
def url(self) -> str:
ext = "gif" if self.is_animated else "png"

return routes.CDN_CUSTOM_EMOJI.compile(constants.CDN_URL, emoji_id=self.id, file_format=ext)
return routes.CDN_CUSTOM_EMOJI.compile(urls.CDN_URL, emoji_id=self.id, file_format=ext)


@attr.s(eq=True, hash=True, init=True, kw_only=True, slots=True, weakref_slot=False)
Expand Down
1 change: 0 additions & 1 deletion hikari/events/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
if typing.TYPE_CHECKING:
import types


T = typing.TypeVar("T")
REQUIRED_INTENTS_ATTR: typing.Final[str] = "___requiresintents___"
NO_RECURSIVE_THROW_ATTR: typing.Final[str] = "___norecursivethrow___"
Expand Down
3 changes: 3 additions & 0 deletions hikari/events/channel_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ class GuildPinsUpdateEvent(PinsUpdateEvent, GuildChannelEvent):
# <<inherited docstring from GuildChannelEvent>>.

last_pin_timestamp: typing.Optional[datetime.datetime] = attr.ib(repr=True)

# <<inherited docstring from ChannelPinsUpdateEvent>>.

@property
Expand Down Expand Up @@ -585,6 +586,7 @@ class PrivatePinsUpdateEvent(PinsUpdateEvent, PrivateChannelEvent):
# <<inherited docstring from ChannelEvent>>.

last_pin_timestamp: typing.Optional[datetime.datetime] = attr.ib(repr=True)

# <<inherited docstring from ChannelPinsUpdateEvent>>.

@property
Expand Down Expand Up @@ -732,6 +734,7 @@ class WebhookUpdateEvent(GuildChannelEvent):
# <<inherited docstring from ChannelEvent>>.

guild_id: snowflakes.Snowflake = attr.ib()

# <<inherited docstring from GuildChannelEvent>>.

async def fetch_channel_webhooks(self) -> typing.Sequence[webhooks.Webhook]:
Expand Down
3 changes: 3 additions & 0 deletions hikari/events/guild_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class BanCreateEvent(BanEvent):
# <<inherited docstring from GuildEvent>>.

user: users.User = attr.ib()

# <<inherited docstring from BanEvent>>.

async def fetch_ban(self) -> guilds.GuildMemberBan:
Expand Down Expand Up @@ -383,6 +384,7 @@ class BanDeleteEvent(BanEvent):
# <<inherited docstring from GuildEvent>>.

user: users.User = attr.ib()

# <<inherited docstring from BanEvent>>.

# Sure, I could allow delete_message_days here, but... is there any point?
Expand Down Expand Up @@ -461,6 +463,7 @@ class IntegrationsUpdateEvent(GuildEvent):
# <<inherited docstring from ShardEvent>>.

guild_id: snowflakes.Snowflake = attr.ib()

# <<inherited docstring from ShardEvent>>.

async def fetch_integrations(self) -> typing.Sequence[guilds.Integration]:
Expand Down
6 changes: 6 additions & 0 deletions hikari/events/message_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class GuildMessageCreateEvent(GuildMessageEvent, MessageCreateEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.Message = attr.ib()

# <<inherited docstring from MessageCreateEvent>>.

@property
Expand All @@ -314,6 +315,7 @@ class PrivateMessageCreateEvent(PrivateMessageEvent, MessageCreateEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.Message = attr.ib()

# <<inherited docstring from MessageCreateEvent>>.

@property
Expand All @@ -335,6 +337,7 @@ class GuildMessageUpdateEvent(GuildMessageEvent, MessageUpdateEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.PartialMessage = attr.ib()

# <<inherited docstring from MessageUpdateEvent>>.

@property
Expand All @@ -359,6 +362,7 @@ class PrivateMessageUpdateEvent(PrivateMessageEvent, MessageUpdateEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.PartialMessage = attr.ib()

# <<inherited docstring from MessageUpdateEvent>>.

@property
Expand All @@ -380,6 +384,7 @@ class GuildMessageDeleteEvent(GuildMessageEvent, MessageDeleteEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.PartialMessage = attr.ib()

# <<inherited docstring from MessageDeleteEvent>>.

@property
Expand All @@ -402,6 +407,7 @@ class PrivateMessageDeleteEvent(PrivateMessageEvent, MessageDeleteEvent):
# <<inherited docstring from ShardEvent>>.

message: messages.PartialMessage = attr.ib()

# <<inherited docstring from MessageDeleteEvent>>.

@property
Expand Down
1 change: 1 addition & 0 deletions hikari/events/reaction_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class GuildReactionAddEvent(GuildReactionEvent, ReactionAddEvent):
# <<inherited docstring from ReactionEvent>>.

emoji: emojis.Emoji = attr.ib()

# <<inherited docstring from ReactionAddEvent>>.

@property
Expand Down
1 change: 1 addition & 0 deletions hikari/events/typing_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class PrivateTypingEvent(TypingEvent):
# <<inherited docstring from TypingEvent>>.

timestamp: datetime.datetime = attr.ib(repr=False)

# <<inherited docstring from TypingEvent>>.

@property
Expand Down
2 changes: 0 additions & 2 deletions hikari/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@

_MAGIC: typing.Final[int] = 50 * 1024


ReaderImplT = typing.TypeVar("ReaderImplT", bound="AsyncReader")
ReaderImplT_co = typing.TypeVar("ReaderImplT_co", bound="AsyncReader", covariant=True)


Pathish = typing.Union["os.PathLike[str]", str]
"""Type hint representing a literal file or path.
Expand Down
14 changes: 7 additions & 7 deletions hikari/guilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@

from hikari import files
from hikari import snowflakes
from hikari import urls
from hikari import users
from hikari.utilities import attr_extensions
from hikari.utilities import constants
from hikari.utilities import flag
from hikari.utilities import routes

Expand Down Expand Up @@ -684,7 +684,7 @@ def format_icon(self, *, ext: typing.Optional[str] = None, size: int = 4096) ->
ext = "png"

return routes.CDN_GUILD_ICON.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.icon_hash,
size=size,
Expand Down Expand Up @@ -745,7 +745,7 @@ def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optiona
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.splash_hash,
size=size,
Expand Down Expand Up @@ -783,7 +783,7 @@ def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typi
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.discovery_splash_hash,
size=size,
Expand Down Expand Up @@ -981,7 +981,7 @@ def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optiona
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.splash_hash,
size=size,
Expand Down Expand Up @@ -1019,7 +1019,7 @@ def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typi
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.discovery_splash_hash,
size=size,
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def format_banner(self, *, ext: str = "png", size: int = 4096) -> typing.Optiona
return None

return routes.CDN_GUILD_BANNER.compile_to_file(
constants.CDN_URL,
urls.CDN_URL,
guild_id=self.id,
hash=self.banner_hash,
size=size,
Expand Down
15 changes: 6 additions & 9 deletions hikari/impl/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from hikari.impl import shard as shard_impl
from hikari.impl import voice as voice_impl
from hikari.utilities import aio
from hikari.utilities import constants
from hikari.utilities import date
from hikari.utilities import event_stream
from hikari.utilities import ux
Expand Down Expand Up @@ -174,11 +173,11 @@ class BotApp(traits.BotAware, event_dispatcher.EventDispatcher):
proxy_settings : typing.Optional[config.ProxySettings]
If specified, custom proxy settings to use with network-layer logic
in your application to get through an HTTP-proxy.
rest_url : builtins.str
Defaults to the Discord REST API URL. Can be overridden if you are
attempting to point to an unofficial endpoint, or if you are attempting
to mock/stub the Discord API for any reason. Generally you do not want
to change this.
rest_url : typing.Optional[builtins.str]
Defaults to the Discord REST API URL if `builtins.None`. Can be
overridden if you are attempting to point to an unofficial endpoint, or
if you are attempting to mock/stub the Discord API for any reason.
Generally you do not want to change this.
!!! note
`force_color` will always take precedence over `allow_color`.
Expand Down Expand Up @@ -226,7 +225,7 @@ def __init__(
intents: intents_.Intents = intents_.Intents.ALL_UNPRIVILEGED,
logs: typing.Union[None, LoggerLevelT, typing.Dict[str, typing.Any]] = "INFO",
proxy_settings: typing.Optional[config.ProxySettings] = None,
rest_url: str = constants.REST_API_URL,
rest_url: typing.Optional[str] = None,
) -> None:
# Beautification and logging
ux.init_logging(logs, allow_color, force_color)
Expand Down Expand Up @@ -292,8 +291,6 @@ def __init__(
proxy_settings=self._proxy_settings,
rest_url=rest_url,
token=token,
token_type=constants.BOT_TOKEN_PREFIX,
version=6,
)

# We populate these on startup instead, as we need to possibly make some
Expand Down
Loading

0 comments on commit b4c5042

Please sign in to comment.