Add option to subscribe to all personal events
This commit is contained in:
parent
efc82c1931
commit
a6025975a9
@ -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,26 +224,9 @@ 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):
|
|
||||||
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:
|
|
||||||
event = Event()
|
event = Event()
|
||||||
|
|
||||||
event.summary = scheduled_event.name
|
event.summary = scheduled_event.name
|
||||||
event.begin = scheduled_event.scheduled_start_time
|
event.begin = scheduled_event.scheduled_start_time
|
||||||
event.end = scheduled_event.scheduled_end_time
|
event.end = scheduled_event.scheduled_end_time
|
||||||
@ -260,10 +244,59 @@ async def ical(guild_id: str):
|
|||||||
alarm.trigger = timedelta(hours=-1)
|
alarm.trigger = timedelta(hours=-1)
|
||||||
event.alarms.append(alarm)
|
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)
|
calendar.events.append(event)
|
||||||
|
|
||||||
return calendar.serialize()
|
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__():
|
def __main__():
|
||||||
quart_task = client.loop.create_task(app.run_task("0.0.0.0"))
|
quart_task = client.loop.create_task(app.run_task("0.0.0.0"))
|
||||||
|
@ -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>
|
||||||
|
|
||||||
</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 %}
|
||||||
|
@ -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",
|
||||||
|
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user