<filename>lib/utils.py<gh_stars>0
"""utility library for useful functions"""

import os
import json


def mention_to_id(mention):
    result = 0

    try:
        result = int(
            mention
            .replace("<", "")
            .replace(">", "")
            .replace("!", "")
            .replace("@", "")
        )
    except Exception:
        result = 0

    return result


def setup_user_env(user_id: int):
    os.mkdir(f"users/{user_id}")

    if not os.path.isdir(f"users/{user_id}/mails"):
        os.mkdir(f"users/{user_id}/mails")
    if not os.path.isdir(f"users/{user_id}/inbox"):
        os.mkdir(f"users/{user_id}/inbox")
    if not os.path.isdir(f"users/{user_id}/outbox"):
        os.mkdir(f"users/{user_id}/outbox")

    config = {
        "states": {
            "editing": None
        }
    }

    open(f"users/{user_id}/user.json", 'w').write(json.dumps(config))
