Add nanoid

This commit is contained in:
Zeva Rose 2022-05-03 14:36:54 -06:00
parent aa13a556d6
commit 364119aaa2
3 changed files with 21 additions and 1 deletions

View file

@ -2,6 +2,7 @@
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import List from typing import List
import nanoid
from bson import ObjectId from bson import ObjectId
from umongo import Document, EmbeddedDocument, fields from umongo import Document, EmbeddedDocument, fields
@ -13,6 +14,11 @@ def get_now() -> datetime:
return datetime.now(tz=timezone.utc) return datetime.now(tz=timezone.utc)
def get_id() -> str:
"""Get nanoid."""
return nanoid.generate(size=16)
@JARVIS_INST.register @JARVIS_INST.register
class Action(EmbeddedDocument): class Action(EmbeddedDocument):
"""Modlog embedded action document.""" """Modlog embedded action document."""
@ -36,6 +42,7 @@ class Modlog(Document):
"""Modlog database object.""" """Modlog database object."""
user: int = fields.IntegerField(required=True) user: int = fields.IntegerField(required=True)
nanoid: str = fields.StringField(default=get_id)
guild: int = fields.IntegerField(required=True) guild: int = fields.IntegerField(required=True)
admin: int = fields.IntegerField(required=True) admin: int = fields.IntegerField(required=True)
actions: List[Action] = fields.ListField(fields.EmbeddedField(Action), factory=list) actions: List[Action] = fields.ListField(fields.EmbeddedField(Action), factory=list)

14
poetry.lock generated
View file

@ -152,6 +152,14 @@ category = "main"
optional = false optional = false
python-versions = ">=3.7" 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]] [[package]]
name = "orjson" name = "orjson"
version = "3.6.8" version = "3.6.8"
@ -319,7 +327,7 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "463b42f3391814d2fc11da3cc7d31cfeaec7e7e43cbfd9ceca031fdf5b7629ae" content-hash = "4581dae71400051e27a4fedf8d3f91303102ab0e25e4b4392fa047f865419f3a"
[metadata.files] [metadata.files]
aiohttp = [ aiohttp = [
@ -562,6 +570,10 @@ multidict = [
{file = "multidict-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:4bae31803d708f6f15fd98be6a6ac0b6958fcf68fda3c77a048a4f9073704aae"}, {file = "multidict-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:4bae31803d708f6f15fd98be6a6ac0b6958fcf68fda3c77a048a4f9073704aae"},
{file = "multidict-6.0.2.tar.gz", hash = "sha256:5ff3bd75f38e4c43f1f470f2df7a4d430b821c4ce22be384e1459cb57d6bb013"}, {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 = [ 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_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"}, {file = "orjson-3.6.8-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:5204e25c12cea58e524fc82f7c27ed0586f592f777b33075a92ab7b3eb3687c2"},

View file

@ -13,6 +13,7 @@ PyYAML = "^6.0"
pytz = "^2022.1" pytz = "^2022.1"
aiohttp = "^3.8.1" aiohttp = "^3.8.1"
rich = "^12.3.0" rich = "^12.3.0"
nanoid = "^2.0.0"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^7.1" pytest = "^7.1"