Compare commits
91 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e5dae82f8 | |||
|
69ffcdf8c6 | ||
7893499305 | |||
b0f10a7933 | |||
a979940e2b | |||
8aa15a6ed0 | |||
|
f62742d62a | ||
194435f04d | |||
|
6867f220f5 | ||
d045afc9d8 | |||
|
e8c6959ae5 | ||
4c0314e7e6 | |||
d2e6a0284c | |||
|
f8211686be | ||
|
4f24b29a0c | ||
0ca5d79487 | |||
|
126c0872f6 | ||
9d2d03514e | |||
|
6bb3775571 | ||
a3deadc28e | |||
|
9fc4012696 | ||
d9ad60075a | |||
|
e3cdd89350 | ||
7b518d4e99 | |||
|
a71b1f7633 | ||
6914cb8b90 | |||
|
547b108e0a | ||
a5e68a2751 | |||
|
1f6cff347f | ||
155bd0aada | |||
274b642c84 | |||
e14ecefcf8 | |||
|
cea9a387c6 | ||
ba8befa3b0 | |||
|
d73a88c102 | ||
b9b66d182b | |||
|
65722ba7c3 | ||
59926c9b5d | |||
304f80a3f5 | |||
20b672df71 | |||
|
7f9b5c32b1 | ||
e9b57594cd | |||
|
9859863b80 | ||
723595c94a | |||
|
0c29a9f040 | ||
1a95628eb5 | |||
|
1a74e4428a | ||
b136784301 | |||
|
ec88c636d8 | ||
cb5650c870 | |||
596a261e00 | |||
2db7b6bbf8 | |||
e38bfc7472 | |||
bedc1ed2e4 | |||
831665232c | |||
8ff7a6bd70 | |||
226f2e1ef0 | |||
|
cf7ef5a05b | ||
ad9a138a08 | |||
|
b18864ef83 | ||
73ab2891a6 | |||
|
5e92b511d2 | ||
22fe3f8c44 | |||
|
7b45a22fe2 | ||
753240d29e | |||
|
1342021398 | ||
e69f51b722 | |||
|
50fd741f9c | ||
2aad442d51 | |||
06797a344c | |||
|
a84228a11c | ||
|
b47b3de93d | ||
ff7576499d | |||
|
d61b0648fc | ||
95c9971d58 | |||
|
3f1684cf53 | ||
9fa3abc5b9 | |||
|
ef6fe70294 | ||
0071466b3e | |||
|
42154aad48 | ||
4d1cd317b9 | |||
|
d8e2fa7504 | ||
6072a3d5e6 | |||
|
12cd4bc38b | ||
9f1e80ea0c | |||
21ff9c0234 | |||
21737c33e4 | |||
842896642e | |||
96ac519fde | |||
f7779ace60 | |||
f49f69cc79 |
|
@ -4,12 +4,12 @@ on: [push]
|
|||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
container: python:3.11
|
||||
container: python:3.12.3
|
||||
steps:
|
||||
- run: apt-get update
|
||||
- run: apt-get install -y git nodejs
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Gr1N/setup-poetry@v8
|
||||
- uses: Gr1N/setup-poetry@v9
|
||||
- run: poetry install
|
||||
- run: poetry run flake8 .
|
||||
- run: poetry run mypy .
|
||||
|
@ -37,20 +37,20 @@ jobs:
|
|||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: ${{ gitea.ref == 'refs/heads/master' || startsWith(gitea.ref, 'refs/tags') }}
|
||||
push: ${{ gitea.ref_name == gitea.event.repository.default_branch || gitea.ref_type == 'tag' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
pypi:
|
||||
runs-on: ubuntu-latest
|
||||
container: python:3.11
|
||||
container: python:3.12.3
|
||||
needs: [lint]
|
||||
if: startsWith(gitea.ref, 'refs/tags')
|
||||
if: gitea.ref_type == 'tag'
|
||||
env:
|
||||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
|
||||
steps:
|
||||
- run: apt-get update
|
||||
- run: apt-get install -y git nodejs
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Gr1N/setup-poetry@v8
|
||||
- uses: Gr1N/setup-poetry@v9
|
||||
- run: poetry publish --build
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
FROM python:3.11.6 as build
|
||||
FROM python:3.12.3 as build
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN pip install poetry && poetry build
|
||||
|
||||
FROM python:3.11.5
|
||||
FROM python:3.12.3
|
||||
|
||||
COPY --from=build /app/dist /tmp/dist
|
||||
RUN pip install /tmp/dist/*.whl && rm -rf /tmp/dist
|
||||
|
|
0
divent/__init__.py
Normal file
0
divent/__init__.py
Normal file
3
divent/__main__.py
Normal file
3
divent/__main__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from divent.bot import run
|
||||
|
||||
run()
|
|
@ -3,9 +3,9 @@ import logging
|
|||
from datetime import datetime, timedelta
|
||||
from functools import wraps
|
||||
from os import getenv, path
|
||||
from typing import Dict, Optional
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
from disnake import Asset, Client, Guild
|
||||
from disnake import Asset, Client, Guild, Intents, Member, User
|
||||
from disnake.guild_scheduled_event import GuildScheduledEvent
|
||||
from dotenv import load_dotenv
|
||||
from ics import Calendar, ContentLine, Event
|
||||
|
@ -36,13 +36,47 @@ API_BASE_URL = getenv("API_BASE_URL", "https://discordapp.com/api")
|
|||
AUTHORIZATION_BASE_URL = f"{API_BASE_URL}/oauth2/authorize"
|
||||
TOKEN_URL = f"{API_BASE_URL}/oauth2/token"
|
||||
|
||||
CATALOG_CACHE = {}
|
||||
EVENTS_CACHE = {}
|
||||
|
||||
|
||||
class Discord(Client):
|
||||
async def on_ready(self):
|
||||
print(f"Logged on as {self.user}!", flush=True)
|
||||
|
||||
for guild in self.guilds:
|
||||
for scheduled_event in guild.scheduled_events:
|
||||
EVENTS_CACHE[scheduled_event.id] = [
|
||||
member.id
|
||||
for member in await scheduled_event.fetch_users().flatten()
|
||||
]
|
||||
|
||||
print("Events synchronised!", flush=True)
|
||||
|
||||
async def on_guild_scheduled_event_subscribe(
|
||||
self, event: GuildScheduledEvent, user: Union[Member, User]
|
||||
):
|
||||
EVENTS_CACHE[event.id].append(user.id)
|
||||
|
||||
async def on_guild_scheduled_event_unsubscribe(
|
||||
self, event: GuildScheduledEvent, user: Union[Member, User]
|
||||
):
|
||||
EVENTS_CACHE[event.id].remove(user.id)
|
||||
|
||||
async def on_guild_scheduled_event_create(self, event: GuildScheduledEvent):
|
||||
EVENTS_CACHE[event.id] = [
|
||||
member.id for member in await event.fetch_users().flatten()
|
||||
]
|
||||
|
||||
async def on_guild_scheduled_event_delete(self, event: GuildScheduledEvent):
|
||||
EVENTS_CACHE.pop(event.id)
|
||||
|
||||
|
||||
intents = Intents.default()
|
||||
intents.guild_scheduled_events = True
|
||||
intents.members = True
|
||||
client = Discord(intents=intents)
|
||||
|
||||
client = Discord()
|
||||
app = Quart(__name__)
|
||||
app.config["SECRET_KEY"] = OAUTH2_CLIENT_SECRET
|
||||
app.config["EXPLAIN_TEMPLATE_LOADING"] = QUART_DEBUG
|
||||
|
@ -57,9 +91,6 @@ def get_guild_by_id(guild_id: str) -> Optional[Guild]:
|
|||
return None
|
||||
|
||||
|
||||
CATALOG_CACHE = {}
|
||||
|
||||
|
||||
@app.errorhandler(500)
|
||||
async def errorhandler(error: Exception):
|
||||
print(f"\33[31m{error}\33[m", flush=True)
|
||||
|
@ -221,7 +252,10 @@ async def subscribe(entity_id: str):
|
|||
entity_id=guild.vanity_url_code or guild.id,
|
||||
)
|
||||
|
||||
try:
|
||||
user = await client.get_or_fetch_user(int(entity_id))
|
||||
except ValueError:
|
||||
return redirect(url_for(".login"))
|
||||
|
||||
if user and str(user.id) == entity_id:
|
||||
return await render_template(
|
||||
|
@ -281,7 +315,10 @@ async def ical(entity_id: str):
|
|||
|
||||
return calendar.serialize()
|
||||
|
||||
try:
|
||||
user = await client.get_or_fetch_user(int(entity_id))
|
||||
except ValueError:
|
||||
return redirect(url_for(".login"))
|
||||
|
||||
if user:
|
||||
calendar = Calendar()
|
||||
|
@ -295,12 +332,8 @@ async def ical(entity_id: str):
|
|||
)
|
||||
|
||||
for guild in client.guilds:
|
||||
if await guild.get_or_fetch_member(int(entity_id)):
|
||||
for scheduled_event in guild.scheduled_events:
|
||||
if user.id in [
|
||||
member.id
|
||||
for member in await scheduled_event.fetch_users().flatten()
|
||||
]:
|
||||
if user.id in EVENTS_CACHE[scheduled_event.id]:
|
||||
event = make_event(scheduled_event)
|
||||
calendar.events.append(event)
|
||||
|
||||
|
@ -309,7 +342,6 @@ async def ical(entity_id: str):
|
|||
return redirect(url_for(".login"))
|
||||
|
||||
|
||||
def __main__():
|
||||
quart_task = client.loop.create_task(app.run_task("0.0.0.0"))
|
||||
quart_task.add_done_callback(lambda f: client.loop.stop())
|
||||
client.run(DISCORD_TOKEN)
|
||||
def run():
|
||||
client.loop.create_task(client.start(DISCORD_TOKEN))
|
||||
app.run("0.0.0.0", loop=client.loop)
|
||||
|
|
1315
poetry.lock
generated
1315
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "divent"
|
||||
version = "4.0.0"
|
||||
version = "4.1.4"
|
||||
description = "The discord scheduled event calendar generator"
|
||||
authors = ["Xéfir Destiny <xefir@crystalyx.net>"]
|
||||
license = "WTFPL"
|
||||
|
@ -9,26 +9,26 @@ homepage = "https://divent.crystalyx.net/"
|
|||
repository = "https://git.crystalyx.net/Xefir/Divent"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
divent = 'divent.bot:__main__'
|
||||
divent = 'divent.bot:run'
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.8.1,<3.12"
|
||||
disnake = "^2.9.1"
|
||||
python = ">=3.8.1,<4.0.0"
|
||||
disnake = "^2.9.2"
|
||||
ics = "0.8.0.dev0"
|
||||
python-dotenv = "^1.0.0"
|
||||
quart = "^0.19.3"
|
||||
requests-oauthlib = "^1.3.1"
|
||||
uvicorn = "^0.24.0"
|
||||
python-dotenv = "^1.0.1"
|
||||
quart = "^0.19.6"
|
||||
requests-oauthlib = "^2.0.0"
|
||||
uvicorn = "^0.30.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
black = "^23.10.1"
|
||||
djlint = "^1.34.0"
|
||||
flake8 = "^6.1.0"
|
||||
black = "^24.4.2"
|
||||
djlint = "^1.34.1"
|
||||
flake8 = "^7.0.0"
|
||||
flake8-alphabetize = "^0.0.21"
|
||||
flake8-black = "^0.3.6"
|
||||
flake8-pyproject = "^1.2.3"
|
||||
mypy = "^1.6.1"
|
||||
types-oauthlib = "^3.2.0.10"
|
||||
mypy = "^1.10.0"
|
||||
types-oauthlib = "^3.2.0"
|
||||
|
||||
[tool.flake8]
|
||||
max-line-length = 88
|
||||
|
|
Loading…
Reference in New Issue
Block a user