12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- """
- Initialize the modules needed for the website
- """
- import os
- import discord
- from flask import Flask
- from flask_sqlalchemy import SQLAlchemy
- from flask_migrate import Migrate
- from flask_login import LoginManager
- from flask_compress import Compress
- from flask_argon2 import Argon2
- from flask_menu import Menu
- from sqlalchemy import MetaData
- from dotenv import load_dotenv
- from flask_apscheduler import APScheduler
- from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
- load_dotenv()
- class Config(object):
- """Flask configuration"""
- UPLOAD_FOLDER = 'app/static/uploads'
- SCHEDULER_API_ENABLED = True
- SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URI"]
- SECRET_KEY = os.environ["SECRET_KEY"]
- SQLALCHEMY_TRACK_MODIFICATIONS = False
- SEND_FILE_MAX_AGE_DEFAULT = 1296000
- app = Flask(__name__)
- app.config.from_object(Config())
- app.jinja_env.lstrip_blocks = True
- app.jinja_env.trim_blocks = True
- app.config['TESTING'] = False
- # Compress settings
- COMPRESS_MIMETYPES = [
- 'text/html',
- 'text/css',
- 'text/xml',
- 'application/json',
- 'application/javascript'
- ]
- COMPRESS_LEVEL = 6
- COMPRESS_MIN_SIZE = 500
- Compress(app)
- Menu(app=app)
- convention = {
- "ix": 'ix_%(column_0_label)s',
- "uq": "uq_%(table_name)s_%(column_0_name)s",
- "ck": "ck_%(table_name)s_%(constraint_name)s",
- "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
- "pk": "pk_%(table_name)s"
- }
- metadata = MetaData(naming_convention=convention)
- db = SQLAlchemy(app, metadata=metadata)
- migrate = Migrate(app, db)
- argon2 = Argon2(app)
- scheduler = APScheduler()
- scheduler.init_app(app)
- scheduler.start()
- # Login
- login_manager = LoginManager()
- login_manager.init_app(app)
- login_manager.login_view = "auth.login"
- login_manager.login_message_category = "warning"
- class DiscordClient(discord.Client):
- """Class for Discord bot"""
- def on_ready(self):
- """Send message after login"""
- print('Logged on as', self.user)
- def on_message(self, message):
- """Read message"""
- # don't respond to ourselves
- if message.author == self.user:
- return
- if message.content == 'ping':
- message.channel.send('pong')
|