Beispiel #1
0
    async def testLecture(self,
                          ctx,
                          semester=None,
                          day=None,
                          hour=None,
                          role_id=0):
        """
        Test the embed message for starting lectures
        Permissions: Owner
        """
        # Input/Error catching
        if day is None or hour is None:
            await ctx.reply(
                "ERROR! Not enough parameters. You need `<semester> <day> <hour> [role ID to ping]`."
            )
            raise discord.ext.commands.CommandError
        try:
            semester = int(semester)
            day = int(day)
            hour = int(hour)
        except ValueError:
            await ctx.reply(
                "ERROR! Semester, day and hour need to be integers.")
            raise discord.ext.commands.BadArgument

        subject: SQLFunctions.Subject = SQLFunctions.get_starting_subject(
            semester, self.conn, day, hour)
        if subject is None:
            await ctx.reply("No subject starting at that time.")
            return
        try:
            await self.send_lecture_start(
                subject_name=subject.name,
                website_url=subject.website_link,
                stream_url=subject.stream_link,
                channel_id=756391202546384927,  # lecture updates channel,
                role_id=role_id,
                zoom_url=subject.zoom_link,
                subject_room=subject.on_site_location)
        except Exception as e:
            await ctx.reply(f"ERROR! Can't send embed message:\n`{e}`")
Beispiel #2
0
    async def background_loop(self):
        await self.bot.wait_until_ready()
        try:
            # Find out what semesters are currently going on
            # Only works for the 3 bachelor years as of now
            month = datetime.now().month
            if 9 <= month <= 12:
                semesters = [1, 3, 5]
            elif 2 <= month <= 6:
                semesters = [2, 4, 6]
            else:
                print(
                    "No subjects going on right now. So skipping the loop completely."
                )
                return

            dt = datetime.now(timezone("Europe/Zurich"))
            minute = dt.minute
            day = dt.day

            # Check what lectures are starting
            for sem in semesters:
                if not self.sent_updates[sem] and minute <= 5:
                    role_id = 0
                    if sem in [1, 2]:
                        role_id = self.lecture_updates_role_ids["first"]
                    elif sem in [3, 4]:
                        role_id = self.lecture_updates_role_ids["second"]
                    elif sem in [5, 6]:
                        role_id = self.lecture_updates_role_ids["third"]
                    subject = SQLFunctions.get_starting_subject(
                        sem, self.conn, dt.weekday(), dt.hour)
                    if subject is not None:
                        await self.send_lecture_start(
                            subject_name=subject.name,
                            website_url=subject.website_link,
                            stream_url=subject.stream_link,
                            channel_id=
                            756391202546384927,  # lecture updates channel,
                            role_id=role_id,
                            zoom_url=subject.zoom_link,
                            subject_room=subject.on_site_location)
                        self.sent_updates[sem] = True
            if minute > 5:
                self.sent_updates = {
                    1: False,
                    2: False,
                    3: False,
                    4: False,
                    5: False,
                    6: False
                }

            if not self.sent_website_updates and minute % 10 == 0:
                exercise_update_channel = self.bot.get_channel(
                    756391202546384927)  # lecture updates channel
                if exercise_update_channel is None:
                    exercise_update_channel = self.bot.get_channel(
                        402563165247766528)  # channel on bot testing server
                if exercise_update_channel is not None:
                    await self.check_updates(exercise_update_channel,
                                             self.lecture_updater_version)
                self.sent_website_updates = True
            elif minute % 10 != 0:
                self.sent_website_updates = False

            # advent of code ping
            if minute > 5:
                self.sent_advent = False
            if month == 12 and not self.sent_advent and 1 <= day <= 25 and dt.hour == 6 and minute <= 5:
                channel = self.bot.get_channel(910450760234467328)
                msg = f"Good Morning! It's time for **Advent of Code** day #{day}!\n[*Click here to get to the challenge*](https://adventofcode.com/2021/day/{day})"
                msg += "\n||*Consider donating to AoC to have it continue next year again* <:Santawww:910435057607524352>||"
                embed = discord.Embed(description=msg,
                                      color=discord.Color.red())
                await channel.send("<@&910433615689699388>", embed=embed)
                self.sent_advent = True

        except AttributeError as e:
            print(
                f"ERROR in Lecture Updates Loop! Probably wrong channel ID | {e}"
            )
        except Exception:
            await asyncio.sleep(10)
            user = self.bot.get_user(self.bot.owner_id)
            await user.send(
                f"Error in background loop: {traceback.format_exc()}")
            log(
                f"Error in background loop self.bot.py: {traceback.format_exc()}",
                "BACKGROUND")