def createEmbed(day, dayDatetime, semester, year, schedule): # Create a date object to check the current week startDate = 1612224000 currentTime = dayDatetime.timestamp() # TODO don't clamp because week 1 is calculated as week 0!! week = clamp( timeFormatters.timeIn(currentTime - startDate, "weeks")[0], 1, 13) # Compensate for easter holidays # Sorry but I don't have time to make a clean solution for this rn # this will have to do # Does -1 instead of -2 because weeks were 0-indexed all along week -= 1 title, week = getTitle(day, dayDatetime, week) # Add all courses & their corresponding times + locations of today courses, extras, prev, online = getCourses(schedule, day, week) embed = discord.Embed(colour=discord.Colour.blue(), title=title) embed.set_author(name="Lessenrooster voor {}{} Bachelor".format( year, "ste" if year == 1 else "de")) if len(courses) == 0: embed.add_field(name="Geen Les", value="Geen Les", inline=False) else: courseString = createCourseString(courses) # TODO uncomment this when covid rules slow down # courseString += "\nGroep {} heeft vandaag online les.".format(1 if week % 2 == 0 else 2) embed.description = courseString if prev: embed.add_field(name="Vakken uit vorige jaren", value=createCourseString(prev), inline=False) if extras: embed.add_field(name="Extra", value="\n".join( getExtras(extra) for extra in extras), inline=False) # Add online links - temporarily removed because everything is online right now if online: uniqueLinks: dict = getUniqueLinks(online) embed.add_field( name="Online Links", value="\n".join( sorted( getLinks(onlineClass, links) for onlineClass, links in uniqueLinks.items()))) embed.set_footer( text="Semester {} | Lesweek {}".format(semester, round(week))) return embed
async def age(self, ctx, specification=None): allowedSpecifications = ["d", "days", "m", "months", "w", "weeks", "y", "years"] if specification is not None and specification.lower() not in allowedSpecifications: await ctx.send("**{}** is geen geldig formaat.".format(specification)) return if specification is None: timeString = timeFormatters.diffYearBasisString(constants.creationDate) else: ageSeconds = round(time.time()) - constants.creationDate timeFormat = timeFormatters.getFormat(specification) timeString = str(timeFormatters.timeIn(ageSeconds, timeFormat)[0]) timeString += " " + timeFormatters.getPlural(int(timeString), timeFormat) await ctx.send("Didier is **{}** oud.".format(timeString))
async def les(self, ctx, *day): semester = int(config.get("semester")) year = int(config.get("year")) years_counter = int(config.get("years")) # Check if a schedule or a day was called if len(day) == 0: day = [] else: # Only either of them was passed if len(day) == 1: # Called a schedule if day[0].isdigit(): if 0 < int(day[0]) < years_counter + 1: year = int(day[0]) day = [] else: return await ctx.send("Dit is geen geldige jaargang.") # elif: calling a weekday is automatically handled below, # so checking is obsolete else: # Both were passed if day[0].isdigit(): if 0 < int(day[0]) < years_counter + 1: year = int(day[0]) day = [] else: return await ctx.send("Dit is geen geldige jaargang.") # Cut the schedule from the string day = day[1:] day = self.getWeekDay(None if len(day) == 0 else day)[1] dayDatetime = self.findDate(timeFormatters.weekdayToInt(day)) schedule = self.customizeSchedule(ctx, year, semester) # Create a date object to check the current week startDate = 1600041600 currentTime = dayDatetime.timestamp() week = clamp( timeFormatters.timeIn(currentTime - startDate, "weeks")[0], 1, 13) title, week = self.getTitle(day, dayDatetime, week) # Add all courses & their corresponding times + locations of today courses, extras, prev, online = self.getCourses(schedule, day, week) embed = discord.Embed(colour=discord.Colour.blue(), title=title) embed.set_author(name="Lessenrooster voor {}{} Bachelor".format( year, "ste" if year == 1 else "de")) if len(courses) == 0: embed.add_field(name="Geen Les", value="Geen Les", inline=False) else: courseString = self.createCourseString(courses) courseString += "\nGroep {} heeft vandaag online les.".format( 1 if week % 2 == 0 else 2) embed.description = courseString if prev: embed.add_field(name="Vakken uit vorige jaren", value=self.createCourseString(prev), inline=False) if extras: embed.add_field(name="Extra", value="\n".join( self.getExtras(extra) for extra in extras), inline=False) # Add online links if not commnet if online: embed.add_field(name="Online Links", value="\n".join( self.getLink(onlineClass) for onlineClass in online)) embed.set_footer( text="Semester {} | Lesweek {}".format(semester, round(week))) await ctx.send(embed=embed)