Add option to subscribe to all personal events
divent / lint (push) Successful in 2m28s Details
divent / docker (push) Successful in 2m6s Details
divent / pypi (push) Has been skipped Details

This commit is contained in:
Michel Roux 2023-11-06 21:56:09 +01:00
parent efc82c1931
commit a6025975a9
4 changed files with 71 additions and 37 deletions

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,46 +224,78 @@ 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"))
def make_event(scheduled_event: GuildScheduledEvent, guild_id: int) -> Event:
event = Event()
calendar = Calendar()
event.summary = scheduled_event.name
event.begin = scheduled_event.scheduled_start_time
event.end = scheduled_event.scheduled_end_time
event.duration = timedelta(hours=2)
event.uid = str(scheduled_event.id)
event.description = scheduled_event.description
event.url = f"https://discord.com/events/{guild_id}/{scheduled_event.id}"
event.location = (
scheduled_event.entity_metadata.location
if scheduled_event.entity_metadata
else None
)
calendar.extra.append(ContentLine(name="REFRESH-INTERVAL", value="PT1H"))
calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H"))
alarm = DisplayAlarm()
alarm.trigger = timedelta(hours=-1)
event.alarms.append(alarm)
calendar.extra.append(ContentLine(name="NAME", value=guild.name))
calendar.extra.append(ContentLine(name="X-WR-CALNAME", value=guild.name))
return event
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 = Event()
event.summary = scheduled_event.name
event.begin = scheduled_event.scheduled_start_time
event.end = scheduled_event.scheduled_end_time
event.duration = timedelta(hours=2)
event.uid = str(scheduled_event.id)
event.description = scheduled_event.description
event.url = f"https://discord.com/events/{guild_id}/{scheduled_event.id}"
event.location = (
scheduled_event.entity_metadata.location
if scheduled_event.entity_metadata
else None
@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)
)
alarm = DisplayAlarm()
alarm.trigger = timedelta(hours=-1)
event.alarms.append(alarm)
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)
calendar.events.append(event)
return calendar.serialize()
return calendar.serialize()
return redirect(url_for(".login"))
def __main__():

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"