2024-02-12 13:20:31 +00:00
|
|
|
# plugins/date.py
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import logging
|
|
|
|
import simplematrixbotlib as botlib
|
|
|
|
|
|
|
|
async def handle_command(room, message, bot, PREFIX):
|
|
|
|
"""
|
|
|
|
Function to handle the !date command.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
room (Room): The Matrix room where the command was invoked.
|
|
|
|
message (RoomMessage): The message object containing the command.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
|
|
|
if match.is_not_from_this_bot() and match.prefix() and match.command("date"):
|
|
|
|
logging.info("Fetching current date and time")
|
|
|
|
current_datetime = datetime.datetime.now()
|
|
|
|
day_of_week = current_datetime.strftime("%A")
|
|
|
|
month = current_datetime.strftime("%B")
|
|
|
|
year = current_datetime.strftime("%Y")
|
|
|
|
time = current_datetime.strftime("%I:%M:%S %p")
|
2024-02-12 21:41:01 +00:00
|
|
|
date_message = f"📅 Today is **{day_of_week}** of **{month}** in **{year}**. The time is **⏰ {time}**"
|
2024-02-12 13:20:31 +00:00
|
|
|
await bot.api.send_markdown_message(room.room_id, date_message)
|
|
|
|
logging.info("Sent current date and time to the room")
|