From 364119aaa2e9389c30137d7eecffe522a09a7e58 Mon Sep 17 00:00:00 2001 From: zevaryx Date: Tue, 3 May 2022 14:36:54 -0600 Subject: [PATCH] Add nanoid --- jarvis_core/db/models/modlog.py | 7 +++++++ poetry.lock | 14 +++++++++++++- pyproject.toml | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/jarvis_core/db/models/modlog.py b/jarvis_core/db/models/modlog.py index 378dcb4..f0593e5 100644 --- a/jarvis_core/db/models/modlog.py +++ b/jarvis_core/db/models/modlog.py @@ -2,6 +2,7 @@ from datetime import datetime, timezone from typing import List +import nanoid from bson import ObjectId from umongo import Document, EmbeddedDocument, fields @@ -13,6 +14,11 @@ def get_now() -> datetime: return datetime.now(tz=timezone.utc) +def get_id() -> str: + """Get nanoid.""" + return nanoid.generate(size=16) + + @JARVIS_INST.register class Action(EmbeddedDocument): """Modlog embedded action document.""" @@ -36,6 +42,7 @@ class Modlog(Document): """Modlog database object.""" user: int = fields.IntegerField(required=True) + nanoid: str = fields.StringField(default=get_id) guild: int = fields.IntegerField(required=True) admin: int = fields.IntegerField(required=True) actions: List[Action] = fields.ListField(fields.EmbeddedField(Action), factory=list) diff --git a/poetry.lock b/poetry.lock index 990a78e..a014e2c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -152,6 +152,14 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "nanoid" +version = "2.0.0" +description = "A tiny, secure, URL-friendly, unique string ID generator for Python" +category = "main" +optional = false +python-versions = "*" + [[package]] name = "orjson" version = "3.6.8" @@ -319,7 +327,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "463b42f3391814d2fc11da3cc7d31cfeaec7e7e43cbfd9ceca031fdf5b7629ae" +content-hash = "4581dae71400051e27a4fedf8d3f91303102ab0e25e4b4392fa047f865419f3a" [metadata.files] aiohttp = [ @@ -562,6 +570,10 @@ multidict = [ {file = "multidict-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:4bae31803d708f6f15fd98be6a6ac0b6958fcf68fda3c77a048a4f9073704aae"}, {file = "multidict-6.0.2.tar.gz", hash = "sha256:5ff3bd75f38e4c43f1f470f2df7a4d430b821c4ce22be384e1459cb57d6bb013"}, ] +nanoid = [ + {file = "nanoid-2.0.0-py3-none-any.whl", hash = "sha256:90aefa650e328cffb0893bbd4c236cfd44c48bc1f2d0b525ecc53c3187b653bb"}, + {file = "nanoid-2.0.0.tar.gz", hash = "sha256:5a80cad5e9c6e9ae3a41fa2fb34ae189f7cb420b2a5d8f82bd9d23466e4efa68"}, +] orjson = [ {file = "orjson-3.6.8-cp310-cp310-macosx_10_7_x86_64.whl", hash = "sha256:3a287a650458de2211db03681b71c3e5cb2212b62f17a39df8ad99fc54855d0f"}, {file = "orjson-3.6.8-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:5204e25c12cea58e524fc82f7c27ed0586f592f777b33075a92ab7b3eb3687c2"}, diff --git a/pyproject.toml b/pyproject.toml index e8a8cc8..608d4d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ PyYAML = "^6.0" pytz = "^2022.1" aiohttp = "^3.8.1" rich = "^12.3.0" +nanoid = "^2.0.0" [tool.poetry.dev-dependencies] pytest = "^7.1"