changes on tasks
This commit is contained in:
parent
4da89f496d
commit
a93efb4089
29
task_bot.py
29
task_bot.py
@ -5,6 +5,7 @@ import google_auth_oauthlib.flow
|
||||
from weather import OpenWeatherMapAPIClient
|
||||
from googleapiclient.discovery import build
|
||||
from discord.ext import commands
|
||||
from dotenv import load_dotenv
|
||||
|
||||
global service
|
||||
service = None
|
||||
@ -12,6 +13,7 @@ service = None
|
||||
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
|
||||
service = None
|
||||
|
||||
load_dotenv()
|
||||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
||||
WEATHER_TOKEN = os.getenv("WEATHER_TOKEN")
|
||||
|
||||
@ -35,22 +37,33 @@ async def authenticate(interaction: discord.Interaction):
|
||||
except Exception as 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):
|
||||
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
|
||||
|
||||
now = datetime.datetime.utcnow().isoformat() + 'Z'
|
||||
events_result =service.events().list(calendarId='primary', timeMin=now, maxResults=1, singleEvents=True, orderBy='startTime').execute()
|
||||
events = events_result.get('items', [])
|
||||
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',[])
|
||||
|
||||
if not events:
|
||||
await interaction.response.send_message('No upcoming events found.')
|
||||
await interaction.response.send_message('No tasks for today !')
|
||||
else:
|
||||
event_list = "\n".join([f"{event['start'].get('dateTime', event['start'].get('date'))}: {event['summary']}" for event in events])
|
||||
await interaction.response.send_message(event_list)
|
||||
|
||||
tasks = []
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user