-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtodoList.py
More file actions
106 lines (80 loc) · 2.12 KB
/
todoList.py
File metadata and controls
106 lines (80 loc) · 2.12 KB
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
import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import json
db = dict() # or mongodb
"""
dictionnary of <string, List<dict<string, string>>>
db = {
"user1": [{"name": "todo1"}, "name": "todo2", ...]
"user2": []
.
.
.
}
"""
client = commands.Bot(command_prefix = "/")
# activate via "/todo ... "
# commands:
# /todo add [desc] [date time]
# /todo display (in n)
# /tdo
# -------------------------------
@client.command()
async def todo(ctx, *arg):
author = ctx.message.author
# need to get all the string
todo_string = makeString(arg)
print(author)
if arg[0] == "add":
addToDo(todo_string, author)
await ctx.send("added!")
elif arg[0] == "display":
await ctx.send("displaying...")
# temporariry display them like this
for item in db[author]:
await ctx.send("%s" % item)
elif arg[0] == "remove":
remove(arg, author)
else:
await ctx.send("something else")
# -------------------
# remove
def remove(arg, author):
list_todo = db[author]
# remove all todo list at that index
# super inefficient method
newlist = []
removeIndices = arg[1:] # indexes to remove
for i in range(0, len(list_todo)):
if (i + 1) not in removeIndices:
newlist.append(list_todo[i])
db[author] = newlist # new list with removed indices
# -------------
# concatenate all the parameter
def makeString(arg):
s = arg[1]
for i in range(2, len(arg)):
s += " " + arg[i]
return s
# ----------------------
# add msg to the db written by author
#
# ----------------------
def addToDo(msg, author):
if (author in db.keys()): # user exist
if {"name": msg} not in db[author]:
db[author].append({"name": msg})
else: # case: this is new person
db[author] = [{"name": msg}]
# -----------------------
# displays their current todo list
#
# -------------------
def display(author, ctx):
pass
def put
#just putting pass so it doesnt get syntax error
# thanks!
#client.run(os.getenv('TOKEN'))