From 26d368e45089b6a198fa6ae0d1982c841a20d859 Mon Sep 17 00:00:00 2001 From: Israel Ferreira Date: Tue, 26 Nov 2019 23:58:44 -0300 Subject: [PATCH] Adding main functionality --- .gitignore | 3 + main.py | 141 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 23 ++++++++ 3 files changed, 167 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 894a44c..7696fb1 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +# vscode +.vscode/ \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..33f3b49 --- /dev/null +++ b/main.py @@ -0,0 +1,141 @@ +import os +import discord +from discord.ext import commands +from dotenv import load_dotenv + +load_dotenv() +token = os.getenv("DISCORD_TOKEN") + +bot = commands.Bot(command_prefix="!") + +lists_dict = {} + + +@bot.command(name="new", help="Creates a new todo list") +async def create_list(ctx, list_name): + embed = discord.Embed() + list_name = list_name.lower() + if list_name in lists_dict: + embed.color = 0xff0000 + embed.title = f"**List already exists!**" + embed.description = f"{list_name.capitalize()} already exists" + else: + embed.color = 0x00ff00 + embed.title = f"**List has been created!**" + embed.description = f"New list {list_name.capitalize()} has been created!" + lists_dict[list_name] = {} + await ctx.send(embed=embed) + + +@bot.command(name="delete", help="Removes todo list") +async def delete_list(ctx, list_name): + embed = discord.Embed() + list_name = list_name.lower() + if lists_dict.pop(list_name, None) is None: + embed.color = 0xff0000 + embed.title = f"**List not found!**" + embed.description = f"{list_name.capitalize()} was not found" + else: + embed.color = 0x00ff00 + embed.title = f"**List has been removed!**" + embed.description = f"{list_name.capitalize()} has been removed!" + await ctx.send(embed=embed) + + +@bot.command(name="add", help="Adds item to list") +async def add_item(ctx, item, list_name): + embed = discord.Embed() + item = item.lower() + list_name = list_name.lower() + if list_name not in lists_dict: + embed.color = 0xff0000 + embed.title = f"**List not found!**" + embed.description = f"{list_name.capitalize()} was not found" + else: + lists_dict[list_name][item] = False + embed.color = 0x00ff00 + embed.title = list_name.capitalize() + items = "" + for item in lists_dict[list_name]: + if lists_dict[list_name][item]: + items += f"~~[X] {item.capitalize()}~~\n" + else: + items += f"[ \u200B \u200B ] {item.capitalize()}\n" + embed.description = items + await ctx.send(embed=embed) + + +@bot.command(name="remove", help="Removes item from list") +async def remove_item(ctx, item, list_name): + embed = discord.Embed() + item = item.lower() + list_name = list_name.lower() + if list_name not in lists_dict: + embed.color = 0xff0000 + embed.title = f"**List not found!**" + embed.description = f"{list_name.capitalize()} was not found" + elif item not in lists_dict[list_name]: + embed.color = 0xff0000 + embed.title = f"**Item was not found on list!**" + embed.description = f"{item.capitalize()} was not found in {list_name.capitalize()}" + else: + lists_dict[list_name].pop(item, None) + embed.color = 0x00ff00 + embed.title = list_name.capitalize() + items = "" + for item in lists_dict[list_name]: + if lists_dict[list_name][item]: + items += f"~~[X] {item.capitalize()}~~\n" + else: + items += f"[ \u200B \u200B ] {item.capitalize()}\n" + embed.description = items + await ctx.send(embed=embed) + + +@bot.command(name="done", help="Sets item as done") +async def set_done(ctx, item, list_name): + embed = discord.Embed() + item = item.lower() + list_name = list_name.lower() + if list_name not in lists_dict: + embed.color = 0xff0000 + embed.title = f"**List not found!**" + embed.description = f"{list_name.capitalize()} was not found" + elif item not in lists_dict[list_name]: + embed.color = 0xff0000 + embed.title = f"**Item was not found on list!**" + embed.description = f"{item.capitalize()} was not found in {list_name.capitalize()}" + else: + lists_dict[list_name][item] = True + embed.color = 0x00ff00 + embed.title = list_name.capitalize() + items = "" + for item in lists_dict[list_name]: + if lists_dict[list_name][item]: + items += f"~~[X] {item.capitalize()}~~\n" + else: + items += f"[ \u200B \u200B ] {item.capitalize()}\n" + embed.description = items + await ctx.send(embed=embed) + + +@bot.command(name="show", help="Shows list contents") +async def show_list(ctx, list_name): + embed = discord.Embed() + list_name = list_name.lower() + if list_name not in lists_dict: + embed.color = 0xff0000 + embed.title = f"**List not found!**" + embed.description = f"{list_name.capitalize()} was not found" + else: + embed.title = list_name.capitalize() + items = "" + for item in lists_dict[list_name]: + if lists_dict[list_name][item]: + items += f"~~[X] {item.capitalize()}~~\n" + else: + items += f"[ \u200B \u200B ] {item.capitalize()}\n" + embed.description = items + await ctx.send(embed=embed) + +bot.run(token) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..44e6a88 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,23 @@ +aiohttp==3.5.4 +astroid==2.3.3 +async-timeout==3.0.1 +attrs==19.3.0 +autopep8==1.4.4 +chardet==3.0.4 +discord==1.0.1 +discord.py==1.2.5 +idna==2.8 +idna-ssl==1.1.0 +isort==4.3.21 +lazy-object-proxy==1.4.3 +mccabe==0.6.1 +multidict==4.6.1 +pycodestyle==2.5.0 +pylint==2.4.4 +python-dotenv==0.10.3 +six==1.13.0 +typed-ast==1.4.0 +typing-extensions==3.7.4.1 +websockets==6.0 +wrapt==1.11.2 +yarl==1.3.0