-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
154 lines (138 loc) · 5.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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.colour = 0xff0000
embed.title = f"**List already exists!**"
embed.description = f"{list_name.capitalize()} already exists"
else:
embed.colour = 0x00ff00
embed.title = f"**List has been created!**"
embed.description = f"New list {list_name.capitalize()} has been created!"
embed.set_author(name=ctx.message.author.name,
icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
list_content = {}
list_content["author"] = ctx.message.author.name
list_content["items"] = {}
lists_dict[list_name] = list_content
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.colour = 0xff0000
embed.title = f"**List not found!**"
embed.description = f"{list_name.capitalize()} was not found"
else:
embed.colour = 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.colour = 0xff0000
embed.title = f"**List not found!**"
embed.description = f"{list_name.capitalize()} was not found"
else:
lists_dict[list_name]["items"][item] = False
embed.colour = 0x00ff00
embed.title = list_name.capitalize()
embed.set_author(name=lists_dict[list_name]["author"],
icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
items = ""
for item in lists_dict[list_name]["items"]:
if lists_dict[list_name]["items"][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.colour = 0xff0000
embed.title = f"**List not found!**"
embed.description = f"{list_name.capitalize()} was not found"
elif item not in lists_dict[list_name]["items"]:
embed.colour = 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]["items"].pop(item, None)
embed.colour = 0x00ff00
embed.title = list_name.capitalize()
embed.set_author(name=lists_dict[list_name]["author"],
icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
items = ""
for item in lists_dict[list_name]["items"]:
if lists_dict[list_name]["items"][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.colour = 0xff0000
embed.title = f"**List not found!**"
embed.description = f"{list_name.capitalize()} was not found"
elif item not in lists_dict[list_name]["items"]:
embed.colour = 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]["items"][item] = True
embed.colour = 0x00ff00
embed.title = list_name.capitalize()
embed.set_author(name=lists_dict[list_name]["author"],
icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
items = ""
for item in lists_dict[list_name]["items"]:
if lists_dict[list_name]["items"][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.colour = 0xff0000
embed.title = f"**List not found!**"
embed.description = f"{list_name.capitalize()} was not found"
else:
embed.title = list_name.capitalize()
embed.set_author(name=lists_dict[list_name]["author"],
icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
items = ""
for item in lists_dict[list_name]["items"]:
if lists_dict[list_name]["items"][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)