__init__.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. Initialize the modules needed for the website
  3. """
  4. import os
  5. import discord
  6. from flask import Flask
  7. from flask_sqlalchemy import SQLAlchemy
  8. from flask_migrate import Migrate
  9. from flask_login import LoginManager
  10. from flask_compress import Compress
  11. from flask_argon2 import Argon2
  12. from flask_menu import Menu
  13. from sqlalchemy import MetaData
  14. from dotenv import load_dotenv
  15. from flask_apscheduler import APScheduler
  16. from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
  17. load_dotenv()
  18. class Config(object):
  19. """Flask configuration"""
  20. UPLOAD_FOLDER = 'app/static/uploads'
  21. SCHEDULER_API_ENABLED = True
  22. SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URI"]
  23. SECRET_KEY = os.environ["SECRET_KEY"]
  24. SQLALCHEMY_TRACK_MODIFICATIONS = False
  25. SEND_FILE_MAX_AGE_DEFAULT = 1296000
  26. app = Flask(__name__)
  27. app.config.from_object(Config())
  28. app.jinja_env.lstrip_blocks = True
  29. app.jinja_env.trim_blocks = True
  30. app.config['TESTING'] = False
  31. # Compress settings
  32. COMPRESS_MIMETYPES = [
  33. 'text/html',
  34. 'text/css',
  35. 'text/xml',
  36. 'application/json',
  37. 'application/javascript'
  38. ]
  39. COMPRESS_LEVEL = 6
  40. COMPRESS_MIN_SIZE = 500
  41. Compress(app)
  42. Menu(app=app)
  43. convention = {
  44. "ix": 'ix_%(column_0_label)s',
  45. "uq": "uq_%(table_name)s_%(column_0_name)s",
  46. "ck": "ck_%(table_name)s_%(constraint_name)s",
  47. "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
  48. "pk": "pk_%(table_name)s"
  49. }
  50. metadata = MetaData(naming_convention=convention)
  51. db = SQLAlchemy(app, metadata=metadata)
  52. migrate = Migrate(app, db)
  53. argon2 = Argon2(app)
  54. scheduler = APScheduler()
  55. scheduler.init_app(app)
  56. scheduler.start()
  57. # Login
  58. login_manager = LoginManager()
  59. login_manager.init_app(app)
  60. login_manager.login_view = "auth.login"
  61. login_manager.login_message_category = "warning"
  62. class DiscordClient(discord.Client):
  63. """Class for Discord bot"""
  64. def on_ready(self):
  65. """Send message after login"""
  66. print('Logged on as', self.user)
  67. def on_message(self, message):
  68. """Read message"""
  69. # don't respond to ourselves
  70. if message.author == self.user:
  71. return
  72. if message.content == 'ping':
  73. message.channel.send('pong')