コード例 #1
0
ファイル: school.py プロジェクト: niwla23/schoolbot
    async def plan_function(self, class_="9f", day=1):
        print(type(day))
        print(day)

        if day == 1:
            url = config["plan"]["day1URL"]
        elif day == 2:
            url = config["plan"]["day2URL"]
        else:
            return _("Day must be either 1 or 2")
        plan, date, week = iserv.get_untis_substitution_plan(url)

        text = _(":newspaper: **Substitution Plan**   |   ")
        text = text + f":family: {class_}   |   " \
                      f":calendar: {week}   |   " \
                      f":calendar_spiral: {date}\n\n"
        if class_ in plan.keys():
            for item in plan[class_]:
                time_emoji = time_to_emoji(
                    f"{random.randint(1, 12)}:{random.randint(0, 60)}")
                text = text + f"> {time_emoji} **{_('Lesson')} {item['time']}**\n" \
                              f"> :abc: {item['subject']}\n" \
                              f"> :green_square: {item['room']}\n" \
                              f"> :{random.choice(['man', 'woman'])}_teacher: {item['teacher']}\n" \
                              f"> :family: {item['course']}\n\n"
        else:
            text = text + "Nothing found."

        return text
コード例 #2
0
ファイル: school.py プロジェクト: niwla23/schoolbot
    async def check_tests(self):
        iserv.login()
        current_tests = iserv.get_next_tests()
        last_tests = tests_collection.find()
        last_tests_formatted = [{
            'date': i['date'],
            'time': i['time'],
            'class': i['class'],
            'subject': i['subject']
        } for i in last_tests]

        for test in current_tests:
            if test not in last_tests_formatted:
                print("new!")
                subject = test["subject"]
                date = test["date"]
                time = test["time"]
                time_emoji = time_to_emoji(time)
                course = test["class"]
                localized_announce = _('New test announced!')
                text = f"> **:pencil: {localized_announce} :pencil:**\n" \
                       f"> :abc: {subject}\n" \
                       f"> :calendar: {date}\n" \
                       f"> {time_emoji} {time}\n" \
                       f"> :family: {course}\n"
                await self.bot.get_channel(config["autoTests"]["channel"]
                                           ).send(text)
                tests_collection.insert_one(test)
        for test in last_tests_formatted:
            if test not in current_tests:
                tests_collection.delete_one(test)
                print("deleted!")
コード例 #3
0
ファイル: school.py プロジェクト: niwla23/schoolbot
 async def get_tests(self, ctx):
     iserv.login()
     tests = iserv.get_next_tests()
     text = _(":newspaper: **Tests**\n\n")
     for test in tests:
         text = text + f"**{test['date']}**\n:point_right: {test['subject']},\n"
     await ctx.send(text)
コード例 #4
0
ファイル: system.py プロジェクト: niwla23/schoolbot
 async def iserv_speedtest(self, ctx):
     message = await ctx.send("Testing login speed....")
     start_time = datetime.datetime.now()
     iserv.login()
     duration = datetime.datetime.now() - start_time
     await message.edit(content=_(
         "Logging into iserv took {seconds}.{microseconds} seconds."
     ).format(seconds=duration.seconds, microseconds=duration.microseconds))
コード例 #5
0
    async def on_command_error(self, ctx, error):
        err = getattr(error, "original", error)

        if isinstance(err, commands.CommandNotFound):
            await ctx.send(get_pre_mention(ctx,
                                           "dieses Kommando existiert nicht!"),
                           delete_after=5)
        elif isinstance(err, commands.CommandOnCooldown):
            await ctx.send(
                'Dieses Kommando hat einen Cooldown. Versuche es nochmal in {:.2f} Sekunden!'
                .format(error.retry_after))
        elif isinstance(err, commands.NoPrivateMessage):
            await ctx.send(get_pre_mention(
                ctx, _("command can not be used in DMs")),
                           delete_after=5)
        elif isinstance(err, commands.errors.MissingRequiredArgument):
            await ctx.send(
                get_pre_mention(
                    ctx,
                    _("the argument {0} is missing").format(
                        err.args[0].split(" ")[0])))
        elif isinstance(err, commands.errors.MissingPermissions):
            await ctx.send(
                get_pre_mention(
                    ctx,
                    _("you are missing these permissions: {0}").format(
                        ", ".join(err.missing_perms))))
        elif isinstance(err, commands.errors.MissingRole):
            await ctx.send(
                get_pre_mention(
                    ctx,
                    _("you are missing these permissions: {0}").format(
                        err.missing_role)))
        elif isinstance(err, commands.errors.BadArgument):
            await ctx.send(
                get_pre_mention(
                    ctx,
                    _("the argument {0} must be of type {1}").format(
                        err.args[0].split(" ")[-1][:-1],
                        err.args[0].split(" ")[2])))
        else:
            await ctx.send(_("an error occurred"))
            raise error
コード例 #6
0
ファイル: system.py プロジェクト: niwla23/schoolbot
 async def ping(self, ctx):
     await ctx.send(_("Pong!"))