1
1
import asyncio
2
- import base64
3
2
import datetime as dt
4
3
import difflib
5
4
import logging
6
5
import random
7
6
import re
8
- import uuid
9
7
from contextlib import suppress
10
8
from typing import Optional
11
9
from urllib .parse import quote_plus
22
20
import handshapes
23
21
import cuteid
24
22
import catchphrase
23
+ import meetings
25
24
26
25
# -----------------------------------------------------------------------------
27
26
@@ -370,26 +369,6 @@ async def idiom_command(ctx, spoiler: Optional[str]):
370
369
# -----------------------------------------------------------------------------
371
370
372
371
373
- async def create_meeting ():
374
- async with aiohttp .ClientSession () as client :
375
- resp = await client .post (
376
- f"https://api.zoom.us/v2/users/{ ZOOM_USER_ID } /meetings" ,
377
- json = {
378
- "type" : 1 ,
379
- "topic" : "PRACTICE" ,
380
- "settings" : {
381
- "host_video" : False ,
382
- "participant_video" : False ,
383
- "mute_upon_entry" : True ,
384
- "waiting_room" : False ,
385
- },
386
- },
387
- headers = {"Authorization" : f"Bearer { ZOOM_JWT } " },
388
- )
389
- resp .raise_for_status ()
390
- return await resp .json ()
391
-
392
-
393
372
ZOOM_TEMPLATE = """**Join URL**: {join_url}
394
373
**Passcode**: {passcode}
395
374
🚀 This meeting is happening now. Go practice!
@@ -406,15 +385,25 @@ async def zoom_command(ctx: Context):
406
385
message = await ctx .send ("Creating meeting..." )
407
386
logger .info ("creating zoom meeting" )
408
387
try :
409
- data = await create_meeting ()
388
+ meeting = await meetings .create_zoom (
389
+ token = ZOOM_JWT ,
390
+ user_id = ZOOM_USER_ID ,
391
+ topic = "PRACTICE" ,
392
+ settings = {
393
+ "host_video" : False ,
394
+ "participant_video" : False ,
395
+ "mute_upon_entry" : True ,
396
+ "waiting_room" : False ,
397
+ },
398
+ )
410
399
except Exception :
411
400
logger .exception ("could not create Zoom meeting" )
412
401
await message .edit (
413
402
content = "🚨 _Could not create Zoom meeting. That's embarrassing._"
414
403
)
415
404
else :
416
405
content = ZOOM_TEMPLATE .format (
417
- join_url = data [ " join_url" ] , passcode = data [ "password" ]
406
+ join_url = meeting . join_url , passcode = meeting . passcode
418
407
)
419
408
await message .edit (content = content , suppress = True )
420
409
@@ -441,13 +430,9 @@ async def zoom_error(ctx, error):
441
430
MEET_CLOSED_MESSAGE = "✨ _Jitsi Meet ended_"
442
431
443
432
444
- def pretty_uuid () -> str :
445
- return base64 .urlsafe_b64encode (uuid .uuid4 ().bytes ).decode ().replace ("=" , "" )
446
-
447
-
448
433
@bot .command (name = "meet" , aliases = ("jitsi" ,), help = "Start a Jitsi Meet meeting" )
449
434
async def meet_command (ctx : Context ):
450
- join_url = f"https://meet.jit.si/ { pretty_uuid () } "
435
+ join_url = meetings . create_jitsi_meet ()
451
436
content = MEET_TEMPLATE .format (join_url = join_url )
452
437
logger .info ("sending jitsi meet info" )
453
438
message = await ctx .send (content = content )
@@ -458,19 +443,6 @@ async def meet_command(ctx: Context):
458
443
# -----------------------------------------------------------------------------
459
444
460
445
461
- async def create_watch2gether (video_url : Optional [str ]) -> str :
462
- async with aiohttp .ClientSession () as client :
463
- payload = {"api_key" : WATCH2GETHER_API_KEY }
464
- if payload :
465
- payload ["share" ] = video_url
466
- resp = await client .post ("https://w2g.tv/rooms/create.json" , json = payload )
467
- resp .raise_for_status ()
468
- data = await resp .json ()
469
- stream_key = data ["streamkey" ]
470
- url = f"https://w2g.tv/rooms/{ stream_key } "
471
- return url
472
-
473
-
474
446
WATCH2GETHER_HELP = """Create a new watch2gether room
475
447
476
448
You can optionally pass a URL to use for the first video.
@@ -506,7 +478,7 @@ async def watch2gether_command(ctx: Context, video_url: str = None):
506
478
message = await ctx .send ("Creating watch2gether room..." )
507
479
logger .info ("creating watch2gether meeting" )
508
480
try :
509
- url = await create_watch2gether (video_url )
481
+ url = await meetings . create_watch2gether (WATCH2GETHER_API_KEY , video_url )
510
482
except Exception :
511
483
logger .exception ("could not create watch2gether room" )
512
484
await message .edit (
0 commit comments