holiday event manager (actually works now edition) (#22)
Co-authored-by: Snakes <duolsm@outlook.com> Co-authored-by: justcool393 <justcool393@gmail.com> Reviewed-on: rDrama/rDrama#22 Co-authored-by: geese_suck <deandre.williams@geese-suck.us> Co-committed-by: geese_suck <deandre.williams@geese-suck.us>pull/31/head
parent
4fcbf574bf
commit
a3fa96242c
|
@ -1,4 +1,4 @@
|
|||
.*
|
||||
.env
|
||||
venv/
|
||||
__pycache__/
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from os import environ
|
|||
from sys import argv, stdout
|
||||
|
||||
import gevent
|
||||
import redis
|
||||
from flask import Flask
|
||||
from flask_caching import Cache
|
||||
from flask_compress import Compress
|
||||
|
@ -44,7 +43,9 @@ app.config['SQLALCHEMY_DATABASE_URL'] = environ.get("DATABASE_URL").strip()
|
|||
app.config["CACHE_TYPE"] = "RedisCache"
|
||||
app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL").strip()
|
||||
|
||||
r=redis.Redis(host=environ.get("REDIS_URL").strip(), decode_responses=True, ssl_cert_reqs=None)
|
||||
app.config['SERVICE'] = Service.RDRAMA
|
||||
if "load_chat" in argv:
|
||||
app.config['SERVICE'] = Service.CHAT
|
||||
|
||||
def get_CF():
|
||||
with app.app_context():
|
||||
|
@ -79,9 +80,13 @@ def no_step_on_jc():
|
|||
if key and key == request.headers.get("X-No-Step", ""): return True
|
||||
return False
|
||||
|
||||
if "load_chat" in argv:
|
||||
from files.routes.chat import *
|
||||
else:
|
||||
if app.config['SERVICE'] == Service.RDRAMA:
|
||||
from files.routes import *
|
||||
|
||||
if HOLIDAY_EVENT:
|
||||
from files.events import *
|
||||
event_init()
|
||||
elif app.config['SERVICE'] == Service.CHAT:
|
||||
from files.routes.chat import *
|
||||
|
||||
stdout.flush()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../events/assets/css
|
|
@ -0,0 +1 @@
|
|||
../../events/assets/fonts
|
|
@ -0,0 +1 @@
|
|||
../../events/assets/images
|
|
@ -0,0 +1 @@
|
|||
../../events/assets/js
|
|
@ -0,0 +1 @@
|
|||
../../events/assets/media
|
|
@ -0,0 +1,28 @@
|
|||
from sqlalchemy import inspect
|
||||
|
||||
from files.helpers.const import AWARDS2, AWARDS_DISABLED
|
||||
from files.__main__ import engine
|
||||
|
||||
from files.events.classes import *
|
||||
from files.events.helpers import *
|
||||
from files.events.routes import *
|
||||
|
||||
def _build_table():
|
||||
if not inspect(engine).has_table(EventUser.__table__.name, schema="public"):
|
||||
print("[EVENT] Building event table...")
|
||||
EventUser.__table__.create(bind=engine, checkfirst=True)
|
||||
|
||||
def _populate_awards():
|
||||
temp = {x: AWARDS2[x] for x in AWARDS2 if x not in EVENT_AWARDS}
|
||||
AWARDS2.clear()
|
||||
AWARDS2.update(EVENT_AWARDS)
|
||||
AWARDS2.update(temp)
|
||||
|
||||
for award in EVENT_AWARDS:
|
||||
if award in AWARDS_DISABLED:
|
||||
AWARDS_DISABLED.remove(award)
|
||||
|
||||
def event_init():
|
||||
_build_table()
|
||||
|
||||
_populate_awards()
|
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -0,0 +1 @@
|
|||
from .eventuser import EventUser
|
|
@ -0,0 +1,20 @@
|
|||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from files.classes import Base
|
||||
|
||||
class EventUser(Base):
|
||||
__tablename__ = "event"
|
||||
id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||
user = relationship("User", primaryjoin="EventUser.id == User.id", lazy="joined")
|
||||
event_music = Column(Boolean, default=True, nullable=False)
|
||||
|
||||
# start event specific columns
|
||||
|
||||
# end event specific columns
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Event(id={self.id})>"
|
|
@ -0,0 +1,2 @@
|
|||
from .const import *
|
||||
from .jinja import *
|
|
@ -0,0 +1,3 @@
|
|||
EVENT_AWARDS = {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
from typing import Union
|
||||
from sqlalchemy.orm import scoped_session
|
||||
|
||||
from files.events.classes.eventuser import EventUser
|
||||
from files.classes.user import User
|
||||
|
||||
def get_or_create_event_user(target:Union[int, User], db:scoped_session) -> EventUser:
|
||||
if isinstance(target, User): target = target.id # type: ignore
|
||||
user = db.get(EventUser, target)
|
||||
if not user:
|
||||
user = EventUser(id=target)
|
||||
db.add(target)
|
||||
db.flush()
|
||||
return user
|
|
@ -0,0 +1,8 @@
|
|||
EVENT_JINJA_CONST = {
|
||||
"EVENT_BANNER": "banner_rDrama.html",
|
||||
"EVENT_SIDEBAR": True,
|
||||
"EVENT_STYLES": "spooky.css",
|
||||
"EVENT_AWARDS": True,
|
||||
"EVENT_MUSIC": "music.html",
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
from .awards import *
|
||||
from .jinja import *
|
|
@ -0,0 +1,9 @@
|
|||
from flask import g
|
||||
|
||||
from files.events.helpers.get import get_or_create_event_user
|
||||
|
||||
def award_thing_event(v, kind, author):
|
||||
event_author = get_or_create_event_user(author, g.db)
|
||||
event_v = get_or_create_event_user(v, g.db)
|
||||
|
||||
g.db.add(event_author)
|
|
@ -0,0 +1,6 @@
|
|||
from files.__main__ import app
|
||||
from files.events import EVENT_JINJA_CONST
|
||||
|
||||
@app.context_processor
|
||||
def event_constants():
|
||||
return EVENT_JINJA_CONST
|
|
@ -0,0 +1,3 @@
|
|||
<a rel="nofollow noopener noreferrer" href="{% if 'rama' in request.host %}https://youtu.be/3l7X94GLqSQ?t=16{% else %}/{% endif %}" style="text-decoration: none !important">
|
||||
|
||||
</a>
|
|
@ -0,0 +1,24 @@
|
|||
{% if not (v and v.poor) and (not event_v or event_v.event_music) and not (sub and sub.name == 'music') %}
|
||||
{% if not song %}
|
||||
{% set path = "assets/media/event/music" %}
|
||||
{% set song = "/" + path + "/" + listdir('files/' + path)|random() + '?v=45' %}
|
||||
{% endif %}
|
||||
<script>
|
||||
const audio = new Audio("{{song}}");
|
||||
audio.loop=true;
|
||||
|
||||
function play() {
|
||||
audio.play();
|
||||
}
|
||||
|
||||
audio.loop=true;
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
audio.play();
|
||||
document.getElementById('frontpage').addEventListener('click', () => {
|
||||
if (audio.paused) audio.play();
|
||||
}, {once : true});
|
||||
prepare_to_pause(audio)
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
|
@ -0,0 +1,78 @@
|
|||
<div class="col sidebar text-left {% if '/sidebar' not in request.path %}d-none d-lg-block{% endif %} pt-3 pb-5" {% if request.path != '/sidebar' %}id="sidebar-content"{% endif %}>
|
||||
|
||||
{% if sub %}
|
||||
{% set image = sub.sidebar_url %}
|
||||
{% else %}
|
||||
{% set sidebar_path = "assets/images/event/sidebar" %}
|
||||
{% set selected_image = listdir('files/' + sidebar_path)|random() %}
|
||||
{% set image = "/" + sidebar_path + "/" + selected_image + '?v=45' %}
|
||||
{% endif %}
|
||||
|
||||
{% if request.path != '/sidebar' %}
|
||||
<a href="{{image}}" style="text-decoration:none">
|
||||
<img class="mb-4" alt="sidebar image" onclick="expandDesktopImage()" loading="lazy" src="{{image}}" width=100%>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<p class="text-center text-md mb-4">
|
||||
<a class="sidebar-link" href="/marseys" data-bs-toggle="tooltip" data-bs-placement="top" title="Marseys"><i class="fas fa-cat"></i></a>
|
||||
<a class="sidebar-link" href="/badges" data-bs-toggle="tooltip" data-bs-placement="top" title="Badges"><i class="fas fa-hexagon"></i></a>
|
||||
<a class="sidebar-link" href="/admins" data-bs-toggle="tooltip" data-bs-placement="top" title="Admins"><i class="fas fa-crown"></i></a>
|
||||
<a class="sidebar-link" href="/log" data-bs-toggle="tooltip" data-bs-placement="top" title="Moderation Log"><i class="fas fa-scroll-old"></i></a>
|
||||
<a class="sidebar-link" href="/transfers" data-bs-toggle="tooltip" data-bs-placement="top" title="Transfers"><i class="fas fa-arrow-right-arrow-left"></i></a>
|
||||
<a class="sidebar-link" href="/random_post" data-bs-toggle="tooltip" data-bs-placement="top" title="Random Post"><i class="fas fa-random"></i></a>
|
||||
<span class="sidebar-link" onclick="if(localStorage.getItem('setting_upsidedown')=='true'){localStorage.setItem('setting_upsidedown', 'false')}else{localStorage.setItem('setting_upsidedown', 'true')};location.reload()" style="display:inline" data-bs-toggle="tooltip" data-bs-placement="top" title="???"><i class="fas fa-trees"></i></span>
|
||||
</p>
|
||||
|
||||
{% if sub %}
|
||||
{% if sub.sidebar_html %}
|
||||
<div class="mb-4">{{sub.sidebar_html|safe}}</div>
|
||||
{% endif %}
|
||||
{% if v %}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/holes">BROWSE {{HOLE_NAME|upper}}S</a>
|
||||
{% if v.can_create_hole -%}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE {{HOLE_NAME|upper}}</a>
|
||||
{%- endif %}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub}}/log">{{HOLE_NAME|upper}} LOG</a>
|
||||
{% if v.mods(sub.name) %}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub}}/settings">{{HOLE_NAME|upper}} SETTINGS</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub}}/mods">{{HOLE_NAME|upper}} MODS</a>
|
||||
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub}}/exilees">{{HOLE_NAME|upper}} EXILEES</a>
|
||||
{% else %}
|
||||
<a id="sidebar--directory--btn" class="btn btn-primary btn-block mb-3" href="/directory">
|
||||
<span id="sidebar--directory--head">DIRECTORY</span>
|
||||
<span id="sidebar--directory--subhead">Submit Marseys & Art | Info Megathreads</span>
|
||||
</a>
|
||||
<a class="btn btn-primary btn-block mb-3" href="/holes">BROWSE {{HOLE_NAME|upper}}S</a>
|
||||
{% if v and v.can_create_hole -%}
|
||||
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE {{HOLE_NAME|upper}}</a>
|
||||
{%- endif %}
|
||||
|
||||
<div class="sidebar--rules">
|
||||
<h3 class="sidebar--rules-head mt-4 mb-3">Rules</h3>
|
||||
<ol class="sidebar--rules-list sidebar--rules-list--rdrama">
|
||||
<li class="font-weight-bold" style="color: red"><a href="/post/19711/a-short-guide-on-how-to" style="color: inherit">NO RIGHTWING AGENDAPOSTING.</a></li>
|
||||
<li>Don't post anything illegal.</li>
|
||||
<li>No sexualizing minors even as a “joke”.</li>
|
||||
<li>No doxing.</li>
|
||||
<li>Using alts to game dramacoin will get you banned.</li>
|
||||
<li>Supporting free speech is an immediate ban.</li>
|
||||
<li class="font-weight-bold">Absolutely NO anti-CCP sentiment.</li>
|
||||
</ol>
|
||||
|
||||
<p>All rules can and likely will be ignored at the discretion of the janitorial staff. Be funny, or at least compelling, and pretty much anything legal is welcome.</p>
|
||||
|
||||
<p style="color: hotpink">𝐜𝐚𝐫𝐩 𝐰𝐨𝐳 𝐞𝐫𝐞</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</pre>
|
||||
</div>
|
|
@ -1,4 +1,5 @@
|
|||
from copy import deepcopy
|
||||
from enum import Enum, auto
|
||||
from os import environ, path
|
||||
|
||||
import tldextract
|
||||
|
@ -42,6 +43,9 @@ FP = environ.get("FP", "").strip()
|
|||
KOFI_TOKEN = environ.get("KOFI_TOKEN", "").strip()
|
||||
KOFI_LINK = environ.get("KOFI_LINK", "").strip()
|
||||
|
||||
class Service(Enum):
|
||||
RDRAMA = auto()
|
||||
CHAT = auto()
|
||||
|
||||
CLOUDFLARE_COOKIE_VALUE = "yes." # remember to change this in CloudFlare too
|
||||
|
||||
|
@ -205,6 +209,8 @@ PAGE_SIZES = {10, 25, 50, 100}
|
|||
### SITE SPECIFIC CONSTANTS
|
||||
################################################################################
|
||||
|
||||
HOLIDAY_EVENT = None
|
||||
|
||||
PERMS = { # Minimum admin_level to perform action.
|
||||
'ADMIN_ADD': 3,
|
||||
'ADMIN_REMOVE': 3,
|
||||
|
|
|
@ -390,6 +390,10 @@ def award_thing(v, thing_type, id):
|
|||
if author.spider: author.spider += 86400
|
||||
else: author.spider = int(time.time()) + 86400
|
||||
badge_grant(user=author, badge_id=179, notify=False)
|
||||
elif HOLIDAY_EVENT:
|
||||
from files.events import EVENT_AWARDS, award_thing_event
|
||||
if kind in EVENT_AWARDS:
|
||||
award_thing_event(v, kind, author)
|
||||
|
||||
if author.received_award_count: author.received_award_count += 1
|
||||
else: author.received_award_count = 1
|
||||
|
|
|
@ -5,15 +5,19 @@
|
|||
{% include "modals/expanded_image.html" %}
|
||||
|
||||
{% if '@' not in request.path %}
|
||||
{% if sub and SITE_NAME != WPD %}
|
||||
{% set src = sub.banner_url %}
|
||||
{% set alt = ['/h/', sub, 'banner']|join %}
|
||||
{% set class = 'site-banner-hole' %}
|
||||
{% elif SITE_NAME == "rDrama" %}
|
||||
{% set href = "https://secure.transequality.org/site/Donation2?df_id=1480" %}
|
||||
{% set expand = false %}
|
||||
{% if EVENT_BANNER and not sub %}
|
||||
{% include 'event/' + EVENT_BANNER %}
|
||||
{% else %}
|
||||
{% if sub and SITE_NAME != WPD %}
|
||||
{% set src = sub.banner_url %}
|
||||
{% set alt = ['/h/', sub, 'banner']|join %}
|
||||
{% set class = 'site-banner-hole' %}
|
||||
{% elif SITE_NAME == "rDrama" %}
|
||||
{% set href = "https://secure.transequality.org/site/Donation2?df_id=1480" %}
|
||||
{% set expand = false %}
|
||||
{% endif %}
|
||||
{{macros.banner(src, href, alt, expand, class)}}
|
||||
{% endif %}
|
||||
{{macros.banner(src, href, alt, expand, class)}}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -31,7 +35,8 @@
|
|||
</div>
|
||||
{% block sidebar %}
|
||||
{% if has_sidebar and (home or p) %}
|
||||
{% include "sidebar_" + SITE_NAME + ".html" %}
|
||||
{% set sidebar = "sidebar_" + SITE_NAME + ".html" %}
|
||||
{% include sidebar if not EVENT_SIDEBAR else 'event/' + sidebar %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../events/templates
|
|
@ -146,6 +146,10 @@
|
|||
<link rel="stylesheet" href="{{'css/rDrama.css' | asset}}">
|
||||
{% endif %}
|
||||
|
||||
{% if EVENT_STYLES %}
|
||||
<link rel="stylesheet" href="/assets/css/event/{{EVENT_STYLES}}">
|
||||
{% endif %}
|
||||
|
||||
{% if request.path == '/chat' %}
|
||||
{% if IS_LOCALHOST %}
|
||||
<link rel="stylesheet" href="https://rdrama.net/assets/css/chat_done.css">
|
||||
|
|
|
@ -8,7 +8,7 @@ server {
|
|||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
add_header X-Frame-Options "deny";
|
||||
add_header X-Content-Type-Options "nosniff";
|
||||
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' challenges.cloudflare.com; connect-src 'self' tls-use1.fpapi.io api.fpjs.io 00bb6d59-7b11-4339-b1ae-b1f1259d1316.pushnotifications.pusher.com; object-src 'none';";
|
||||
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' challenges.cloudflare.com rdrama.net; connect-src 'self' tls-use1.fpapi.io api.fpjs.io 00bb6d59-7b11-4339-b1ae-b1f1259d1316.pushnotifications.pusher.com; object-src 'none';";
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:5000/;
|
||||
|
|
Loading…
Reference in New Issue