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 typing import Dict, Optional
from disnake import Client, Guild from disnake import Client, Guild
from disnake.guild_scheduled_event import GuildScheduledEvent
from dotenv import load_dotenv from dotenv import load_dotenv
from ics import Calendar, ContentLine, Event from ics import Calendar, ContentLine, Event
from ics.alarm import DisplayAlarm from ics.alarm import DisplayAlarm
@ -223,46 +224,78 @@ async def subscribe(guild_id: str):
return await render_template("subscribe.html.j2", guild=guild) return await render_template("subscribe.html.j2", guild=guild)
@app.route("/<guild_id>.ics") def make_event(scheduled_event: GuildScheduledEvent, guild_id: int) -> Event:
async def ical(guild_id: str): event = Event()
guild = get_guild_by_id(guild_id)
if guild is None:
return redirect(url_for(".login"))
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")) alarm = DisplayAlarm()
calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H")) alarm.trigger = timedelta(hours=-1)
event.alarms.append(alarm)
calendar.extra.append(ContentLine(name="NAME", value=guild.name)) return event
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: @app.route("/<entity_id>.ics")
event = Event() async def ical(entity_id: str):
event.summary = scheduled_event.name guild = get_guild_by_id(entity_id)
event.begin = scheduled_event.scheduled_start_time
event.end = scheduled_event.scheduled_end_time if guild:
event.duration = timedelta(hours=2) calendar = Calendar()
event.uid = str(scheduled_event.id)
event.description = scheduled_event.description calendar.extra.append(ContentLine(name="REFRESH-INTERVAL", value="PT1H"))
event.url = f"https://discord.com/events/{guild_id}/{scheduled_event.id}" calendar.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT1H"))
event.location = (
scheduled_event.entity_metadata.location calendar.extra.append(ContentLine(name="NAME", value=guild.name))
if scheduled_event.entity_metadata calendar.extra.append(ContentLine(name="X-WR-CALNAME", value=guild.name))
else None
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() for guild in client.guilds:
alarm.trigger = timedelta(hours=-1) if guild.get_or_fetch_member(int(entity_id)):
event.alarms.append(alarm) 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__(): def __main__():

View File

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

View File

@ -5,6 +5,7 @@
"This will allow you to:": "Ceci te permettra de :", "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", "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", "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 :", "Choose a server:": "Choisi un serveur :",
"You must have": "Tu dois avoir la permission", "You must have": "Tu dois avoir la permission",
"Manage Server": "Gérer le serveur", "Manage Server": "Gérer le serveur",

View File

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