changes on tasks

This commit is contained in:
Tenzing Kandang 2026-03-19 02:40:58 +01:00
parent 4da89f496d
commit a93efb4089

View File

@ -5,6 +5,7 @@ import google_auth_oauthlib.flow
from weather import OpenWeatherMapAPIClient from weather import OpenWeatherMapAPIClient
from googleapiclient.discovery import build from googleapiclient.discovery import build
from discord.ext import commands from discord.ext import commands
from dotenv import load_dotenv
global service global service
service = None service = None
@ -12,6 +13,7 @@ service = None
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
service = None service = None
load_dotenv()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
WEATHER_TOKEN = os.getenv("WEATHER_TOKEN") WEATHER_TOKEN = os.getenv("WEATHER_TOKEN")
@ -35,22 +37,33 @@ async def authenticate(interaction: discord.Interaction):
except Exception as e: except Exception as e:
await interaction.followup.send(f'An error occurred: {e}') await interaction.followup.send(f'An error occurred: {e}')
@bot.tree.command() @bot.tree.command(name='tasks_otd')
async def events(interaction: discord.Interaction): async def events(interaction: discord.Interaction):
if service is None: if service is None:
await interaction.response.send_message('Please authenticate first using the command authenticate.') await interaction.response.send_message('Please authenticate first using /authenticate.')
return return
now = datetime.datetime.utcnow().isoformat() + 'Z' now = datetime.datetime.utcnow().isoformat() + 'Z'
events_result =service.events().list(calendarId='primary', timeMin=now, maxResults=1, singleEvents=True, orderBy='startTime').execute() start_of_day = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + 'Z'
end_of_day = datetime.datetime.utcnow().replace(hour=23, minute=59, second=59, microsecond=999999).isoformat() + 'Z'
events_result = service.events().list(
calendarId='primary',
timeMin=start_of_day,
timeMax=end_of_day,
singleEvents=True,
orderBy='startTime'
).execute()
events = events_result.get('items',[]) events = events_result.get('items',[])
if not events: if not events:
await interaction.response.send_message('No upcoming events found.') await interaction.response.send_message('No tasks for today !')
else: else:
event_list = "\n".join([f"{event['start'].get('dateTime', event['start'].get('date'))}: {event['summary']}" for event in events]) tasks = []
await interaction.response.send_message(event_list) for event in events:
task= f"{event['summary']} at {event['start'].get('dateTime', event['start'].get('date'))}"
await interaction.response.send_message('\n'.join(tasks))
#Weather commad tree #Weather commad tree