From 77a12754319f4015617d680cf5a5096751294231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Tue, 23 Jan 2024 17:46:39 +0100 Subject: [PATCH] Add introduction command !parkerbot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Abdulkadir Furkan Şanlı --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 54d6551..ddfe659 100755 --- a/main.py +++ b/main.py @@ -185,7 +185,7 @@ async def message_callback(client, room, event): youtube_link_pattern = r"(https?://(?:www\.|music\.)?youtube\.com/(?!playlist\?list=)watch\?v=[\w-]+|https?://youtu\.be/[\w-]+)" sender = event.sender if sender != MATRIX_USER: - body = event.body + body = event.body.strip() timestamp = event.server_timestamp room_id = room.room_id monday_date = get_monday_date(timestamp) @@ -198,6 +198,16 @@ async def message_callback(client, room, event): ) # milisec to sec current_time = datetime.now(datetime.UTC) + if body == "!parkerbot" and current_time - timestamp_sec < timedelta(seconds=30): + intro_message = ("Hi, I'm ParkerBot! I generate YouTube playlists " + "from links sent to this channel. You can find my source code here: " + "https://git.abdulocra.cy/abdulocracy/parkerbot") + await client.room_send( + room_id=room_id, + message_type="m.room.message", + content={"msgtype": "m.text", "body": intro_message} + ) + if body == "!pow" and current_time - timestamp_sec < timedelta(seconds=30): playlist_link = f"https://www.youtube.com/playlist?list={playlist_id}" reply_msg = f"{sender}, here's the playlist of the week: {playlist_link}"