Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
osef
Browse files Browse the repository at this point in the history
  • Loading branch information
haysberg committed Nov 8, 2023
1 parent 1beb48d commit ed9e5bd
Show file tree
Hide file tree
Showing 6 changed files with 1,119 additions and 37 deletions.
17 changes: 6 additions & 11 deletions kayo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import dotenv
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from peewee import *

dotenv.load_dotenv()
LOGLEVEL = os.environ.get('LOGLEVEL').upper()
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()


class BotContext:
Expand All @@ -27,23 +28,17 @@ def __init__(self):
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(message)s'))
self.logger.addHandler(handler)

if LOGLEVEL == "DEBUG":
logging.getLogger("sqlalchemy.engine").setLevel(level=LOGLEVEL)

self.http_client = aiohttp.ClientSession()

if os.getenv("DEPLOYED") == "production":
self.engine = (create_engine("sqlite:///db/kayo.db"))
self.db = SqliteDatabase("sqlite:///db/kayo.db")
else:
self.engine = (create_engine("sqlite:///:memory:", echo=True))
self.db = SqliteDatabase("sqlite:///:memory:")

Session = sessionmaker(bind=self.engine)
global session
self.session = Session()
global db

# Initializing core objects
if os.environ.get('DEPLOYED').upper() == "PRODUCTION":
if os.environ.get('DEPLOYED', 'DEBUG').upper() == "PRODUCTION":
self.bot = discord.Bot()
else:
self.bot = discord.Bot(debug_guilds=[int(os.environ.get('DEBUG_GUILD'))])
Expand Down
13 changes: 2 additions & 11 deletions kayo/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
from datetime import datetime
from datetime import timedelta
from typing import Optional

from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy.dialects.sqlite import insert
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import relationship
from peewee import *

from kayo import instance
from kayo.league import League
from kayo.model import Base


class Match(Base):
class Match(Model):
"""Represents a Match between two teams.
Args:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def updateDatabase():
fetch_leagues()
await fetch_events_and_teams()

if os.environ.get('DEPLOYED').upper() != "PRODUCTION":
if os.environ.get('DEPLOYED', 'DEBUG').upper() != "PRODUCTION":
@instance.bot.slash_command(name="debug_alert", description="DO NOT USE ON YOUR SERVER !")
@commands.has_permissions(manage_roles=True, ban_members=True)
async def debug_alerts(ctx):
Expand Down
Loading

0 comments on commit ed9e5bd

Please sign in to comment.