-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
152 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ venv/ | |
|
||
*.ini | ||
|
||
config.py | ||
config.toml | ||
|
||
.temp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"ibot", | ||
"irebot", | ||
"ireloop", | ||
"IRENESTEST", | ||
"kmmrbot", | ||
"lolrankbot", | ||
"loremipsum", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
import tomllib | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from types_.config import Config | ||
|
||
__all__ = ( | ||
"config", | ||
"replace_secrets", | ||
) | ||
|
||
|
||
with Path("config.toml").open("rb") as fp: | ||
config: Config = tomllib.load(fp) # pyright: ignore[reportAssignmentType] | ||
|
||
|
||
DO_NOT_SPOIL_LIST: list[str] = [ | ||
config["TWITCH"]["CLIENT_ID"], | ||
config["TWITCH"]["CLIENT_SECRET"], | ||
config["TOKENS"]["STEAM"], | ||
] | ||
|
||
|
||
SPOIL_PATTERN = re.compile("|".join(map(re.escape, DO_NOT_SPOIL_LIST))) | ||
|
||
|
||
def replace_secrets(text: str) -> str: | ||
"""Hide Secrets from my config files from a string.""" | ||
return SPOIL_PATTERN.sub("SECRET", text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import TypedDict | ||
|
||
__all__ = ("Config",) | ||
|
||
|
||
class Twitch(TypedDict): | ||
CLIENT_ID: str | ||
CLIENT_SECRET: str | ||
|
||
|
||
class Postgres(TypedDict): | ||
VPS: str | ||
HOME: str | ||
|
||
|
||
class SteamAccount(TypedDict): | ||
USERNAME: str | ||
PASSWORD: str | ||
|
||
|
||
class Steam(TypedDict): | ||
IRENE_ID64: int | ||
IRENESTEST: SteamAccount | ||
IRENESBOT: SteamAccount | ||
|
||
|
||
class Tokens(TypedDict): | ||
STRATZ_BEARER: str | ||
STEAM: str | ||
SPOTIFY_AIDENWALLIS: str | ||
EVENTSUB: str | ||
|
||
|
||
class Webhooks(TypedDict): | ||
ERROR: str | ||
LOGGER: str | ||
|
||
|
||
class Config(TypedDict): | ||
"""Type-hints for dictionary created from loading `config.toml` file.""" | ||
|
||
POSTGRES: Postgres | ||
STEAM: Steam | ||
TWITCH: Twitch | ||
WEBHOOKS: Webhooks | ||
TOKENS: Tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Any, override | ||
|
||
import asyncpg | ||
|
||
|
||
class PoolTypedWithAny(asyncpg.Pool[asyncpg.Record]): | ||
"""Fake Type Class. | ||
For typing purposes, our `bot.pool` will be "type-ignore"'d-as `PoolTypedWithAny` | ||
that allows us to properly type the return values via narrowing like mentioned in instructions above | ||
without hundreds of "type: ignore" notices for each TypedDict. | ||
I could use Protocol to type it all, but `async-stubs` provide a good job in typing most of the stuff | ||
and we also don't lose doc-string this way. | ||
* Right now, asyncpg is untyped so this is better than the current status quo | ||
* If we ever need the regular Pool type we have `bot.database` without any shenanigans. | ||
""" | ||
|
||
# all methods below were changed from "asyncpg.Record" to "Any" | ||
|
||
@override | ||
async def fetch(self, query: str, *args: Any, timeout: float | None = None) -> list[Any]: ... | ||
|
||
@override | ||
async def fetchrow(self, query: str, *args: Any, timeout: float | None = None) -> Any: ... |
Oops, something went wrong.