Matrix channels are working

This commit is contained in:
Yohann D'ANELLO 2021-01-18 15:30:24 +01:00
parent 64e2d8d264
commit b4da740fb6
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 41 additions and 25 deletions

View File

@ -65,7 +65,7 @@ class Command(BaseCommand):
Matrix.create_room( Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias="bot", alias="bot",
name="#bot", name="Bot",
topic="Vive les r0b0ts", topic="Vive les r0b0ts",
federate=False, federate=False,
preset=RoomPreset.public_chat, preset=RoomPreset.public_chat,
@ -75,7 +75,7 @@ class Command(BaseCommand):
Matrix.create_room( Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias="cno", alias="cno",
name="#cno", name="CNO",
topic="Channel des dieux", topic="Channel des dieux",
federate=False, federate=False,
preset=RoomPreset.private_chat, preset=RoomPreset.private_chat,
@ -105,7 +105,7 @@ class Command(BaseCommand):
Matrix.create_room( Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias="flood", alias="flood",
name="#flood", name="Flood",
topic="Discutez de tout et de rien !", topic="Discutez de tout et de rien !",
federate=False, federate=False,
preset=RoomPreset.public_chat, preset=RoomPreset.public_chat,
@ -121,8 +121,8 @@ class Command(BaseCommand):
preset=RoomPreset.public_chat, preset=RoomPreset.public_chat,
) )
# Setup avaters # Setup avatars
Matrix.set_room_avatar("#aide-jury-orgas:tfjm.org", avatar_uri) Matrix.set_room_avatar("#aide-jurys-orgas:tfjm.org", avatar_uri)
Matrix.set_room_avatar("#annonces:tfjm.org", avatar_uri) Matrix.set_room_avatar("#annonces:tfjm.org", avatar_uri)
Matrix.set_room_avatar("#bienvenue:tfjm.org", avatar_uri) Matrix.set_room_avatar("#bienvenue:tfjm.org", avatar_uri)
Matrix.set_room_avatar("#bot:tfjm.org", avatar_uri) Matrix.set_room_avatar("#bot:tfjm.org", avatar_uri)
@ -144,18 +144,23 @@ class Command(BaseCommand):
Matrix.invite("#flood:tfjm.org", f"@{r.matrix_username}:tfjm.org") Matrix.invite("#flood:tfjm.org", f"@{r.matrix_username}:tfjm.org")
Matrix.invite("#je-cherche-une-equipe:tfjm.org", Matrix.invite("#je-cherche-une-equipe:tfjm.org",
f"@{r.matrix_username}:tfjm.org") f"@{r.matrix_username}:tfjm.org")
self.stdout.write(f"Invite {r} in most common channels...")
# Volunteers have access to the help channel # Volunteers have access to the help channel
for volunteer in VolunteerRegistration.objects.all(): for volunteer in VolunteerRegistration.objects.all():
Matrix.invite("#aide-jury-orgas:tfjm.org", f"@{volunteer.matrix_username}:tfjm.org") Matrix.invite("#aide-jurys-orgas:tfjm.org", f"@{volunteer.matrix_username}:tfjm.org")
self.stdout.write(f"Invite {volunteer} in #aide-jury-orgas...")
# Admins are admins # Admins are admins
for admin in AdminRegistration.objects.all(): for admin in AdminRegistration.objects.all():
self.stdout.write(f"Invite {admin} in #cno and #dev-bot...")
Matrix.invite("#cno:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite("#cno:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.invite("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.set_room_power_level("#aide-jury-orgas:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) self.stdout.write(f"Give admin permissions for {admin}...")
Matrix.set_room_power_level("#aide-jurys-orgas:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level("#annonces:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level("#annonces:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level("#bienvenue:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level("#bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level("#bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level("#cno:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level("#cno:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
@ -165,6 +170,8 @@ class Command(BaseCommand):
# Create tournament-specific channels # Create tournament-specific channels
for tournament in Tournament.objects.all(): for tournament in Tournament.objects.all():
self.stdout.write(f"Managing tournament of {tournament.name}.")
name = tournament.name name = tournament.name
slug = name.lower().replace(" ", "-") slug = name.lower().replace(" ", "-")
@ -227,12 +234,14 @@ class Command(BaseCommand):
# Invite admins and give permissions # Invite admins and give permissions
for admin in AdminRegistration.objects.all(): for admin in AdminRegistration.objects.all():
self.stdout.write(f"Invite {admin} in all channels of the tournament {name}...")
Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.invite(f"#general-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#general-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
self.stdout.write(f"Give permissions to {admin} in all channels of the tournament {name}...")
Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95)
@ -241,31 +250,35 @@ class Command(BaseCommand):
# Invite organizers and give permissions # Invite organizers and give permissions
for orga in tournament.organizers.all(): for orga in tournament.organizers.all():
self.stdout.write(f"Invite organizer {orga} in all channels of the tournament {name}...")
Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.invite(f"#general-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#general-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) if not orga.is_admin:
Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
# Invite participants # Invite participants
for participation in tournament.participations.filter(valid=True).all(): for participation in tournament.participations.filter(valid=True).all():
for participant in participation.team.participants.all(): for participant in participation.team.participants.all():
self.stdout.write(f"Invite {participant} in public channels of the tournament {name}...")
Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org")
Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org")
Matrix.invite(f"#general-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") Matrix.invite(f"#general-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org")
# Create pool-specific channels # Create pool-specific channels
for pool in tournament.pools.all(): for pool in tournament.pools.all():
if not async_to_sync(Matrix.resolve_room_alias)(f"#poule-{pool.id}:tfjm.org"): self.stdout.write(f"Managing {pool}...")
if not async_to_sync(Matrix.resolve_room_alias)(f"#poule-{slug}-{pool.id}:tfjm.org"):
Matrix.create_room( Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias=f"poule-{pool.id}", alias=f"poule-{slug}-{pool.id}",
name=f"{name} - Jour {pool.round} - Poule " name=f"{name} - Jour {pool.round} - Poule "
f"{', '.join(participation.team.trigram for participation in pool.participations.all())}", f"{', '.join(participation.team.trigram for participation in pool.participations.all())}",
topic=f"Discussion avec les équipes - {pool}", topic=f"Discussion avec les équipes - {pool}",
@ -293,7 +306,7 @@ class Command(BaseCommand):
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jury:tfjm.org", Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
# Invite organizers and give permissions # Invite organizers and give permissions
@ -301,10 +314,11 @@ class Command(BaseCommand):
Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{orga.matrix_username}:tfjm.org") Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", if not orga.is_admin:
f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org",
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jury:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50)
f"@{orga.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50)
# Invite the jury, give good permissions # Invite the jury, give good permissions
for jury in pool.juries.all(): for jury in pool.juries.all():
@ -316,11 +330,12 @@ class Command(BaseCommand):
Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{jury.matrix_username}:tfjm.org")
Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{jury.matrix_username}:tfjm.org") Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{jury.matrix_username}:tfjm.org")
Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org", 50) if not jury.is_admin:
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org", 50)
f"@{jury.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org",
Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jury:tfjm.org", f"@{jury.matrix_username}:tfjm.org", 50)
f"@{jury.matrix_username}:tfjm.org", 50) Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{jury.matrix_username}:tfjm.org", 50)
# Invite participants to the right pool # Invite participants to the right pool
for participation in pool.participations.all(): for participation in pool.participations.all():
@ -329,6 +344,7 @@ class Command(BaseCommand):
# Create private channels for teams # Create private channels for teams
for team in Team.objects.all(): for team in Team.objects.all():
self.stdout.write(f"Create private channel for {team}...")
if not async_to_sync(Matrix.resolve_room_alias)(f"#equipe-{team.trigram.lower()}:tfjm.org"): if not async_to_sync(Matrix.resolve_room_alias)(f"#equipe-{team.trigram.lower()}:tfjm.org"):
Matrix.create_room( Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
@ -340,5 +356,5 @@ class Command(BaseCommand):
) )
for participant in team.participants.all(): for participant in team.participants.all():
Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org", f"@{participant.matrix_username}:tfjm.org")
Matrix.set_room_power_level(f"#equipe-{team.trigram.lower}:tfjm.org", Matrix.set_room_power_level(f"#equipe-{team.trigram.lower()}:tfjm.org",
f"@{participant.matrix_username}:tfjm.org", 50) f"@{participant.matrix_username}:tfjm.org", 50)