-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncLibrary.py
297 lines (242 loc) · 11.2 KB
/
FuncLibrary.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
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
import nextcord
import nextcord.ext
from datetime import timedelta, date, datetime
import sqlite3
import Buttons
import covid_despair
Itemfile = "ItemFiles.db"
database = sqlite3.connect(Itemfile, timeout=10)
cs = database.cursor()
weekdays = ["Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag", # es git vor datetime-library ä command wo tuet dr wuchetag vomne datum zrüggäh,
"Sonntag"] # allerdings nur aus integer. Ds isch für ds formatting.
StP_colors = {"deutsch":0xffdd00,
"geschichte":0xcc8904,
"englisch":0xff0011,
"math":0x097dd6,
"franz":0x09a6d6,
"physik":0x2847ad,
"bio":0x0eab25,
"chemie":0x48fac2,
"sport":0x821705,
"mint":0xe1e2eb,
"musik":0x1bd18e,
"bg":0x9f11c2,
"sf physik": 0x041859,
"sf am": 0x5e0303,
"sf Bio":0x06701d,
"sf Chemie":0x08d134,
"sf Wirtschaft": 0xe01094,
"sf Recht": 0xe010cf,
"sf pp":0xf72fc9,
"ef musik":0xdbce14,
"ef geschichte":0xa85507,
"ef info":0x10e0c5,
"ef pp":0xe0103a,
"ef philo":0xb80b6a,
}
def get_access_permissions(author):
try:
ef = "all"
sf = "all"
kf = "all"
mint = "all"
for role in author.roles:
if role.name.lower().startswith("ef"):
ef = role.name
elif role.name.lower().startswith("sf"):
sf = role.name
elif role.name.lower().startswith("kf"):
kf = role.name
elif role.name.lower().startswith("mint"):
mint = role.name
except AttributeError: # für DM-modus
perm = cs.execute(f"SELECT sf, ef, kf, mint FROm briefing WHERE user_id = {author.id}").fetchall()
if perm:
sf = perm[0][0]
ef = perm[0][1]
kf = perm[0][2]
mint = perm[0][3]
else:
sf = "all"
ef = "all"
kf = "all"
mint = "all"
return sf, ef, kf, mint
def changefachname(fach): # so isches übersichtlecher
fach = fach.capitalize()
if fach == "Französisch":
fach = "Franz"
elif fach == 'Englisch':
fach = 'English'
elif fach == 'Biologie':
fach = 'Bio'
elif fach == 'Geschichte':
fach = 'History'
return fach
def layout(items, footer):
i = 1
today = False
tmrw = False
week_1 = False
week_2 = False
month_1 = False
month_2 = False
future = False
output = nextcord.Embed()
for item in items:
(year, month, day) = item[0].split("-")
itemdate = date(int(year), int(month), int(day))
if itemdate==date.today() and not today:
zeit = date.today()
output.add_field(name="__HEUTE:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})",
inline=False)
today = True
elif itemdate==date.today()+timedelta(1) and not tmrw:
zeit = date.today()+timedelta(1)
output.add_field(name="__MORGEN:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})",
inline=False)
tmrw = True
# week_1 teschtet öb ds scho isch vergäh worde, wenn nid de machter das häre
elif date.today()+timedelta(1)< itemdate <= date.today() + timedelta(7) and not week_1:
zeit = date.today() + timedelta(7)
output.add_field(name="__\nBIS NÄCHSTE WOCHE:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})",
inline=False)
week_1 = True
elif date.today() + timedelta(7) <= itemdate <= date.today() + timedelta(14) and not week_2:
zeit = date.today() + timedelta(14)
output.add_field(name="__\nNÄCHSTE 2 WOCHEN:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})", inline=False)
week_2 = True
elif date.today() + timedelta(14) < itemdate <= date.today() + timedelta(30) and not month_1:
zeit = date.today() + timedelta(30)
output.add_field(name="__\nINNERHALB VON 30 TAGEN:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})", inline=False)
month_1 = True
elif date.today() + timedelta(30) < itemdate <= date.today() + timedelta(60) and not month_2:
zeit = date.today() + timedelta(60)
output.add_field(name="__\nINNERHALB VON 60 TAGEN:__",
value=f"(Bis zum {zeit.day}.{zeit.month}.{zeit.year})", inline=False)
month_2 = True
elif date.today() + timedelta(60) < itemdate and not future:
lastitem = items[-1][0].split("-")
output.add_field(name="__\nSPÄTER ALS 60 TAGE:__",
value=f"(Bis zum {date(int(lastitem[0]), int(lastitem[1]), int(lastitem[2]))})", inline=False)
future = True
desc = item[3]
if not desc: # Wenn man keine Lernziele angegeben hat, dann ist desc=None.
desc = "Keine Lernziele"
elif len(desc) > 30:
desc = item[3][:30]+"..." # wöu schüsch chasch du lernziele ha wo viu ds läng si.
output.add_field(name=f"{i}: {item[1].capitalize()} {item[2]}",
value=f" {str(weekdays[itemdate.weekday()])}, "
f"{day}.{month}.{year}\n {desc}\n ",
inline=False)
output.set_footer(text=footer)
i+=1
return output
def outputbriefing(user, ef, sf, kf, mint):
output = nextcord.Embed(title=f"{weekdays[date.today().weekday()]}, "
f"{date.today().day}.{date.today().month}.{str(date.today().year)[2:]} "
f"({datetime.now().hour}:{datetime.now().minute:02})")
timeset = date.today()+timedelta(days=7)
items = cs.execute(f"SELECT * FROM items WHERE datum <= ? AND (access = 'all' " \
f"OR access = ? OR access = ? " \
f"OR access = ? OR access = ?) ORDER BY datum",
(timeset, user.id, sf, ef, kf)).fetchall()
output.add_field(name="AUFGABEN UND TESTS DIESE WOCHE:",
value=f"(Bis {timeset.day}.{timeset.month}.{timeset.year})", inline=False)
if items:
for item in items:
desc = item[3]
if not desc: # Wenn man keine Lernziele angegeben hat, dann ist desc=None.
desc = "Keine Lernziele"
elif len(desc) > 20:
desc = item[3][:20] + "..." # wöu schüsch chasch du lernziele ha wo viu ds läng si.
(year, month, day) = item[0].split("-")
itemdate = date(int(year), int(month), int(day))
output.add_field(name=f" {item[1].capitalize()} {item[2]}",
value=f" {str(weekdays[itemdate.weekday()])}, "
f"{day}.{month}.{year}\n {desc}\n ",
inline=False)
else:
output.add_field(name="Es ist nichts zu tun", value="Du kannst mit !new etwas hinzufügen.", inline=False)
currdate = (datetime.now()+timedelta(hours=24-17)).date()
tag = currdate.weekday()
wochentage = ["Mo", "Di", "Mi", "Do", "Fr"]
if tag > 4:
tag = (currdate + (timedelta(7) - timedelta(tag))).weekday() # tag wird ufe mänti gsetzt
output.add_field(name=".", value="**DER STUNDENPLAN VON MONTAG:**")
elif currdate == date.today():
output.add_field(name=".", value="**DER STUNDENPLAN VON HEUTE:**")
else:
output.add_field(name=".", value="**DER STUNDENPLAN VON MORGEN**")
allitems = cs.execute(f"SELECT fach, time, room FROM Stundenplan_23b WHERE weekday = ?" \
" AND (access='all' OR access = ? OR access = ? OR access = ? OR access=?)", \
(wochentage[tag], ef, sf, kf, mint)).fetchall()
allitems.sort(key=lambda elem: elem[1])
for i in allitems:
output.add_field(name=i[0], value=f"{i[1]}\n{i[2]}", inline=False)
return output
async def covid_embed(channel, delete_after):
now = datetime.utcnow() + timedelta(hours=2)
output = await channel.send("Get covid data...")
all_data = list(i for i in covid_despair.get_cases())
await output.edit(content="Get graph...")
then = datetime.now()
graph_name = covid_despair.get_graph()
collapse = False
while then + timedelta(seconds=delete_after) > datetime.now():
await output.delete()
if not collapse:
buttons = nextcord.ui.View(timeout=600)
collapse_btn = Buttons.CollapseBtn()
buttons.add_item(nextcord.ui.Button(label="Source [1]",
url="https://www.covid19.admin.ch/de/overview"))
buttons.add_item(nextcord.ui.Button(label="Source [2]\n",
url="https://www.worldometers.info/coronavirus/"))
buttons.add_item(collapse_btn)
embed = nextcord.Embed(title="+++COVID-NEWS+++", description=f"Stand {all_data[8]}", color=0xfff700) \
.add_field(name="SCHWEIZ:", value=f"**Cases**: {all_data[0]} [2] "
f"(+{all_data[2]} [1])\n"
f"**Tode:**: {all_data[1]} [2] "
f"(+{all_data[3]} [1])", inline=False) \
.add_field(name="WELTWEIT:", value=f"**Cases**: {all_data[4]} [2] "
f"(+{all_data[6]} [2])\n"
f"**Tode:**: {all_data[5]} [2] "
f"(+{all_data[7]} [2])", inline=False) \
.set_image(url=f"attachment://{graph_name}")
output = await channel.send(content=None, embed=embed, view=buttons, file=nextcord.File(graph_name))
await buttons.wait()
collapse = True
else:
buttons = nextcord.ui.View(timeout=delete_after)
collapse_btn = Buttons.CollapseBtn()
collapse_btn.label = "Ausklappen"
buttons.add_item(collapse_btn)
output = await channel.send(content=f"COVID Stats (aufgerufen am {now.day}.{now.month}. um {now.hour}:{now.minute})", view=buttons)
await buttons.wait()
collapse = not collapse_btn.collapse
def get_channel(guild:nextcord.Guild, name) -> nextcord.TextChannel | None:
for i in guild.channels:
if i.name == name and type(i) == nextcord.TextChannel:
return i
return None
def linebreaks(string:str, n:int)->str:
out = []
elem = string.split(" ")[0]
for i in string.split(" ")[1:]:
if len(elem) + len(i) + len(" ") > n:
out.append(elem)
elem = i
else:
elem += " "+i
out.append(elem)
return "\n".join(out)