refresh chat automatically when orgy starts

master
Aevann 2023-09-26 15:29:36 +03:00
parent 204c756de5
commit c9f3b95f86
5 changed files with 18 additions and 17 deletions

View File

@ -313,6 +313,10 @@ socket.on('delete', function(text) {
}
})
socket.on('refresh_chat', () => {
location.reload()
})
document.addEventListener('click', function (e) {
if (e.target.classList.contains('delconfirm')) {
e.target.nextElementSibling.classList.remove('d-none');
@ -362,20 +366,3 @@ setTimeout(function () {
document.addEventListener('DOMContentLoaded', function () {
box.scrollTo(0, box.scrollHeight)
});
const now = new Date();
const day_of_week = now.getUTCDay()
if ([4,5,7].includes(day_of_week)) {
let hour
if (day_of_week == 7) hour = 20
else hour = 0
let millis = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), hour, 0, 10) - now;
if (millis < 0)
millis += 86400000;
const minutes = Math.round(millis/1000/60*10)/10
console.log(`Refreshing page in ${minutes} minutes`)
setTimeout(() => location.reload(), millis);
}

View File

@ -97,6 +97,7 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
if every_sat_00 or every_sun_20:
_create_orgy()
g.db.commit()
requests.get(f'{SITE_FULL}/refresh_chat')
if every_sat_03 or every_sun_23:
_delete_all_posts()

View File

@ -1978,10 +1978,14 @@ def start_orgy(v):
)
g.db.add(orgy)
g.db.commit()
requests.get(f'{SITE_FULL}/refresh_chat')
return redirect('/chat')
@app.post("/admin/stop_orgy")
@admin_level_required(PERMS['ORGIES'])
def stop_orgy(v):
g.db.query(Orgy).delete()
requests.get(f'{SITE_FULL}/refresh_chat')
return {"message": "Orgy stopped successfully!"}

View File

@ -61,6 +61,11 @@ def is_not_banned_socketio(f):
CHAT_ERROR_MESSAGE = f"To prevent spam, you'll need {TRUESCORE_CC_CHAT_MINIMUM} truescore (this is {TRUESCORE_CC_CHAT_MINIMUM} votes, either up or down, on any threads or comments you've made) in order to access chat. Sorry! I love you 💖"
@app.get('/refresh_chat')
def refresh_chat():
emit('refresh_chat', namespace='/', to=f'{SITE_FULL}/chat')
return ''
@app.get("/chat")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)

View File

@ -24,6 +24,10 @@ server {
proxy_pass http://localhost:5001/chat;
include includes/headers;
}
location /refresh_chat {
proxy_pass http://localhost:5001/refresh_chat;
include includes/headers;
}
location =/offline.html {
alias /d/files/templates/errors/offline.html;