1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-26 06:22:22 +00:00

Reformat Matrix script

This commit is contained in:
Yohann D'ANELLO 2021-04-04 16:06:16 +02:00
parent aa69e6eadb
commit 5101746d29
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -30,8 +30,8 @@ class Command(BaseCommand):
else: else:
stat_file = os.stat("tfjm/static/logo.png") stat_file = os.stat("tfjm/static/logo.png")
with open("tfjm/static/logo.png", "rb") as f: with open("tfjm/static/logo.png", "rb") as f:
resp = await Matrix.upload(f, filename="logo.png", content_type="image/png", resp = (await Matrix.upload(f, filename="logo.png", content_type="image/png",
filesize=stat_file.st_size)[0][0] filesize=stat_file.st_size))[0][0]
avatar_uri = resp.content_uri avatar_uri = resp.content_uri
with open(".matrix_avatar", "w") as f: with open(".matrix_avatar", "w") as f:
f.write(avatar_uri) f.write(avatar_uri)
@ -169,15 +169,24 @@ class Command(BaseCommand):
await Matrix.invite("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org") await Matrix.invite("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
self.stdout.write(f"Give admin permissions for {admin}...") self.stdout.write(f"Give admin permissions for {admin}...")
await Matrix.set_room_power_level("#aide-jurys-orgas:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level("#aide-jurys-orgas:tfjm.org",
await Matrix.set_room_power_level("#annonces:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#bienvenue:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level("#annonces:tfjm.org",
await Matrix.set_room_power_level("#bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#cno:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level("#bienvenue:tfjm.org",
await Matrix.set_room_power_level("#dev-bot:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#faq:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level("#bot:tfjm.org",
await Matrix.set_room_power_level("#flood:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#je-cherche-une-equipe:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level("#cno:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#dev-bot:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#faq:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#flood:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level("#je-cherche-une-equipe:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
# Create tournament-specific channels # Create tournament-specific channels
for tournament in Tournament.objects.all(): for tournament in Tournament.objects.all():
@ -265,12 +274,18 @@ class Command(BaseCommand):
await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")
self.stdout.write(f"Give permissions to {admin} in all channels of the tournament {name}...") self.stdout.write(f"Give permissions to {admin} in all channels of the tournament {name}...")
await Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org",
await Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org",
await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) await Matrix.set_room_power_level(f"#general-{slug}:tfjm.org",
await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org", f"@{admin.matrix_username}:tfjm.org", 95) f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org",
f"@{admin.matrix_username}:tfjm.org", 95)
# Invite organizers and give permissions # Invite organizers and give permissions
for orga in tournament.organizers.all(): for orga in tournament.organizers.all():
@ -283,11 +298,16 @@ class Command(BaseCommand):
await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org")
if not orga.is_admin: if not orga.is_admin:
await Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) await Matrix.set_room_power_level(f"#annonces-{slug}:tfjm.org",
await Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#general-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) await Matrix.set_room_power_level(f"#flood-{slug}:tfjm.org",
await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org", f"@{orga.matrix_username}:tfjm.org", 50) await Matrix.set_room_power_level(f"#general-{slug}:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#orga-{slug}:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org", await Matrix.set_room_power_level(f"#tirage-au-sort-{slug}:tfjm.org",
f"@{orga.matrix_username}:tfjm.org", 50) f"@{orga.matrix_username}:tfjm.org", 50)
@ -295,10 +315,14 @@ class Command(BaseCommand):
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}...") self.stdout.write(f"Invite {participant} in public channels of the tournament {name}...")
await Matrix.invite(f"#annonces-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") await Matrix.invite(f"#annonces-{slug}:tfjm.org",
await Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") f"@{participant.matrix_username}:tfjm.org")
await Matrix.invite(f"#general-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") await Matrix.invite(f"#flood-{slug}:tfjm.org",
await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") f"@{participant.matrix_username}:tfjm.org")
await Matrix.invite(f"#general-{slug}:tfjm.org",
f"@{participant.matrix_username}:tfjm.org")
await Matrix.invite(f"#tirage-au-sort-{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():
@ -307,7 +331,8 @@ class Command(BaseCommand):
await Matrix.create_room( await Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias=f"poule-{slug}-{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}",
federate=False, federate=False,
@ -317,7 +342,8 @@ class Command(BaseCommand):
await Matrix.create_room( await Matrix.create_room(
visibility=RoomVisibility.public, visibility=RoomVisibility.public,
alias=f"poule-{slug}-{pool.id}-jurys", alias=f"poule-{slug}-{pool.id}-jurys",
name=f"{name} - Jour {pool.round} - Jurys poule " name=
f"{name} - Jour {pool.round} - Jurys 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 jurys - {pool}", topic=f"Discussion avec les jurys - {pool}",
federate=False, federate=False,
@ -331,17 +357,21 @@ class Command(BaseCommand):
isAudioConf='false', displayName='$matrix_display_name', isAudioConf='false', displayName='$matrix_display_name',
avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \ avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \
.replace("%24", "$") .replace("%24", "$")
await Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org", await Matrix.add_integration(
f"#poule-{slug}-{pool.id}:tfjm.org",
f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}", f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}",
f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool)) f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool))
await Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org", await Matrix.add_integration(
f"#poule-{slug}-{pool.id}:tfjm.org",
f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}", f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}",
"customwidget", "Tableau", str(pool)) "customwidget", "Tableau", str(pool))
# Invite admins and give permissions # Invite admins and give permissions
for admin in AdminRegistration.objects.all(): for admin in AdminRegistration.objects.all():
await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org",
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{admin.matrix_username}:tfjm.org") f"@{admin.matrix_username}:tfjm.org")
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{admin.matrix_username}:tfjm.org")
await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", await 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)
@ -350,8 +380,10 @@ class Command(BaseCommand):
# Invite organizers and give permissions # Invite organizers and give permissions
for orga in VolunteerRegistration.objects.all(): for orga in VolunteerRegistration.objects.all():
await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{orga.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org",
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{orga.matrix_username}:tfjm.org") f"@{orga.matrix_username}:tfjm.org")
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{orga.matrix_username}:tfjm.org")
if not orga.is_admin: if not orga.is_admin:
await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org",
@ -366,12 +398,16 @@ class Command(BaseCommand):
await Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") await Matrix.invite(f"#flood-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org")
await Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") await Matrix.invite(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org")
await Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") await Matrix.invite(f"#orga-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org")
await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org",
await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", f"@{jury.matrix_username}:tfjm.org") f"@{jury.matrix_username}:tfjm.org")
await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
f"@{jury.matrix_username}:tfjm.org")
await Matrix.invite(f"#tirage-au-sort-{slug}:tfjm.org",
f"@{jury.matrix_username}:tfjm.org")
if not jury.is_admin: if not jury.is_admin:
await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org", f"@{jury.matrix_username}:tfjm.org", 50) await Matrix.set_room_power_level(f"#jury-{slug}:tfjm.org",
f"@{jury.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org", await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}:tfjm.org",
f"@{jury.matrix_username}:tfjm.org", 50) f"@{jury.matrix_username}:tfjm.org", 50)
await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", await Matrix.set_room_power_level(f"#poule-{slug}-{pool.id}-jurys:tfjm.org",
@ -380,7 +416,8 @@ class Command(BaseCommand):
# Invite participants to the right pool # Invite participants to the right pool
for participation in pool.participations.all(): for participation in pool.participations.all():
for participant in participation.team.participants.all(): for participant in participation.team.participants.all():
await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") await Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org",
f"@{participant.matrix_username}:tfjm.org")
# Create private channels for teams # Create private channels for teams
for team in Team.objects.all(): for team in Team.objects.all():
@ -395,7 +432,8 @@ class Command(BaseCommand):
preset=RoomPreset.private_chat, preset=RoomPreset.private_chat,
) )
for participant in team.participants.all(): for participant in team.participants.all():
await Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org", f"@{participant.matrix_username}:tfjm.org") await Matrix.invite(f"#equipe-{team.trigram.lower}:tfjm.org",
f"@{participant.matrix_username}:tfjm.org")
await Matrix.set_room_power_level(f"#equipe-{team.trigram.lower()}:tfjm.org", await 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)