mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Calendar
This commit is contained in:
parent
40d81be639
commit
2e62f0c70a
6 changed files with 157 additions and 15 deletions
4
db.py
4
db.py
|
@ -2,7 +2,7 @@ import datetime
|
|||
from sqlalchemy.ext.declarative import declarative_base
|
||||
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
|
||||
from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint, PrimaryKeyConstraint, Boolean, or_, LargeBinary, Text, Date, func
|
||||
import requests
|
||||
from errors import RequestError, NotFoundError, AlreadyExistingError
|
||||
import re
|
||||
|
@ -853,7 +853,7 @@ class Event(Base):
|
|||
|
||||
id = Column(Integer, primary_key=True)
|
||||
author_id = Column(Integer, ForeignKey("royals.id"), nullable=False)
|
||||
author = relationship("Royal")
|
||||
author = relationship("Royal", lazy="joined")
|
||||
name = Column(String, nullable=False)
|
||||
description = Column(Text)
|
||||
time = Column(DateTime, nullable=False)
|
||||
|
|
|
@ -120,6 +120,25 @@ nav {
|
|||
}
|
||||
}
|
||||
|
||||
.box {
|
||||
border-radius: 4px;
|
||||
background-color: rgba(red(@text-color), green(@text-color), blue(@text-color), 0.1);
|
||||
padding: 4px;
|
||||
|
||||
|
||||
&.upper-box {
|
||||
border-radius: 4px 4px 0 0;
|
||||
background-color: rgba(red(@text-color), green(@text-color), blue(@text-color), 0.2);
|
||||
color: @accent-color;
|
||||
font-size: small;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
&.lower-box {
|
||||
border-radius: 0 0 4px 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.input-grid {
|
||||
display: grid;
|
||||
|
||||
|
@ -171,7 +190,7 @@ nav {
|
|||
}
|
||||
}
|
||||
|
||||
@media (min-width:600px) {
|
||||
@media (min-width:601px) {
|
||||
.mobile-only {
|
||||
display: none;
|
||||
}
|
||||
|
@ -593,6 +612,68 @@ nav {
|
|||
}
|
||||
}
|
||||
|
||||
.main-page {
|
||||
display: grid;
|
||||
|
||||
@media (min-width:601px) {
|
||||
//Desktop
|
||||
.left {
|
||||
grid-column: 1;
|
||||
margin: 4px;
|
||||
}
|
||||
|
||||
.right {
|
||||
grid-column: 2;
|
||||
margin: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width:600px) {
|
||||
//Mobile
|
||||
.left {
|
||||
grid-row: 1;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.right {
|
||||
grid-row: 2;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.event {
|
||||
display: grid;
|
||||
grid-template-columns: 10% 70% 20%;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
|
||||
.time {
|
||||
grid-column: 1;
|
||||
grid-row: 1;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.name {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.author {
|
||||
grid-column: 3;
|
||||
grid-row: 1;
|
||||
}
|
||||
|
||||
.description {
|
||||
grid-row: 2;
|
||||
grid-column-start: 1;
|
||||
grid-column-end: 4;
|
||||
}
|
||||
}
|
||||
|
||||
#edit-css {
|
||||
font-size: medium;
|
||||
}
|
|
@ -237,7 +237,8 @@ def cmd_vote(bot: Bot, update: Update):
|
|||
user = session.query(db.Telegram).filter_by(telegram_id=update.message.from_user.id).one_or_none()
|
||||
if user is None:
|
||||
bot.send_message(update.message.chat.id,
|
||||
"⚠ Il tuo account Telegram non è registrato al RYGdb! Registrati con `/register@royalgamesbot <nomeutenteryg>`.")
|
||||
"⚠ Il tuo account Telegram non è registrato al RYGdb!"
|
||||
" Registrati con `/register@royalgamesbot <nomeutenteryg>`.")
|
||||
return
|
||||
try:
|
||||
_, mode, question = update.message.text.split(" ", 2)
|
||||
|
@ -540,6 +541,22 @@ def cmd_newevent(bot: Bot, update: Update):
|
|||
bot.send_message(update.message.chat.id, "✅ Evento aggiunto al Calendario Royal Games!")
|
||||
|
||||
|
||||
def cmd_calendar(bot: Bot, update: Update):
|
||||
session = db.Session()
|
||||
next_events = session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by(db.Event.time).all()
|
||||
session.close()
|
||||
msg = "📆 Prossimi eventi\n"
|
||||
for event in next_events:
|
||||
if event.time_left.days >= 1:
|
||||
msg += event.time.strftime('%Y-%m-%d %H:%M')
|
||||
else:
|
||||
msg += f"{int(event.time_left.total_seconds() // 3600)}h" \
|
||||
f" {int((event.time_left.total_seconds() % 3600) // 60)}m"
|
||||
msg += f" <b>{event.name}</b>\n"
|
||||
msg += '\nPer ulteriori dettagli, visita <a href="https://ryg.steffo.eu">Royalnet</a>'
|
||||
bot.send_message(update.message.chat.id, msg, parse_mode="HTML", disable_web_page_preview=True)
|
||||
|
||||
|
||||
def process(arg_discord_connection):
|
||||
print("Telegrambot starting...")
|
||||
if arg_discord_connection is not None:
|
||||
|
@ -564,11 +581,12 @@ def process(arg_discord_connection):
|
|||
u.dispatcher.add_handler(CommandHandler("bridge", cmd_bridge))
|
||||
u.dispatcher.add_handler(CommandHandler("wheel", cmd_wheel))
|
||||
u.dispatcher.add_handler(CommandHandler("newevent", cmd_newevent))
|
||||
u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar))
|
||||
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
||||
u.bot.send_message(config["Telegram"]["main_group"],
|
||||
f"ℹ Royal Bot avviato e pronto a ricevere comandi!\n"
|
||||
f"Ultimo aggiornamento: `{version}: {commit_msg}`",
|
||||
parse_mode="Markdown")
|
||||
parse_mode="Markdown", disable_notification=True)
|
||||
while True:
|
||||
try:
|
||||
u.start_polling()
|
||||
|
|
20
templates/components/event.html
Normal file
20
templates/components/event.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<div class="event">
|
||||
{% if event.time_left.days >= 1 %}
|
||||
<div class="time date">
|
||||
{{ event.time.strftime('%Y-%m-%d %H:%M') }}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="time remaining">
|
||||
{{ (event.time_left.total_seconds() // 3600) | int }}h {{ ((event.time_left.total_seconds() % 3600) // 60) | int }}m
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="name">
|
||||
{{ event.name }}
|
||||
</div>
|
||||
<div class="author">
|
||||
di <a href="/profile/{{ event.author.username }}">{{ event.author.username }}</a>
|
||||
</div>
|
||||
<div class="description">
|
||||
{{ event.description }}
|
||||
</div>
|
||||
</div>
|
|
@ -8,9 +8,27 @@
|
|||
<h1>
|
||||
Royal Games
|
||||
</h1>
|
||||
<p>
|
||||
Benvenuto al sito web della Royal Games! Sta lentamente migliorando, ma spero che comunque collaboriate a migliorarlo!
|
||||
</p>
|
||||
<div class="main-page">
|
||||
<div class="left">
|
||||
<div class="box upper-box">
|
||||
Prossimi eventi
|
||||
</div>
|
||||
<div class="box lower-box">
|
||||
{% for event in next_events %}
|
||||
{% include "/components/event.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="box upper-box">
|
||||
Sassi
|
||||
</div>
|
||||
<div class="box lower-box">
|
||||
CIAOOOOOO
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
<h2>Profili</h2>
|
||||
<ul>
|
||||
{% for user in royals %}
|
||||
|
@ -37,4 +55,6 @@
|
|||
<ul>
|
||||
<a href="/diario">Nuovo</a>
|
||||
</ul>
|
||||
</div>
|
||||
-->
|
||||
{% endblock %}
|
17
webserver.py
17
webserver.py
|
@ -52,13 +52,16 @@ def page_500():
|
|||
|
||||
@app.route("/")
|
||||
def page_main():
|
||||
if fl_session.get("user_id"):
|
||||
db_session = db.Session()
|
||||
royals = db_session.query(db.Royal).order_by(db.Royal.username).all()
|
||||
wiki_pages = db_session.query(db.WikiEntry).order_by(db.WikiEntry.key).all()
|
||||
db_session.close()
|
||||
return render_template("main.html", royals=royals, wiki_pages=wiki_pages, config=config)
|
||||
return redirect(url_for("page_login"))
|
||||
if not fl_session.get("user_id"):
|
||||
return redirect(url_for("page_login"))
|
||||
db_session = db.Session()
|
||||
royals = db_session.query(db.Royal).order_by(db.Royal.username).all()
|
||||
wiki_pages = db_session.query(db.WikiEntry).order_by(db.WikiEntry.key).all()
|
||||
random_diario = db_session.query(db.Diario).order_by(db.func.random()).first()
|
||||
next_events = db_session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by(db.Event.time).all()
|
||||
db_session.close()
|
||||
return render_template("main.html", royals=royals, wiki_pages=wiki_pages, diario=random_diario,
|
||||
next_events=next_events, config=config, a_day=datetime.timedelta(days=1))
|
||||
|
||||
|
||||
@app.route("/profile/<name>")
|
||||
|
|
Loading…
Reference in a new issue