Skip to content

Commit

Permalink
more unique IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
koeqaife committed Jul 9, 2024
1 parent d97e907 commit dc529f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from redis import Redis
import traceback

VERSION = 2
VERSION = 3
db_manager = core.AsyncDatabaseConnectionManager()

core.init_logging(logging.INFO, True, True, other_logs=True)
Expand Down Expand Up @@ -442,7 +442,7 @@ async def ping():
async def info():
return jsonify({
"success": True,
"rate_limit": config["rate_limit"],
"max_rate_limit": config["rate_limit"],
"version": VERSION
})

Expand Down
39 changes: 36 additions & 3 deletions functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 1.2
# 1.3
import os
import string
import aiosqlite
import random
import re
Expand Down Expand Up @@ -166,16 +167,48 @@ async def decrypt_message_async(encrypted_message: str | bytes, private_key: byt
return await asyncio.to_thread(decrypt_message, encrypted_message, private_key, passphrase)


def generate_chars():
digits = string.digits
base61_chars = digits + string.ascii_letters + punctuation()
return base61_chars


def punctuation():
unwanted_chars = "/\\:*?\"<>|-"
valid_punctuation = ''.join(c for c in string.punctuation if c not in unwanted_chars)
return valid_punctuation


def compress_int(num: int):
if num == 0:
return '0'

chars = generate_chars()
output = ''
is_negative = num < 0
num = abs(num)

while num > 0:
output = chars[num % len(chars)] + output
num //= len(chars)

if is_negative:
output = '-' + output

return output


def get_room_id(passphrase: str) -> int:
passphrase = sha512(passphrase)
return random.Random(passphrase).randint(0, 10**25)
return random.Random(passphrase).randint(-2**128, 2**128)


def room_db(id: int) -> str:
folder = './rooms/'
_id = compress_int(id)
if not os.path.exists(folder):
os.makedirs(folder)
return f"{folder}{id}.db"
return f"{folder}{_id}.db"


class Room():
Expand Down

0 comments on commit dc529f5

Please sign in to comment.