Add introduction command !parkerbot

Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
Abdulkadir Furkan Şanlı 2024-01-23 17:46:39 +01:00
parent bd976a2cd5
commit 77a1275431
Signed by: afk
SSH Key Fingerprint: SHA256:s1hULLl4YWdqU501MUfGe1CAG/m1pf9Cs6vFsqeTNHk

12
main.py
View File

@ -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}"