From f74f3a6df751744a949fa6f3786e0df35eeba73d Mon Sep 17 00:00:00 2001 From: Ville Ranki Date: Tue, 21 Jul 2020 00:06:17 +0300 Subject: [PATCH] Added jitsi module (fixes #94). Modified dockerfile (fixes #92). --- Dockerfile | 7 +++---- Pipfile | 2 +- README.md | 5 +++++ modules/jitsi.py | 41 +++++++++++++++++++++++++++++++++++++++++ modules/loc.py | 2 -- 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 modules/jitsi.py diff --git a/Dockerfile b/Dockerfile index f39a2b8..9a3db65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,9 @@ WORKDIR /bot COPY Pipfile . RUN pip install pipenv && \ - pipenv install --pre && \ - pipenv install --deploy --system && \ - rm -r /root/.cache/* && \ - rm -r /root/.local/* + pip install pipfile-requirements +RUN pipfile2req Pipfile > requirements.txt +RUN pip install -r requirements.txt COPY bot.py *.json *.pickle /bot/ COPY config config diff --git a/Pipfile b/Pipfile index ff6eac4..ce28a43 100644 --- a/Pipfile +++ b/Pipfile @@ -15,7 +15,7 @@ requests = "*" igramscraper = "*" twitterscraper = "*" httpx = "*" -pyyaml = "==5.3" +PyYAML = "==5.3" wolframalpha = "*" [dev-packages] diff --git a/README.md b/README.md index 377377f..c156787 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,11 @@ bot ownership) * !flog rmlive - disable live field log for this room * !flog timezone 3 - set timezone (relative to UTC, see API docs) +### Jitsi + +If enabled, Jitsi calls created with Matrix clients will be sent as text messages +to rooms, allowing non-matrix users to join them. + ## Bot setup * Create a Matrix user diff --git a/modules/jitsi.py b/modules/jitsi.py new file mode 100644 index 0000000..197c2c9 --- /dev/null +++ b/modules/jitsi.py @@ -0,0 +1,41 @@ +from nio import RoomMessageUnknown, UnknownEvent + +from modules.common.module import BotModule + + +class MatrixModule(BotModule): + bot = None + + def matrix_start(self, bot): + super().matrix_start(bot) + self.bot = bot + bot.client.add_event_callback(self.unknownevent_cb, (UnknownEvent,)) + + def matrix_stop(self, bot): + super().matrix_stop(bot) + bot.remove_callback(self.unknownevent_cb) + + async def unknownevent_cb(self, room, event): + if event.type == 'im.vector.modular.widgets' and event.source['content']['type'] == 'jitsi': + domain = event.source['content']['data']['domain'] + conferenceId = event.source['content']['data']['conferenceId'] + isAudioOnly = event.source['content']['data']['isAudioOnly'] + sender = event.source['sender'] + sender_response = await self.bot.client.get_displayname(event.sender) + sender = sender_response.displayname + # This is just a guess - is this the proper way to generate URL? Probably not. + jitsiUrl = f'https://{domain}/{conferenceId}' + + calltype = 'video call' + if isAudioOnly: + calltype = 'audio call' + + plainMessage = f'{sender} started a {calltype}: {jitsiUrl}' + htmlMessage = f'{sender} started a {calltype}' + await self.bot.send_html(room, htmlMessage, plainMessage) + + async def matrix_message(self, bot, room, event): + pass + + def help(self): + return 'Sends text links when user starts a Jitsi video or audio call in room' diff --git a/modules/loc.py b/modules/loc.py index 1740a8e..ffa7679 100644 --- a/modules/loc.py +++ b/modules/loc.py @@ -3,8 +3,6 @@ from nio import RoomMessageUnknown from modules.common.module import BotModule -from modules.common.module import BotModule - class MatrixModule(BotModule): bot = None