task completed e

This commit is contained in:
Tenzing Kandang 2026-03-25 21:59:33 +01:00
parent 3aab9eace2
commit 1112cd83bf
2 changed files with 52 additions and 19 deletions

34
database.py Normal file
View File

@ -0,0 +1,34 @@
import sqlite3
class UserLocation:
def __init__(self, db_name='user_location.db'):
self.db_name = db_name
self.create_table()
def create_table(self):
conn = sqlite3.connect(self.db_name)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_locations (
user_id INTEGER PRIMARY KEY,
location TEXT NOT NULL
)
''')
conn.commit()
conn.close()
def set_user_location(self, user_id: int, location: str):
conn = sqlite3.connect(self.db_name)
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_locations (user_id, location) VALUES (?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (user_id, location))
conn.commit()
conn.close()
def get_user_location(self, user_id: int) -> str:
conn = sqlite3.connect(self.db_name)
cursor = conn.cursor()
cursor.execute('SELECT location FROM user_locations WHERE user_id = ?', (user_id,))
row = cursor.fetchone()
conn.close()
return row[0] if row else None

View File

@ -81,7 +81,7 @@ async def authenticate():
@bot.tree.command(name="daily_tasks", description="Check today's saved tasks")
async def today(interaction: discord.Interaction):
await interaction.response.defer()
await interaction.response.defer(thinking=True)
try:
service = build_tasks_service()
tl_res = service.tasklists().list(maxResults=100).execute()
@ -91,30 +91,28 @@ async def today(interaction: discord.Interaction):
color=0x2ecc71,
timestamp=datetime.datetime.now(tz=TZ)
)
any_tasks = False
for tl in lists:
tl_id = tl["id"]
tl_title = tl.get("title", "Untitled")
tasks_res = service.tasks().list(tasklist=tl_id, showCompleted=True, maxResults=200).execute()
items = tasks_res.get("items", [])
day_tasks = [t for t in items if is_due_today(t.get("due"))]
if not day_tasks:
if not items:
continue
any_tasks = True
lines = []
for t in sorted(day_tasks, key=lambda x: x.get("due") or ""):
status = "✅done" if t.get("status") == "completed" else "🔲"
time = due_time_str(t.get("due"))
title = t.get("title", "(no title)")
tid = t.get("id", "")
lines.append(f"{status} {title}{(' - ' + time) if time else ''} (id:{tid})")
value = "\n".join(lines)[:1024]
embed.add_field(name=tl_title, value=value, inline=False)
if not any_tasks:
embed.description = "No tasks due today."
await interaction.followup.send(embed=embed)
lines = []
for t in items:
status = "" if t.get("status") == "completed" else "🔲"
title = t.get("title", "(no title)")
lines.append(f"{status} {title}")
value = "\n".join(lines)[:1024]
embed.add_field(name=tl_title, value=value, inline=False)
if not embed.fields:
embed.description = "No tasks due today."
await interaction.followup.send(embed=embed)
except Exception as e:
await interaction.followup.send(f"An error occured:{e}")
@ -167,9 +165,9 @@ async def events(interaction: discord.Interaction):
return
else:
embed = discord.Embed(
title="📅 Weekly Events Summary",
description="This week's events",
color=discord.Color.blue()
title="📅 This week's events",
color=discord.Color.blue(),
timestamp=datetime.datetime.now(tz=TZ)
)
for event in events:
@ -223,7 +221,8 @@ async def current_weather(interaction: discord.Interaction, location: str = None
embed = discord.Embed(
title=f"Current weather in {location}",
description=f"Temperature: {temp}°C\nWeather condition: {weather_condition}",
color=discord.Color.yellow()
color=discord.Color.yellow(),
timestamp=datetime.datetime.now(tz=TZ)
)
embed.set_thumbnail(url=f"https://openweathermap.org/img/wn/{icon}.png")