v4: Personal calendar #168

Merged
Xefir merged 5 commits from v4 into master 2023-11-07 00:40:58 +00:00
4 changed files with 71 additions and 37 deletions
Showing only changes of commit a6025975a9 - Show all commits

View File

@ -6,6 +6,7 @@ from os import getenv, path
from typing import Dict, Optional
from disnake import Client, Guild
from disnake.guild_scheduled_event import GuildScheduledEvent
from dotenv import load_dotenv
from ics import Calendar, ContentLine, Event
from ics.alarm import DisplayAlarm
@ -223,26 +224,9 @@ async def subscribe(guild_id: str):
return await render_template("subscribe.html.j2", guild=guild)
@app.route("/<guild_id>.ics")
async def ical(guild_id: str):
guild = get_guild_by_id(guild_id)
if guild is None:
return redirect(url_for(".login"))
calendar = Calendar()
calendar.extra.append(ContentLine(name="REFRESH-INTERVAL", value="PT1H"))
calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H"))
calendar.extra.append(ContentLine(name="NAME", value=guild.name))
calendar.extra.append(ContentLine(name="X-WR-CALNAME", value=guild.name))
if guild.description:
calendar.extra.append(ContentLine(name="DESCRIPTION", value=guild.description))
calendar.extra.append(ContentLine(name="X-WR-CALDESC", value=guild.description))
for scheduled_event in guild.scheduled_events:
def make_event(scheduled_event: GuildScheduledEvent, guild_id: int) -> Event:
event = Event()
event.summary = scheduled_event.name
event.begin = scheduled_event.scheduled_start_time
event.end = scheduled_event.scheduled_end_time
@ -260,10 +244,59 @@ async def ical(guild_id: str):
alarm.trigger = timedelta(hours=-1)
event.alarms.append(alarm)
return event
@app.route("/<entity_id>.ics")
async def ical(entity_id: str):
guild = get_guild_by_id(entity_id)
if guild:
calendar = Calendar()
calendar.extra.append(ContentLine(name="REFRESH-INTERVAL", value="PT1H"))
calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H"))
calendar.extra.append(ContentLine(name="NAME", value=guild.name))
calendar.extra.append(ContentLine(name="X-WR-CALNAME", value=guild.name))
if guild.description:
calendar.extra.append(
ContentLine(name="DESCRIPTION", value=guild.description)
)
calendar.extra.append(
ContentLine(name="X-WR-CALDESC", value=guild.description)
)
for scheduled_event in guild.scheduled_events:
event = make_event(scheduled_event, guild.id)
calendar.events.append(event)
return calendar.serialize()
user = client.get_or_fetch_user(int(entity_id))
if user:
calendar = Calendar()
calendar.extra.append(ContentLine(name="REFRESH-INTERVAL", value="PT1H"))
calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H"))
calendar.extra.append(ContentLine(name="NAME", value=client.user.display_name))
calendar.extra.append(
ContentLine(name="X-WR-CALNAME", value=client.user.display_name)
)
for guild in client.guilds:
if guild.get_or_fetch_member(int(entity_id)):
for scheduled_event in guild.scheduled_events:
event = make_event(scheduled_event, guild.id)
calendar.events.append(event)
return calendar.serialize()
return redirect(url_for(".login"))
def __main__():
quart_task = client.loop.create_task(app.run_task("0.0.0.0"))

View File

@ -16,8 +16,12 @@
<h1>
<a href="{{ url_for(".index") }}">{{ client.user.display_name }}</a>
</h1>
<a class="button" href="{{ url_for(".guilds", guild=user.id) }}">
{{ _("For all your servers") }}
</a>
<div class="hr-sect">{{ _("OR") }}</div>
<h3>{{ _('Choose a server:') }}</h3>
<select name="guild" class="black_input">
<select name="guild" class="black_input" onchange="this.form.submit()">
<option>
&nbsp;
</option>
@ -29,7 +33,6 @@
</select>
<div class="hr-sect">{{ _("OR") }}</div>
<a class="button"
target="_blank"
href="https://discord.com/api/oauth2/authorize?client_id={{ client.user.id }}&permissions=8589934592&scope=bot">
{{ _("Add the bot on your server") }}
</a>
@ -48,8 +51,5 @@
</li>
</ul>
</div>
<div id="buttons">
<input type="submit" class="button" value="{{ _("Let's go!") }}"/>
</div>
</form>
{% endblock content %}

View File

@ -5,6 +5,7 @@
"This will allow you to:": "Ceci te permettra de :",
"Subscribe to a calendar on Google, Outlook, Apple or any ICS complient software": "T'abonner à un calendrier sur Google, Outlook, Apple ou tout autre logiciel compatible",
"Throwing you to a new isekai world": "T'envoyer dans un monde fantaisiste armée d'une poêle à frire",
"For all your servers": "Pour tous tes serveurs",
"Choose a server:": "Choisi un serveur :",
"You must have": "Tu dois avoir la permission",
"Manage Server": "Gérer le serveur",

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "divent"
version = "3.4.4"
version = "4.0.0"
description = "The discord scheduled event calendar generator"
authors = ["Xéfir Destiny <xefir@crystalyx.net>"]
license = "WTFPL"