Updated plugins. AI plugin updated
This commit is contained in:
@@ -1,21 +1,39 @@
|
||||
"""
|
||||
This plugin provides a command to fetch YouTube video information from links.
|
||||
Plugin for providing a command to fetch YouTube video information from links.
|
||||
"""
|
||||
|
||||
# plugins/youtube.py
|
||||
|
||||
# Importing necessary libraries
|
||||
import re
|
||||
import logging
|
||||
import asyncio
|
||||
from pytubefix import YouTube
|
||||
import simplematrixbotlib as botlib
|
||||
import asyncio
|
||||
|
||||
def seconds_to_minutes_seconds(seconds):
|
||||
"""
|
||||
Converts seconds to a string representation of minutes and seconds.
|
||||
|
||||
Args:
|
||||
seconds (int): The number of seconds.
|
||||
|
||||
Returns:
|
||||
str: A string representation of minutes and seconds in the format MM:SS.
|
||||
"""
|
||||
minutes = seconds // 60
|
||||
seconds %= 60
|
||||
return f"{minutes:02d}:{seconds:02d}"
|
||||
|
||||
async def fetch_youtube_info(youtube_url):
|
||||
"""
|
||||
Asynchronously fetches information about a YouTube video.
|
||||
|
||||
Args:
|
||||
youtube_url (str): The URL of the YouTube video.
|
||||
|
||||
Returns:
|
||||
str: A message containing information about the YouTube video.
|
||||
None if an error occurs during fetching.
|
||||
"""
|
||||
try:
|
||||
video = YouTube(youtube_url)
|
||||
title = video.title
|
||||
@@ -31,8 +49,21 @@ async def fetch_youtube_info(youtube_url):
|
||||
return None
|
||||
|
||||
async def handle_command(room, message, bot, prefix, config):
|
||||
"""
|
||||
Asynchronously handles the command to fetch YouTube video information.
|
||||
|
||||
Args:
|
||||
room (Room): The Matrix room where the command was invoked.
|
||||
message (RoomMessage): The message object containing the command.
|
||||
bot (MatrixBot): The Matrix bot instance.
|
||||
prefix (str): The command prefix.
|
||||
config (dict): The bot's configuration.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
match = botlib.MessageMatch(room, message, bot, prefix)
|
||||
if match.is_not_from_this_bot() and re.search(r'youtube\.com/watch\?v=', message.body): # and room.room_id != '!uFhErnfpYhhlauJsNK:matrix.org':
|
||||
if match.is_not_from_this_bot() and re.search(r'youtube\.com/watch\?v=', message.body):
|
||||
logging.info("YouTube link detected")
|
||||
video_id_match = re.search(r'youtube\.com/watch\?v=([^\s]+)', message.body)
|
||||
if video_id_match:
|
||||
@@ -52,5 +83,3 @@ async def handle_command(room, message, bot, prefix, config):
|
||||
await asyncio.sleep(1) # wait for 1 second before retrying
|
||||
else:
|
||||
logging.error("Failed to fetch YouTube video information after retries")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user