diff --git a/.flake8 b/.flake8 index c747e10..4864a54 100644 --- a/.flake8 +++ b/.flake8 @@ -11,6 +11,7 @@ extend-ignore = D401, # First line should be in imperative mood; try rephrasing D400, # First line should end with a period D101, # Missing docstring in public class + D106, # Missing docstring in public nested class # Plugins we don't currently include: flake8-return R503, # missing explicit return at the end of function ableto return non-None value. diff --git a/jarvis_core/db/models.py b/jarvis_core/db/models.py index e8325ad..ffb0019 100644 --- a/jarvis_core/db/models.py +++ b/jarvis_core/db/models.py @@ -197,6 +197,9 @@ class TwitterAccount(Document): last_tweet = fields.IntegerField(required=True) last_sync = fields.DateTimeField(default=datetime.utcnow) + class Meta: + collection_name = "twitteraccount" + @JARVIS_INST.register class TwitterFollow(Document): @@ -210,6 +213,9 @@ class TwitterFollow(Document): admin = fields.IntegerField(required=True) created_at = fields.DateTimeField(default=datetime.utcnow) + class Meta: + collection_name = "twitterfollow" + @JARVIS_INST.register class Unban(Document): diff --git a/jarvis_core/util/ansi.py b/jarvis_core/util/ansi.py new file mode 100644 index 0000000..af470e3 --- /dev/null +++ b/jarvis_core/util/ansi.py @@ -0,0 +1,75 @@ +"""ANSI color helper.""" +from enum import Enum, EnumMeta +from typing import Any, List + +ESCAPE = "\u001b" +RESET = ESCAPE + "[0m" + + +class SearchableEnum(EnumMeta): + def __contains__(cls, item: Any): + return item in [v.value for v in cls.__members__.values()] + + +class Format(Enum, metaclass=SearchableEnum): + NORMAL = 0 + BOLD = 1 + UNDERLINE = 4 + + +class Fore(Enum, metaclass=SearchableEnum): + GRAY = 30 + RED = 31 + GREEN = 32 + YELLOW = 33 + BLUE = 34 + PINK = 35 + CYAN = 36 + WHITE = 37 + + +class Back(Enum, metaclass=SearchableEnum): + DARK_BLUE = 40 + ORANGE = 41 + DARK_GRAY = 42 + GRAY = 43 + LIGHT_GRAY = 44 + INDIGO = 45 + LIGHTER_GRAY = 46 + WHITE = 47 + + +def fmt(*formats: List[Format | Fore | Back] | int) -> str: + """ + Get format string. + + Args: + formats: List of format modifiers + + Return: + Format string + """ + fore = "" + back = "" + fmt = "" + block_fmt = False + for f in formats: + if isinstance(f, Enum): + f = f.value + if f == 0: + fmt = "0;" + elif f in [1, 4]: + if str(f) not in fmt and not block_fmt: + fmt += f"{f};" + elif 30 <= f <= 37: + fore = f"{f};" + elif 40 <= f <= 47: + back = f"{f};" + + ret = fmt + fore + back + if not any(ret, fore, back): + ret = RESET + if ret[-1] == ";": + ret = ret[:-1] + + return ESCAPE + "[" + ret + "m" diff --git a/pyproject.toml b/pyproject.toml index d3e7507..f2ec084 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jarvis-core" -version = "0.4.1" +version = "0.5.0" description = "" authors = ["Your Name "]