Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Add Google Tasks integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ASmallSquishySquid committed Jan 21, 2024
1 parent afc2fc7 commit ed84cf9
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
70 changes: 70 additions & 0 deletions cogs/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from typing import List

import discord
from discord import app_commands
from discord.app_commands import locale_str as _T
from discord.ext import commands

import helpers.constants as constants
from helpers.google import Google, Task

class Tasks(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot

@commands.hybrid_command(
description=_T("tasks"),
help="Get your tasks"
)
@app_commands.describe(
task_list=_T("tasks-task_list")
)
@commands.is_owner()
@app_commands.default_permissions()
async def tasks(self, ctx: commands.Context, *,
task_list: str = commands.parameter(default=None, description="The task list")):

list_id = None
name = None
tasklists = Google.tasklists()

if not task_list:
list_id = tasklists[0].id
name = tasklists[0].title
else:
tasklist = next((tasklist for tasklist in tasklists
if task_list == tasklist.id or task_list in tasklist.title.lower()), None)

if not tasklist:
await ctx.send(f"That task list does not exist {constants.DEFAULT_EMOTE}")
return

list_id = tasklist.id
name = tasklist.title

tasks = Google.tasks(list_id)

await ctx.send(embed=self.build_tasks_embed(tasks, name))

@tasks.autocomplete("task_list")
async def tasks_autocomplete(
self, interaction: discord.Interaction, current: str,) -> List[app_commands.Choice[str]]:
tasklists = Google.tasklists()
return [
app_commands.Choice(name=tasklist.title, value=tasklist.id)
for tasklist in tasklists if current.lower() in tasklist.title.lower()
]

def build_tasks_embed(self, tasks: List[Task], name: str) -> discord.Embed:
embed_message = discord.Embed(
title=name,
description="\n".join([f"☐ {task.title}" for task in tasks]),
color=discord.Color.blue())
embed_message.set_author(
name="Google Tasks",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Google_Tasks_2021.svg/527px-Google_Tasks_2021.svg.png")

return embed_message

async def setup(bot: commands.Bot):
await bot.add_cog(Tasks(bot))
2 changes: 1 addition & 1 deletion helpers/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import discord

COGS = {"admin", "contextmenus", "crochet", "events",
"loops", "recipes", "reminders", "textcommands"}
"loops", "recipes", "reminders", "tasks", "textcommands"}
DEFAULT_ACTIVITY = discord.Activity(type=discord.ActivityType.watching, name="you 👀")
DEFAULT_EMOTE = "<:charmanderawr:837344550804127774>"
DEFAULT_LOCALE = discord.Locale.american_english
Expand Down
9 changes: 9 additions & 0 deletions helpers/l10n/en-US/commands.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ arg-desc-set-when = When do you want to be reminded?
arg-desc-delete-reminder_id = The ID of the reminder being deleted


# Tasks
cmd-tasks = tasks
desc-tasks = Get your tasks

arg-task_list = task_list

arg-desc-tasks-task_list = The task list


## Text commands
cmd-date = date
desc-date = Get the current date and time
Expand Down

0 comments on commit ed84cf9

Please sign in to comment.