-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
135 lines (95 loc) · 3.66 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from flask import Flask
from flask_apscheduler import APScheduler
from flask_limiter import Limiter
from flask_mail import Mail, Message
from Routes.AuthenticationHandler import *
from Routes.Servers import *
from Routes.Store import *
from Routes.Admin import *
from Routes.Tickets import *
from flask_session import Session
from multiprocessing import Process
from bot import enable_bot
import asyncio
import random
from scripts import *
from cacheext import cache
#This imports the bot's code ONLY if the user wishes to use it
app = Flask(__name__, "/static")
app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 # Limit to 16 MB
cache.init_app(app)
def rate_limit_key():
# Replace 'user_id' with the actual key used to store the user identifier in the session
user_identifier = session.get('random_id', None)
print(user_identifier, 1)
return user_identifier
limiter = Limiter(rate_limit_key, app=app, default_limits=["200 per day", "50 per hour"])
limiter.limit("20 per hour", key_func=rate_limit_key)(user)
limiter.limit("15 per hour", key_func=rate_limit_key)(servers)
limiter.limit("15 per hour", key_func=rate_limit_key)(tickets)
limiter.limit("10 per hour", key_func=rate_limit_key)(store)
app.register_blueprint(user)
app.register_blueprint(servers, url_prefix="/servers")
app.register_blueprint(store, url_prefix="/store")
app.register_blueprint(admin, url_prefix="/admin")
app.register_blueprint(tickets, url_prefix="/tickets")
class Config:
SCHEDULER_API_ENABLED = True
app.config["SESSION_PERMANENT"] = True
app.config["SESSION_TYPE"] = "filesystem"
app.config["SECRET_KEY"] = SECRET_KEY
# Initialize the session
Session(app)
app.config.from_object(Config())
# initialize scheduler
scheduler = APScheduler()
# if you don't want to use a config, you can set options here:
# scheduler.api_enabled = True
scheduler.init_app(app)
app.config['MAIL_SERVER'] = MAIL_SERVER
app.config['MAIL_PORT'] = MAIL_PORT
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = MAIL_USERNAME
app.config['MAIL_PASSWORD'] = MAIL_PASSWORD
app.config['MAIL_DEFAULT_SENDER'] = MAIL_DEFAULT_SENDER
app.config['RECAPTCHA_PUBLIC_KEY'] = RECAPTCHA_SITE_KEY
app.config['RECAPTCHA_PRIVATE_KEY'] = RECAPTCHA_SECRET_KEY
mail = Mail(app)
# Configuration for Flask-Caching
@scheduler.task('interval', id='do_job_1', seconds=3600, misfire_grace_time=900)
def job1():
print("started using credits")
use_credits()
print("finished job 1")
@scheduler.task('interval', id='do_job_2', seconds=180, misfire_grace_time=900)
def job2():
print("started job2 (check to unsuspend)")
check_to_unsuspend()
print("finished job 2")
job_has_run = False
@scheduler.task('interval', id='do_run_job', seconds=5, misfire_grace_time=900)
def run_job():
global job_has_run
if not job_has_run:
asyncio.run(enable_bot())
job_has_run = True
@scheduler.task('interval', id='do_sync_users', seconds=3600, misfire_grace_time=900)
def sync_users():
print("started users sync")
sync_users_script()
pterocache.update_all()
print("finished job users sync")
scheduler.start()
@app.route('/')
def index():
if 'email' not in session:
return redirect(url_for("user.login_user"))
after_request(session=session, request=request.environ, require_login=True)
if __name__ == '__main__':
# Create separate processes for Flask and the Discord bot
webhook_log("**----------------DASHBOARD HAS STARTED UP----------------**")
app.run(debug=False, host="0.0.0.0", port=1137)
def webhook_log(message: str):
resp = requests.post(WEBHOOK_URL,
json={"username": "Web Logs", "content": message})
print(resp.text)