diff --git a/db.py b/db.py index 86a66837..fef2eb28 100644 --- a/db.py +++ b/db.py @@ -2,10 +2,9 @@ import datetime import logging import os import typing - import coloredlogs from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker, relationship, joinedload +from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary, Text, Date, func, desc import requests @@ -31,6 +30,7 @@ logger = logging.getLogger(__name__) os.environ["COLOREDLOGS_LOG_FORMAT"] = "%(asctime)s %(levelname)s %(name)s %(message)s" coloredlogs.install(level="DEBUG", logger=logger) + class Royal(Base): __tablename__ = "royals" @@ -964,22 +964,17 @@ class Halloween(Base): return count @staticmethod - def event_started() -> bool: - session = Session() - halloweens = session.query(Halloween).all() - return bool(halloweens) - - @staticmethod - def puzzle_status() -> typing.List[bool]: + def puzzle_status() -> typing.Tuple[bool, typing.List[bool]]: session = Session() halloweens = session.query(Halloween).all() session.close() + started = bool(halloweens) completed = [False for _ in range(10)] for h in halloweens: for i in range(10): if h[i+1]: completed[i] = True - return completed + return started, completed # If run as script, create all the tables in the db if __name__ == "__main__": diff --git a/ohciaovedochestaileggendoilmiostato.py b/ohciaovedochestaileggendoilmiostato.py new file mode 100644 index 00000000..d8a74e85 --- /dev/null +++ b/ohciaovedochestaileggendoilmiostato.py @@ -0,0 +1,82 @@ +import secrets +from flask import Flask, render_template, request, abort, redirect, url_for, Markup, escape, jsonify +from flask import session as fl_session +from flask import g as fl_g +import db +import bcrypt +import configparser +import markdown2 +import datetime +import telegram +import query_discord_music +import random +import re +from raven.contrib.flask import Sentry + +app = Flask(__name__) + +app.jinja_env.trim_blocks = True +app.jinja_env.lstrip_blocks = True + +config = configparser.ConfigParser() +config.read("config.ini") + +app.secret_key = config["Flask"]["secret_key"] + +telegram_bot = telegram.Bot(config["Telegram"]["bot_token"]) + +sentry = Sentry(app, dsn=config["Sentry"]["token"]) + + +@app.before_request +def pre_request(): + fl_g.event_started, fl_g.event_progress = db.Halloween.puzzle_status() + fl_g.time_left = datetime.datetime.fromtimestamp(1540999800) - datetime.datetime.now() + fl_g.display_on_main_site = (fl_g.time_left < datetime.timedelta(days=7)) or __debug__ + fl_g.css = "spoopy.less" if (fl_g.event_started or __debug__) else "nryg.less" + fl_g.rygconf = config + + +@app.route("/") +def page_owlcaptain(): + return render_template("ohciaodinuovo.html") + + +@app.route("/voiceofevil", methods=["POST"]) +def page_voiceofevil(): + if request.form.get("solution", "") != "1": + abort(400) + return + db_session = db.Session() + halloween = db_session.query(db.Halloween).filter_by(royal_id=fl_session["user_id"]).one_or_none() + if halloween is None: + abort(403) + return + halloween[3] = True + db_session.commit() + return redirect(url_for("page_owlcaptain")) + + +@app.route("/mansion", methods=["POST"]) +def page_mansion(): + if request.form.get("solution", "") != "bobooboooboooo": + abort(400) + return + db_session = db.Session() + halloween = db_session.query(db.Halloween).filter_by(royal_id=fl_session["user_id"]).one_or_none() + if halloween is None: + abort(403) + return + halloween[5] = True + db_session.commit() + return redirect(url_for("page_owlcaptain")) + + +@app.route("/whatpumpkin", methods=["POST"]) +def page_whatpumpkin(): + abort(400) + return + + +if __name__ == "__main__": + app.run(debug=True, port=1235) diff --git a/static/ee.ogg b/static/ee.ogg deleted file mode 100644 index 31d633d1..00000000 Binary files a/static/ee.ogg and /dev/null differ diff --git a/static/nryg.less b/static/nryg.less index 6b1fd6b0..03c55118 100644 --- a/static/nryg.less +++ b/static/nryg.less @@ -777,7 +777,7 @@ table { } } -ntry { +.entry { display: grid; .left { diff --git a/static/owl.less b/static/owl.less new file mode 100644 index 00000000..e69de29b diff --git a/static/secret.ogg b/static/secret.ogg deleted file mode 100644 index 313da601..00000000 Binary files a/static/secret.ogg and /dev/null differ diff --git a/static/snesfile.zip b/static/snesfile.zip new file mode 100644 index 00000000..ee6b13f5 Binary files /dev/null and b/static/snesfile.zip differ diff --git a/static/spoopy.less b/static/spoopy.less index 1fa39e5f..1c286bd9 100644 --- a/static/spoopy.less +++ b/static/spoopy.less @@ -755,7 +755,7 @@ table { padding: 18px; grid-template-columns: 100%; - .moons.game-score { + .mysterystatus.game-score { font-size: 0; i { @@ -791,7 +791,7 @@ table { } } -ntry { +.entry { display: grid; .left { @@ -855,19 +855,15 @@ ntry { } .halloween { - .upper-box { - font-size: xx-large; - } - .lower-box { text-align: center; .time-left { font-size: 64px; - font-family: monospace; + font-family: "Consolas", "Source Code Pro", monospace; } - .moons { + .mysterystatus { font-size: 64px; } } @@ -921,15 +917,13 @@ ntry { } } -.moons a { - color: @text-color; - - &:hover { - color: @highlight-color; +.mysterystatus i { + &.todo { + color: rgba(255, 255, 0, 0.2); } - .fas { - color: yellow; + &.done { + color: rgba(255, 255, 0, 1); } } diff --git a/telegrambot.py b/telegrambot.py index 748f5d65..562572f4 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -134,7 +134,8 @@ def cmd_cast(bot: Bot, update: Update): @catch_and_report def cmd_color(bot: Bot, update: Update): - bot.send_message(update.message.chat.id, "I am sorry, unknown error occured during working with your request, Admin were notified") + bot.send_message(update.message.chat.id, "I am sorry, unknown error occured during working with your request," + " Admin were notified") @catch_and_report diff --git a/templates/base.html b/templates/base.html index 0fdf862e..c96578fc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,7 +7,7 @@ {% block prehead %}{% endblock %} {% block pagetitle %}{% endblock %} - Royal Games - + {% block posthead %}{% endblock %} @@ -19,8 +19,8 @@ Home {% if session.get('username') is not none %} - Telegram - Discord + Telegram + Discord Steam /r/RoyalGames {% endif %} diff --git a/templates/main.html b/templates/main.html index 3d878f08..1884b55e 100644 --- a/templates/main.html +++ b/templates/main.html @@ -10,16 +10,16 @@ {% block posthead %} {% endblock %} @@ -28,20 +28,20 @@ Royal Games
- {% if g["css"] == "spoopy.less" %} + {% if g.time_left %}
- Rituale di Halloween! + owlcaptain.tk
Lune raccolte: -
+
{% for index, star in halloween %} {% if star %} - + {% else %} - + {% endif %} {% endfor %}
@@ -97,8 +97,8 @@
  • Royal Games
  • - {% if rygconf["Events"]["halloween"] %} -
  • Rituale di Halloween
  • + {% if g.css == "spoopy.less" %} +
  • Halloween
  • {% endif %}
  • Telegram
  • Discord
  • diff --git a/templates/minis/halloween.html b/templates/minis/halloween.html index ed2292d6..407cae96 100644 --- a/templates/minis/halloween.html +++ b/templates/minis/halloween.html @@ -1,17 +1,17 @@
    - Rituale di Halloween + {{ record.royal.username }}
    -
    +
    Lune ottenute
    -
    +
    {% for index in range(10) %} - {% if halloween[index] %} - + {% if record[index + 1] %} + {% else %} - + {% endif %} {% endfor %}
    diff --git a/templates/ohciaodinuovo.html b/templates/ohciaodinuovo.html new file mode 100644 index 00000000..1e6881b8 --- /dev/null +++ b/templates/ohciaodinuovo.html @@ -0,0 +1,154 @@ + + + + + + + a curse. + + + + + +
    +

    + a curse. +

    +
    + +
    +
    + a curse lies in waiting for the night of the dead.
    + you and your friends are in danger.
    + stop it before it activates.
    +
    + i'm willing to help you.
    + you will have to perform a ritual.
    + here are the steps.
    +
    + you can perform them in any order, except for the final step.
    + i'll reveal that when all others are complete, just to be safe. +
    +
    + {% for quest in g.event_progress %} +
    +
    + {% if quest %} + + {% else %} + + {% endif %} +
    + {% if loop.index == 1 %} + {# hecarim o chaos knight #} +

    + unleash the horsemen +

    +
    + you'll need the help of the horsemen of the apocalypse to dispel the curse.
    + lead Chaos to victory in the battle of the ancients, or the War from the shadow isles to victory on the rift, and you'll gain their support. +
    + {% elif loop.index == 2 %} + {# la zucca di balu e max #} +

    + carve the ritual pumpkin +

    +
    + prepare a pumpkin, and empty its inside.
    + carve something on its exterior then put a light inside of it.
    + when dusk has come, take a picture, and post it to the owl captain. +
    + {% elif loop.index == 3 %} + {# https://osu.ppy.sh/beatmapsets/385#osu/2038 #} +

    + circle the sound +

    +
    + find the 2038th sound of halloween.
    + then, follow the circle pattern.
    +
    + it is rather dashing, isn't it? +
    + {% elif loop.index == 4 %} +

    + uproot the evil +

    +
    + listen to the sounds in here.
    + do you hear the evil that stole your voice?
    + answer it. +
    +
    + + +
    + {% elif loop.index == 5 %} +

    + remove the ghosts +

    +
    + during the ritual something strange might happen.
    + in that case, the ghosts probably will be to blame.
    + to be safe, i would remove them...
    +
    + who should you call? +
    + {% elif loop.index == 6 %} +

    + conquer the mansion +

    +
    + a mansion has appeared.
    + prove yourself worthy, and find the words hidden deep inside.
    + only then i can trust you to completely perform the ritual. +
    +
    + + +
    + {% elif loop.index == 7 %} +

    + +

    +
    + +
    + {% elif loop.index == 8 %} +

    + +

    +
    + +
    + {% elif loop.index == 9 %} +

    + +

    +
    + +
    + {% elif loop.index == 10 %} +

    + +

    +
    + +
    + {% endif %} +
    + {% endfor %} +
    +
    + + \ No newline at end of file diff --git a/templates/ritual.html b/templates/ritual.html deleted file mode 100644 index 9aa465cf..00000000 --- a/templates/ritual.html +++ /dev/null @@ -1,29 +0,0 @@ -{% extends 'base.html' %} - -{% block pagetitle %} - Rituale {{ n }} -{% endblock %} - -{% block body %} -

    - Rituale {{ n }} -

    -
    -
    - {% if n == 1 %} - {% elif n == 2 %} - {% elif n == 3 %} - {% elif n == 4 %} - {% elif n == 5 %} - {% elif n == 6 %} - {% elif n == 7 %} - {% elif n == 8 %} - {% elif n == 9 %} - {% elif n == 10 %} - {% endif %} -
    -
    - -
    -
    -{% endblock %} \ No newline at end of file diff --git a/webserver.py b/webserver.py index bbe34ee2..35555c27 100644 --- a/webserver.py +++ b/webserver.py @@ -1,4 +1,5 @@ -from flask import Flask, render_template, request, abort, redirect, url_for, Markup, escape +import secrets +from flask import Flask, render_template, request, abort, redirect, url_for, Markup, escape, jsonify from flask import session as fl_session from flask import g as fl_g import db @@ -84,7 +85,6 @@ def page_profile(name: str): css = db_session.query(db.ProfileData).filter_by(royal=user).one_or_none() steam = db_session.query(db.Steam).filter_by(royal=user).one_or_none() osu = db_session.query(db.Osu).filter_by(royal=user).one_or_none() - # rl = db_session.query(db.RocketLeague).join(db.Steam).filter_by(royal=user).one_or_none() dota = db_session.query(db.Dota).join(db.Steam).filter_by(royal=user).one_or_none() lol = db_session.query(db.LeagueOfLegends).filter_by(royal=user).one_or_none() ow = db_session.query(db.Overwatch).filter_by(royal=user).one_or_none() @@ -333,6 +333,34 @@ def page_diario(): return render_template("diario.html", g=fl_g, entries=diario_entries) +@app.route("/api/token") +def page_token(): + username = request.form.get("username", "") + password = request.form.get("password", "") + db_session = db.Session() + user = db_session.query(db.Royal).filter_by(username=username).one_or_none() + if user is None: + db_session.close() + abort(403) + return + if user.password is None: + db_session.close() + abort(403) + if bcrypt.checkpw(bytes(password, encoding="utf8"), user.password): + new_token = db.LoginToken(royal=user, token=secrets.token_urlsafe()) + db_session.add(new_token) + db_session.commit() + db_session.close() + return jsonify({ + "id": user.id, + "username": user.username, + "token": new_token.token + }) + else: + abort(403) + return + + @app.route("/spooky", methods=["POST"]) def page_spooky(): if request.form.get("solution", "") != "1": @@ -348,41 +376,13 @@ def page_spooky(): return redirect(url_for("page_main")) -@app.route("/ritual/", methods=["GET", "POST"]) -def page_ritual(n: int): - user_id = fl_session.get("user_id") - if not user_id: - return redirect(url_for("page_login")) - if request.method == "GET": - return render_template("ritual.html", g=fl_g, n=n) - elif request.method == "POST": - if n == 1: - pass - elif n == 2: - pass - elif n == 3: - pass - elif n == 4: - pass - elif n == 5: - pass - elif n == 6: - pass - elif n == 7: - pass - elif n == 8: - pass - elif n == 9: - pass - elif n == 10: - pass - return redirect(url_for("page_ritual", n=n)) - - @app.before_request def pre_request(): - fl_g["css"] = "spoopy.less" if db.Halloween.event_started() else "nryg.less" - fl_g["rygconf"] = config + fl_g.event_started, fl_g.event_progress = db.Halloween.puzzle_status() + fl_g.time_left = datetime.datetime.fromtimestamp(1540999800) - datetime.datetime.now() + fl_g.display_on_main_site = (fl_g.time_left < datetime.timedelta(days=7)) or __debug__ + fl_g.css = "spoopy.less" if (fl_g.event_started or __debug__) else "nryg.less" + fl_g.rygconf = config if __name__ == "__main__":