This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
/
toDoBot.py
129 lines (110 loc) · 4.13 KB
/
toDoBot.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
import discord
import asyncio
toDoDB = []
def channelDBManager(channel):
channelExists = False
for db in toDoDB:
if db[0] == channel:
channelExists = True
currentDB = db[1]
if not channelExists:
toDoDB.append([channel, []])
for db in toDoDB:
if db[0] == channel:
currentDB = db[1]
try:
return currentDB
except:
print("channeldbmanager fatal fail - exiting")
exit()
def newToDo(desc, channel):
db = channelDBManager(channel)
status = True
tempTodo = [desc, status]
db.append(tempTodo)
def doneToDo(id, channel):
db = channelDBManager(channel)
i = 0
success = False
for todo in db:
i += 1
if i == id:
success = True
tempI = i - 1
db.remove(db[tempI])
return success
def listToDo(channel):
db = channelDBManager(channel)
id = 0
returnList = []
for todo in db:
temptodo = []
for i in todo:
temptodo.append(i)
id += 1
temptodo.insert(0, id)
returnList.append(temptodo)
return returnList
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
channel = str(message.channel.id)
command = str(message.content)
if command.startswith("/"):
print(toDoDB)
if command.startswith("/add "):
command = command.replace("/add ", "")
if command == "":
await client.send_message(message.channel, ":x: No ToDo entered.")
print(":x: No ToDo entered.")
newToDo(command, channel)
await client.send_message(message.channel, ":white_check_mark: ToDo `" + command + "` added.")
print(":white_check_mark: ToDo '" + command + "' added.")
elif command == "/add":
await client.send_message(message.channel, ":x: Usage: `/add [TODO]`")
print(":x: Usage: `/add [TODO]`")
elif command == "/todo":
list = listToDo(channel)
printline = ""
for todo in list:
printline = printline + "**[" + str(todo[0]) + "]** - " + str(todo[1]) + "\n"
if printline == "":
printline = ":metal: **No ToDo's!** :metal:"
else:
printline = ":pencil: **ToDo's:** :pencil:\n\n" + printline
await client.send_message(message.channel, printline)
print(printline)
elif command.startswith("/done "):
command = command.replace("/done ", "")
try:
command = int(command)
except:
await client.send_message(message.channel, ':x: ID needs to be a number!')
print(":x: ID needs to be a number!")
return
success = doneToDo(command, channel)
if success:
await client.send_message(message.channel, ':white_check_mark: ToDo done.')
print(":white_check_mark: ToDo deleted")
else:
await client.send_message(message.channel, ':x: No ToDo with ID **' + str(command) + '**')
print(':x: No ToDo with ID **' + str(command) + '**')
elif command == "/done":
await client.send_message(message.channel, ":x: Usage: `/done [ID]`")
print(":x: Usage: `/done [ID]`")
elif command == "/help":
printline = "'/todo' - Show the current todo list.\n'/add [TODO]' - Add a new todo.\n'/done [ID]' - Mark a todo done (delete).\n'/help' - Show this menu.\nv1.0 by @xdavidhu"
printline = ":question: **Help menu:** :question:\n" + "```" + printline + "```"
await client.send_message(message.channel, printline)
print(printline)
elif command.startswith("/"):
printline = ":x: Command `" + command + "` not found. Type `/help` for the help menu."
await client.send_message(message.channel, printline)
print(printline)
client.run('YOUR-TOKEN-HERE')