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