mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 14:38:24 +02:00
Clone Corres2math platform
This commit is contained in:
2
apps/participation/management/commands/__init__.py
Normal file
2
apps/participation/management/commands/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
@ -0,0 +1,92 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import os
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from tfjm.matrix import Matrix, RoomPreset, RoomVisibility
|
||||
from django.core.management import BaseCommand
|
||||
from registration.models import AdminRegistration, Registration
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
Matrix.set_display_name("Bot du TFJM²")
|
||||
|
||||
if not os.getenv("SYNAPSE_PASSWORD"):
|
||||
avatar_uri = "plop"
|
||||
else: # pragma: no cover
|
||||
if not os.path.isfile(".matrix_avatar"):
|
||||
stat_file = os.stat("tfjm/static/logo.svg")
|
||||
with open("tfjm/static/logo.svg", "rb") as f:
|
||||
resp = Matrix.upload(f, filename="logo.svg", content_type="image/svg",
|
||||
filesize=stat_file.st_size)[0][0]
|
||||
avatar_uri = resp.content_uri
|
||||
with open(".matrix_avatar", "w") as f:
|
||||
f.write(avatar_uri)
|
||||
Matrix.set_avatar(avatar_uri)
|
||||
|
||||
with open(".matrix_avatar", "r") as f:
|
||||
avatar_uri = f.read().rstrip(" \t\r\n")
|
||||
|
||||
if not async_to_sync(Matrix.resolve_room_alias)("#faq:tfjm.org"):
|
||||
Matrix.create_room(
|
||||
visibility=RoomVisibility.public,
|
||||
alias="faq",
|
||||
name="FAQ",
|
||||
topic="Posez toutes vos questions ici !",
|
||||
federate=False,
|
||||
preset=RoomPreset.public_chat,
|
||||
)
|
||||
|
||||
if not async_to_sync(Matrix.resolve_room_alias)("#annonces:tfjm.org"):
|
||||
Matrix.create_room(
|
||||
visibility=RoomVisibility.public,
|
||||
alias="annonces",
|
||||
name="Annonces",
|
||||
topic="Informations importantes du TFJM²",
|
||||
federate=False,
|
||||
preset=RoomPreset.public_chat,
|
||||
)
|
||||
|
||||
if not async_to_sync(Matrix.resolve_room_alias)("#je-cherche-une-equipe:tfjm.org"):
|
||||
Matrix.create_room(
|
||||
visibility=RoomVisibility.public,
|
||||
alias="je-cherche-une-equipe",
|
||||
name="Je cherche une équipe",
|
||||
topic="Le Tinder du TFJM²",
|
||||
federate=False,
|
||||
preset=RoomPreset.public_chat,
|
||||
)
|
||||
|
||||
if not async_to_sync(Matrix.resolve_room_alias)("#flood:tfjm.org"):
|
||||
Matrix.create_room(
|
||||
visibility=RoomVisibility.public,
|
||||
alias="flood",
|
||||
name="Flood",
|
||||
topic="Discutez de tout et de rien !",
|
||||
federate=False,
|
||||
preset=RoomPreset.public_chat,
|
||||
)
|
||||
|
||||
Matrix.set_room_avatar("#annonces:tfjm.org", avatar_uri)
|
||||
Matrix.set_room_avatar("#faq:tfjm.org", avatar_uri)
|
||||
Matrix.set_room_avatar("#je-cherche-une-equipe:tfjm.org", avatar_uri)
|
||||
Matrix.set_room_avatar("#flood:tfjm.org", avatar_uri)
|
||||
|
||||
Matrix.set_room_power_level_event("#annonces:tfjm.org", "events_default", 50)
|
||||
|
||||
for r in Registration.objects.all():
|
||||
Matrix.invite("#annonces:tfjm.org", f"@{r.matrix_username}:tfjm.org")
|
||||
Matrix.invite("#faq:tfjm.org", f"@{r.matrix_username}:tfjm.org")
|
||||
Matrix.invite("#je-cherche-une-equipe:tfjm.org",
|
||||
f"@{r.matrix_username}:tfjm.org")
|
||||
Matrix.invite("#flood:tfjm.org", f"@{r.matrix_username}:tfjm.org")
|
||||
|
||||
for admin in AdminRegistration.objects.all():
|
||||
Matrix.set_room_power_level("#annonces:tfjm.org",
|
||||
f"@{admin.matrix_username}:tfjm.org", 95)
|
||||
Matrix.set_room_power_level("#faq:tfjm.org",
|
||||
f"@{admin.matrix_username}:tfjm.org", 95)
|
||||
Matrix.set_room_power_level("#flood:tfjm.org",
|
||||
f"@{admin.matrix_username}:tfjm.org", 95)
|
43
apps/participation/management/commands/fix_sympa_lists.py
Normal file
43
apps/participation/management/commands/fix_sympa_lists.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from tfjm.lists import get_sympa_client
|
||||
from django.core.management import BaseCommand
|
||||
from django.db.models import Q
|
||||
from participation.models import Team
|
||||
from registration.models import CoachRegistration, StudentRegistration
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
"""
|
||||
Create Sympa mailing lists and register teams.
|
||||
"""
|
||||
sympa = get_sympa_client()
|
||||
|
||||
sympa.create_list("equipes", "Équipes du TFJM²", "hotline",
|
||||
"Liste de diffusion pour contacter toutes les équipes validées du TFJM².",
|
||||
"education", raise_error=False)
|
||||
sympa.create_list("equipes-non-valides", "Équipes du TFJM²", "hotline",
|
||||
"Liste de diffusion pour contacter toutes les équipes non validées du TFJM².",
|
||||
"education", raise_error=False)
|
||||
|
||||
for problem in range(1, 4):
|
||||
sympa.create_list(f"probleme-{problem}",
|
||||
f"Équipes du TFJM² participant au problème {problem}", "hotline",
|
||||
f"Liste de diffusion pour contacter les équipes participant au problème {problem}"
|
||||
f" du TFJM².", "education", raise_error=False)
|
||||
|
||||
for team in Team.objects.filter(participation__valid=True).all():
|
||||
team.create_mailing_list()
|
||||
sympa.subscribe(team.email, "equipes", f"Equipe {team.name}", True)
|
||||
sympa.subscribe(team.email, f"probleme-{team.participation.problem}", f"Equipe {team.name}", True)
|
||||
|
||||
for team in Team.objects.filter(Q(participation__valid=False) | Q(participation__valid__isnull=True)).all():
|
||||
team.create_mailing_list()
|
||||
sympa.subscribe(team.email, "equipes-non-valides", f"Equipe {team.name}", True)
|
||||
|
||||
for student in StudentRegistration.objects.filter(team__isnull=False).all():
|
||||
sympa.subscribe(student.user.email, f"equipe-{student.team.trigram.lower}", True, f"{student}")
|
||||
for coach in CoachRegistration.objects.filter(team__isnull=False).all():
|
||||
sympa.subscribe(coach.user.email, f"equipe-{coach.team.trigram.lower}", True, f"{coach}")
|
44
apps/participation/management/commands/setup_third_phase.py
Normal file
44
apps/participation/management/commands/setup_third_phase.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from tfjm.matrix import Matrix, RoomVisibility
|
||||
from django.core.management import BaseCommand
|
||||
from participation.models import Participation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
for participation in Participation.objects.filter(valid=True).all():
|
||||
for i, question in enumerate(participation.questions.order_by("id").all()):
|
||||
solution_author = participation.received_participation.team
|
||||
alias = f"equipe-{solution_author.trigram.lower()}-question-{i}"
|
||||
room_id = f"#{alias}:tfjm.org"
|
||||
Matrix.create_room(
|
||||
visibility=RoomVisibility.public,
|
||||
alias=alias,
|
||||
name=f"Solution équipe {solution_author.trigram} - question {i+1}",
|
||||
topic=f"Échange entre l'équipe {solution_author.name} ({solution_author.trigram}) "
|
||||
f"et l'équipe {participation.team.name} ({participation.team.trigram}) "
|
||||
f"autour de la question {i+1} sur le problème {participation.problem}",
|
||||
federate=False,
|
||||
invite=[f"@{registration.matrix_username}:tfjm.org" for registration in
|
||||
list(participation.team.students.all()) + list(participation.team.coachs.all()) +
|
||||
list(solution_author.students.all()) + list(solution_author.coachs.all())],
|
||||
)
|
||||
Matrix.set_room_power_level_event(room_id, "events_default", 21)
|
||||
for registration in solution_author.students.all():
|
||||
Matrix.set_room_power_level(room_id,
|
||||
f"@{registration.matrix_username}:tfjm.org", 42)
|
||||
|
||||
Matrix.send_message(room_id, "Bienvenue dans la troisième phase du TFJM² !")
|
||||
Matrix.send_message(room_id, f"L'équipe {participation.team.name} a visionné la vidéo de l'équipe "
|
||||
f"{solution_author.name} sur le problème {participation.problem}, et a posé "
|
||||
"une série de questions.")
|
||||
Matrix.send_message(room_id, "L'équipe ayant composé la vidéo doit maintenant proposer une réponse.")
|
||||
Matrix.send_message(room_id, "Une fois la réponse apportée, vous pourrez ensuite échanger plus "
|
||||
"librement autour de la question, au travers de ce canal.")
|
||||
Matrix.send_message(room_id, "**Question posée :**", formatted_body="<strong>Question posée :</strong>")
|
||||
Matrix.send_message(room_id, question.question,
|
||||
formatted_body=f"<font color=\"#ff0000\">{question.question}</font>")
|
||||
|
||||
# TODO Setup the bot the set the power level of all members of the room to 42
|
Reference in New Issue
Block a user