Exemplo n.º 1
0
    def __init__(self):
        self.config = get_config()
        if not os.isdir("logs"):
            os.mkdir("logs")
        super().__init__(
            command_prefix=self.config["bot"]["prefix"],
            intents=discord.Intents.all(),
            activity=discord.Game(self.config["bot"]["status"]),
            help_command=None,
        )
        self.discord = Logger.discordLogger()
        self.logger = Logger.defaultLogger("EasyGameBot")

        self.con = connect_database(self.config["database"]["path"])
Exemplo n.º 2
0
import sqlite3
from typing import List, Dict, Union
from src.utils.logger import Logger
import json

logger = Logger.defaultLogger("DB")


def connect_database(path: str) -> sqlite3.Connection:
    con = sqlite3.connect(path)
    cur = con.cursor()

    cur.execute("SELECT COUNT(*) FROM sqlite_master WHERE name='users'")
    if cur.fetchone()[0] == 0:
        logger.info("DB 셋업 (users)")
        cur.execute("CREATE TABLE users ("
                    "id text, money text, items integer,"
                    "join_time text, check_time text, stock text)")
        con.commit()

    cur.execute("SELECT COUNT(*) FROM sqlite_master WHERE name='stocks'")
    if cur.fetchone()[0] == 0:
        logger.info("DB 셋업 (stocks)")
        cur.execute(
            "CREATE TABLE stocks(name text, price text, cap text, history text)"
        )
        con.commit()

    return con