From 5e2ff7a8593c3329c9b6e0dc76884ac528a52d40 Mon Sep 17 00:00:00 2001 From: tenzi Date: Wed, 1 Apr 2026 19:13:42 +0200 Subject: [PATCH] mark task as complete unfinsihed --- .gitignore | 2 +- .../__pycache__/database.cpython-313.pyc | Bin 2445 -> 2443 bytes bot/__pycache__/task.cpython-313.pyc | Bin 0 -> 2948 bytes .../__pycache__/weather.cpython-313.pyc | Bin 1878 -> 1876 bytes {utils => bot}/database.py | 0 bot/task.py | 40 +++++++++++ {utils => bot}/weather.py | 0 main.py | 64 ++++++++++-------- 8 files changed, 75 insertions(+), 31 deletions(-) rename {utils => bot}/__pycache__/database.cpython-313.pyc (85%) create mode 100644 bot/__pycache__/task.cpython-313.pyc rename {utils => bot}/__pycache__/weather.cpython-313.pyc (92%) rename {utils => bot}/database.py (100%) create mode 100644 bot/task.py rename {utils => bot}/weather.py (100%) diff --git a/.gitignore b/.gitignore index 8992d45..f17da50 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /dvenv copy.txt user_location.db -/utils/.env +/bot/.env diff --git a/utils/__pycache__/database.cpython-313.pyc b/bot/__pycache__/database.cpython-313.pyc similarity index 85% rename from utils/__pycache__/database.cpython-313.pyc rename to bot/__pycache__/database.cpython-313.pyc index ad100408e6ef39fea540166602f7b2b16bca76e7..d088d3eaf6073a5dee952ab3961ffbcc0c0f2e52 100644 GIT binary patch delta 44 zcmeAb?iSwQ!YHq$pOK%Ns$Y_tSCyHUt{)KO@8ud29~|Q7?y8@ZU$QxsQG){jLdOmk delta 46 zcmeAc?iJqP!lFDL9VO&%I0=W)CR#rO;vP|mLgxt!FlE%AM_9zi9OD2- z=J`2+33E{vO_M${L=($_yty@?FGLg`ICv&10+Whl zlCsz^k)vL`pgA{!6Zd%F)x)E3p9mjbpmiF+6un0l0SBWHDUzRpp%ge;i4>{AP4H>5 zN@RXv<`yYg9MP>T2#<{_5PNf~pjzFJH>7*lrGW%dX#H$8dk|p&7E_2^a>>Ab{7K8S5pMug}hzksjxPq_KAxGXKl zmg6T$8oYRD&itEZM|m)YNRi~xCr5@tQL{0$BaCXK2oAuNN*pN8r(#8#$8(R2eC)^q zOch=cCg`US-D_aEoAe&HAS6J$_sL>M$UW93D$?RXY~{PczlRt!mWr`r`~s&$F&;x5 zk4mp{MQ)_Mt#pzQ(6;+fN=W5+?0JyIa~wxeO;V1y3IgUgPNLZm_?Ujv@-=nz=oTgQve{hb`!myU%7kb zmsgvK!A4?m`#ZlKuO|lUiP>gizLA*!Q{oCc4xAguP;$CzyXmrBtCq50#F(+ZW>g^U ztPSxJV>bIiTJH7u>yBOZ1k2V+ju&m06^R+nI+PN_6G}!IDoO83&9q9Ye_yqIJx|n} zJ5}AZy_jpO?iw?+k|&jI%d&6P*0JDJVP4W)!!;|07p=K^)xPD4%D4^Q+AL!fzHIEN=Ha zSbmy3yCv?X-n(CEq|R=2>?Zr~%Z=plmiX7M{$|%uqid+yHPYxBc{E(_8mV`UH>L5q zG`=6{jm^_%Dfww?bnEi7{&cfH^T+ndb-<~7vpZk!&hK`o_62gh?|BD_egAnB_dSo29)-SsF+jTeK^`2o zn|!aCJl#m1ZYDyxh^wTAV1;N^E%rPpl(=} zs(wXT5BeEPM-UYZp93G@i{cCcc>Ni98HosE`_h0gPq)uBGn0+X$)>)8pv>Q?Q!+zvC#g2pte!mfgq9b@QOkxKcojpu{J(LBsU;J?1DgZdrZa|lV z?FPJXbb_YwW&9uIZ4nz5e-vr>_Jr7PPN3*fsKSt>cFmP}hHqG4aY-wcRMRyo{&nG( zpP1NNuz3W&Ini{GZ9&Zo_9YMQbI>r5N59}-5" - tasks_res = service.tasks().list( - tasklist=tl_id, showCompleted=True, showHidden=True, maxResults=250).execute() or {} + tasks_res = await asyncio.to_thread(lambda: service.tasks().list( + tasklist=tl_id, showCompleted=True, showHidden=True, maxResults=250).execute() or {}) items = tasks_res.get("items", []) or [] - lines = [] for t in items: if not isinstance(t, dict): @@ -96,35 +100,26 @@ async def today(interaction: discord.Interaction): due_date = parse_rfc3339_to_local_date(t.get("due")) completed_date = parse_rfc3339_to_local_date(t.get("completed")) - print("title:", t.get("title"), "due:", t.get("due"), "completed:", t.get("completed"), "status:", t.get("status")) - if due_date != today and completed_date != today: continue status = "✅" if t.get("status") == "completed" else "🔲" + t_id = t.get("id") title = t.get("title") or "(no title)" - - if completed_date == today and t.get("completed"): - completed_short = t["completed"].replace("T", " ").split(".")[0] - lines.append(f"{status} {title} - completed {completed_short}") - else: - if due_date: - lines.append(f"{status} {title} (due {due_date.isoformat()})") - else: - lines.append(f"{status}{title}") - if not lines: - continue + embed.add_field(name=f"{tl_title} - {status} {title}", value=f"ID: {t.get('id')}", inline=False) - value = "\n".join(lines)[:1024] - embed.add_field(name=tl_title, value=value, inline=False) + value = json.dumps({"tasklist_id": tl_id, "task_id": t.get("id")}) + options.append(discord.SelectOption(label=(title[:90] or "(no title)"), description=tl_title[:50], value=value)) added += 1 if added == 0: embed.description = "No tasks due today." - - await interaction.followup.send(embed=embed) + return + options = options[:25] + view = TasksView(options, interaction.user.id) + await interaction.followup.send(embed=embed, view=view) except Exception as e: await interaction.followup.send(f"An error occured:{e}") @@ -134,6 +129,7 @@ async def today(interaction: discord.Interaction): async def events(interaction: discord.Interaction): await interaction.response.defer(thinking=True) + print(f'Recieved weekly_events command by {interaction.user.display_name}') try: service = build_calendar_service() except FileNotFoundError: @@ -246,13 +242,21 @@ async def on_ready(): print(f'Logged in as {bot.user}') await authenticate() await bot.tree.sync() - #Liste commandes enregistré commands = await bot.tree.fetch_commands() print("Registered Commands:") for command in commands: print(f"- {command.name}") print("- !set_location") + + channel = bot.get_channel(1480922508566990879) + if channel: + embed = discord.Embed( + description="Bot is now online and ready to serve! Type / to check available commands" + ) + await channel.send(embed=embed) + print("your bot is online and ready to serve !") + bot.run(DISCORD_TOKEN)