From e0e7d8655c8b11fa8507c78d20c822c3a998fadf Mon Sep 17 00:00:00 2001 From: tenzi Date: Thu, 16 Apr 2026 17:14:01 +0200 Subject: [PATCH] updated weather and events --- bot/database.py | 7 ++++--- main.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bot/database.py b/bot/database.py index 63f58b0..f31cad7 100644 --- a/bot/database.py +++ b/bot/database.py @@ -1,7 +1,7 @@ import sqlite3 class UserLocation: - def __init__(self, db_name='user_location.db'): + def __init__(self, db_name='users_location.db'): self.db_name = db_name self.create_table() @@ -10,6 +10,7 @@ class UserLocation: cursor = conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS user_locations ( + username TEXT NOT NULL, user_id INTEGER PRIMARY KEY, location TEXT NOT NULL ) @@ -17,11 +18,11 @@ class UserLocation: conn.commit() 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) cursor = conn.cursor() 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.close() diff --git a/main.py b/main.py index dd2d8c8..ffacf10 100644 --- a/main.py +++ b/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()) 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')}") username = interaction.user.display_name 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()}") - try: events_result = service.events().list( calendarId='primary', @@ -230,6 +229,12 @@ async def events(interaction: discord.Interaction): ) 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')) if 'Z' in event_time_str: 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_description = event.get('description') task = f"**{event['summary']}**\n⏰ {event_time_local}\n Description: {event_description}" 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 user_location_db.set_user_location(username, user_id, 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!") async def current_weather(interaction: discord.Interaction, location: str = None):