plateforme-corres2math/apps/participation/management/commands/fix_matrix_channels.py

44 lines
1.9 KiB
Python
Raw Normal View History

2020-10-29 16:22:07 +00:00
from asgiref.sync import async_to_sync
from nio import RoomPreset
from corres2math.matrix import Matrix, RoomVisibility
from django.core.management import BaseCommand
2020-10-29 18:41:07 +00:00
from registration.models import AdminRegistration, Registration
2020-10-29 16:22:07 +00:00
class Command(BaseCommand):
def handle(self, *args, **options):
Matrix.set_display_name("Bot des Correspondances")
if not async_to_sync(Matrix.resolve_room_alias)("#faq:correspondances-maths.fr"):
Matrix.create_room(
visibility=RoomVisibility.public,
alias="faq",
name="FAQ",
topic="Posez toutes vos questions ici !",
federate=False,
preset=RoomPreset.public_chat,
)
2020-10-29 18:41:07 +00:00
if not async_to_sync(Matrix.resolve_room_alias)("#annonces:correspondances-maths.fr"):
Matrix.create_room(
visibility=RoomVisibility.public,
alias="annonces",
name="Annonces",
topic="Informations importantes des Correspondances",
federate=False,
preset=RoomPreset.public_chat,
)
Matrix.set_room_power_level_event("#annonces:correspondances-maths.fr", "events_default", 50)
for r in Registration.objects.all():
Matrix.invite("#annonces:correspondances-maths.fr", f"@{r.matrix_username}:correspondances-maths.fr")
Matrix.invite("#faq:correspondances-maths.fr", f"@{r.matrix_username}:correspondances-maths.fr")
2020-10-29 16:22:07 +00:00
for admin in AdminRegistration.objects.all():
2020-10-29 18:41:07 +00:00
Matrix.set_room_power_level("#annonces:correspondances-maths.fr",
f"@{admin.matrix_username}:correspondances-maths.fr", 95)
2020-10-29 16:22:07 +00:00
Matrix.set_room_power_level("#faq:correspondances-maths.fr",
f"@{admin.matrix_username}:correspondances-maths.fr", 95)