-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimetable.py
More file actions
297 lines (278 loc) · 11.3 KB
/
Copy pathtimetable.py
File metadata and controls
297 lines (278 loc) · 11.3 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
"""
Copyright (C) 2021 Berat Gökgöz
This file is a part of Timetable project.
Timetable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any
later version.
Timetable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import asyncio
import pandas as pd
import discord
import re
import json
botUserId = "789202881336311849"
ownerId = 754327007331876945
timeregex = r'(([01]\d)|(\d)|(2[0123]))[:.]([012345]\d)'
async def timetable(ctx,bot,db,runTimetable):
lang = db.getLang(ctx.guild.id)
f = open("./languages/"+lang+".json", 'r')
strings = json.load(f)
f.close()
strings = strings["timetable"]
ttembed=discord.Embed(title=strings[0], description=strings[1], colour=0xACB6C4)
ttembed.set_image(url="https://i.ibb.co/pRBftnx/unknown.png")
await ctx.channel.send(embed=ttembed)
try:
ttLessontimes = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if ttLessontimes.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
checkLessonTimes = list(map(
lambda x: re.search(timeregex, x.strip()),
ttLessontimes.content.lower().split(',')
))
if None in checkLessonTimes:
await ctx.channel.send(strings[5])
return
ttLessontimes = ttLessontimes.content.replace(':', '_').replace('.', '_').split(",")
ttLessontimes = list(map(lambda x: x.strip(), ttLessontimes))
await ctx.channel.send(strings[6])
try:
monday = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if monday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if monday.content.lower() == "nope":
monday = len(ttLessontimes)*["nope"]
else:
monday = monday.content.split(",")
monday = list(map(lambda x: x.strip(), monday))
if len(monday) > len(ttLessontimes):
monday = monday[:len(ttLessontimes)]
elif len(monday) < len(ttLessontimes):
while len(monday) < len(ttLessontimes):
monday.append("nope")
else:
pass
monday = pd.DataFrame([monday], columns=ttLessontimes)
await ctx.channel.send(strings[7])
try:
tuesday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if tuesday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if tuesday.content.lower() == "nope":
tuesday = len(ttLessontimes)*["nope"]
else:
tuesday = tuesday.content.split(",")
tuesday = list(map(lambda x: x.strip(), tuesday))
if len(tuesday) > len(ttLessontimes):
tuesday = tuesday[:len(ttLessontimes)]
elif len(tuesday) < len(ttLessontimes):
while len(tuesday) < len(ttLessontimes):
tuesday.append("nope")
else:
pass
tuesday = pd.DataFrame([tuesday], columns=ttLessontimes)
await ctx.channel.send(strings[8])
try:
wednesday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if wednesday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if wednesday.content.lower() == "nope":
wednesday = len(ttLessontimes) * ["nope"]
else:
wednesday = wednesday.content.split(",")
wednesday = list(map(lambda x: x.strip(), wednesday))
if len(wednesday) > len(ttLessontimes):
wednesday = wednesday[:len(ttLessontimes)]
elif len(wednesday) < len(ttLessontimes):
while len(wednesday) < len(ttLessontimes):
wednesday.append("nope")
else:
pass
wednesday = pd.DataFrame([wednesday], columns=ttLessontimes)
await ctx.channel.send(strings[9])
try:
thursday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if thursday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if thursday.content.lower() == "nope":
thursday = len(ttLessontimes) * ["nope"]
else:
thursday = thursday.content.split(",")
thursday = list(map(lambda x: x.strip(), thursday))
if len(thursday) > len(ttLessontimes):
thursday = thursday[:len(ttLessontimes)]
elif len(thursday) < len(ttLessontimes):
while len(thursday) < len(ttLessontimes):
thursday.append("nope")
else:
pass
thursday = pd.DataFrame([thursday], columns=ttLessontimes)
await ctx.channel.send(strings[10])
try:
friday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if friday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if friday.content.lower() == "nope":
friday = len(ttLessontimes) * ["nope"]
else:
friday = friday.content.split(",")
friday = list(map(lambda x: x.strip(), friday))
if len(friday) > len(ttLessontimes):
friday = friday[:len(ttLessontimes)]
elif len(friday) < len(ttLessontimes):
while len(friday) < len(ttLessontimes):
friday.append("nope")
else:
pass
friday = pd.DataFrame([friday], columns=ttLessontimes)
await ctx.channel.send(strings[11])
try:
saturday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if saturday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if saturday.content.lower() == "nope":
saturday = len(ttLessontimes) * ["nope"]
else:
saturday = saturday.content.split(",")
saturday = list(map(lambda x: x.strip(), saturday))
if len(saturday) > len(ttLessontimes):
saturday = saturday[:len(ttLessontimes)]
elif len(saturday) < len(ttLessontimes):
while len(saturday) < len(ttLessontimes):
saturday.append("nope")
else:
pass
saturday = pd.DataFrame([saturday], columns=ttLessontimes)
await ctx.channel.send(strings[12])
try:
sunday = await bot.wait_for('message', check = lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if sunday.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if sunday.content.lower() == "nope":
sunday = len(ttLessontimes) * ["nope"]
else:
sunday = sunday.content.split(",")
sunday = list(map(lambda x: x.strip(), sunday))
if len(sunday) > len(ttLessontimes):
sunday = sunday[:len(ttLessontimes)]
elif len(sunday) < len(ttLessontimes):
while len(sunday) < len(ttLessontimes):
sunday.append("nope")
else:
pass
sunday = pd.DataFrame([sunday], columns=ttLessontimes)
timetable = pd.concat([monday, tuesday, wednesday, thursday, friday, saturday, sunday], ignore_index=True)
print(timetable)
def formattime(time):
hour = str(time).split('_')[0]
minute = str(time).split('_')[1]
if len(hour) < 2:
hour = '0'+hour
if len(minute) < 2:
minute = '0'+minute
return hour+'_'+minute
timetable.columns = list(map(formattime, timetable.columns))
await ctx.channel.send(strings[13])
while True:
try:
notificationChannel = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if notificationChannel.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
notificationChannel = ' '.join(map(lambda x: x.strip('<').strip('>').strip('#'), notificationChannel.content.split()))
notificationChannel = re.search(r'(\d){18}', notificationChannel)
if notificationChannel == None:
await ctx.channel.send(strings[14])
continue
else:
notificationChannel = notificationChannel.group()
try:
testChannel = await bot.fetch_channel(notificationChannel)
testMsg = await testChannel.send("Test")
try:
await testMsg.delete()
except:
pass
break
except discord.Forbidden:
await ctx.channel.send(strings[15])
await ctx.channel.send(strings[16])
try:
getmention = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
if getmention.content.lower() in strings[3]:
await ctx.channel.send(strings[4])
return
if getmention.content.lower() == "nope":
mention=''
else:
mention = getmention.content
if mention.find("@everyone") > -1 or mention.find("@here") > -1:
await ctx.channel.send(strings[17])
return
await ctx.channel.send(strings[18])
try:
getpassword = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel,timeout=120)
except asyncio.TimeoutError:
await ctx.channel.send(strings[2])
return
password = getpassword.content.strip("||").strip()
try:
await getpassword.delete()
except:
await ctx.channel.send(strings[19])
try:
tableID = db.addTable(timetable, notificationChannel, password, mention)
except Exception as e:
await ctx.channel.send(strings[20].replace("{e}", str(e)))
await bot.get_channel(798954817459716106).send(f"An error has occured while creating a timetable: {e}")
return
ttTask = asyncio.create_task(runTimetable(tableID))
if ctx.author.dm_channel == None:
await ctx.author.create_dm()
await ctx.author.dm_channel.send(strings[21].replace("{tableID}", str(tableID)).replace("{password}",password))
await ttTask