updated weather and events
This commit is contained in:
parent
e96a1b9161
commit
e0e7d8655c
@ -1,7 +1,7 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
class UserLocation:
|
class UserLocation:
|
||||||
def __init__(self, db_name='user_location.db'):
|
def __init__(self, db_name='users_location.db'):
|
||||||
self.db_name = db_name
|
self.db_name = db_name
|
||||||
self.create_table()
|
self.create_table()
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ class UserLocation:
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS user_locations (
|
CREATE TABLE IF NOT EXISTS user_locations (
|
||||||
|
username TEXT NOT NULL,
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY,
|
||||||
location TEXT NOT NULL
|
location TEXT NOT NULL
|
||||||
)
|
)
|
||||||
@ -17,11 +18,11 @@ class UserLocation:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def set_user_location(self, user_id: int, location: str):
|
def set_user_location(self, username:str, user_id: int, location: str):
|
||||||
conn = sqlite3.connect(self.db_name)
|
conn = sqlite3.connect(self.db_name)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
INSERT INTO user_locations (username, user_id, location) VALUES (?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (username, user_id, location))
|
INSERT INTO user_locations (username, user_id, location) VALUES (?, ?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (username, user_id, location))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|||||||
11
main.py
11
main.py
@ -95,7 +95,7 @@ class TaskSelect(Select):
|
|||||||
updated = await asyncio.to_thread(lambda: service.tasks().update(tasklist=tasklist_id, task=task_id, body=body).execute())
|
updated = await asyncio.to_thread(lambda: service.tasks().update(tasklist=tasklist_id, task=task_id, body=body).execute())
|
||||||
|
|
||||||
if updated.get("status") == "completed":
|
if updated.get("status") == "completed":
|
||||||
await interaction.followup.send(f"User: {interaction.user.display_name} marked task: '{updated.get('title')}' as completed.", ephemeral=True)
|
await interaction.followup.send(f"User {interaction.user.display_name} marked task '{updated.get('title')}' as completed.", ephemeral=True)
|
||||||
print(f"User {interaction.user.display_name} just completed task {updated.get('title')}")
|
print(f"User {interaction.user.display_name} just completed task {updated.get('title')}")
|
||||||
username = interaction.user.display_name
|
username = interaction.user.display_name
|
||||||
user_id = interaction.user.id
|
user_id = interaction.user.id
|
||||||
@ -203,7 +203,6 @@ async def events(interaction: discord.Interaction):
|
|||||||
|
|
||||||
print(f"Start of week: {start_of_week.isoformat()}, End of week: {end_of_week.isoformat()}")
|
print(f"Start of week: {start_of_week.isoformat()}, End of week: {end_of_week.isoformat()}")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
events_result = service.events().list(
|
events_result = service.events().list(
|
||||||
calendarId='primary',
|
calendarId='primary',
|
||||||
@ -230,6 +229,12 @@ async def events(interaction: discord.Interaction):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
|
|
||||||
|
event_description = event.get('description', '')
|
||||||
|
|
||||||
|
if 'tasks.google.com' in event_description:
|
||||||
|
continue
|
||||||
|
|
||||||
event_time_str = event['start'].get('dateTime', event['start'].get('date'))
|
event_time_str = event['start'].get('dateTime', event['start'].get('date'))
|
||||||
if 'Z' in event_time_str:
|
if 'Z' in event_time_str:
|
||||||
event_time = datetime.datetime.fromisoformat(event_time_str.replace('Z', '+00:00'))
|
event_time = datetime.datetime.fromisoformat(event_time_str.replace('Z', '+00:00'))
|
||||||
@ -238,7 +243,6 @@ async def events(interaction: discord.Interaction):
|
|||||||
|
|
||||||
event_time_local = event_time.strftime("%A, %B %d, %Y, %H:%M")
|
event_time_local = event_time.strftime("%A, %B %d, %Y, %H:%M")
|
||||||
|
|
||||||
event_description = event.get('description')
|
|
||||||
task = f"**{event['summary']}**\n⏰ {event_time_local}\n Description: {event_description}"
|
task = f"**{event['summary']}**\n⏰ {event_time_local}\n Description: {event_description}"
|
||||||
embed.add_field(name="\u200b", value=task, inline=False)
|
embed.add_field(name="\u200b", value=task, inline=False)
|
||||||
|
|
||||||
@ -255,6 +259,7 @@ async def set_location(ctx, *, location: str):
|
|||||||
username = ctx.author.display_name
|
username = ctx.author.display_name
|
||||||
user_location_db.set_user_location(username, user_id, location)
|
user_location_db.set_user_location(username, user_id, location)
|
||||||
await ctx.send(f"Location set to: {location}")
|
await ctx.send(f"Location set to: {location}")
|
||||||
|
print(f"{username} just set location to {location}")
|
||||||
|
|
||||||
@bot.tree.command(name="weather", description="Check the weather!")
|
@bot.tree.command(name="weather", description="Check the weather!")
|
||||||
async def current_weather(interaction: discord.Interaction, location: str = None):
|
async def current_weather(interaction: discord.Interaction, location: str = None):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user