Beispiel #1
0
 def schedule_next_challenge_announcement(self):
     if self.days_till_christmas:
         schedule(
             "beginnerpy-advent-of-code-2021",
             self.now + timedelta(days=1, minutes=1) - self.raw_now,
             self.send_daily_link,
             no_duplication=True,
         )
Beispiel #2
0
    async def rotate_available_channels(self, message: nextcord.Message):
        channel: nextcord.TextChannel = message.channel
        if channel.id not in self.available_channel_ids:
            return

        self.available_channel_ids.remove(channel.id)

        # Rotate next occupied channel into active
        next_channel = self.get_next_channel()
        await next_channel.send(embed=nextcord.Embed(
            description=
            "Feel free to ask any of your Python related questions in this channel!",
            color=GREEN,
        ).set_author(name="This Channel Is Available",
                     icon_url=self.server.icon.url))

        async with self.rotation_lock:
            current_bottom_available = self.available_category.channels[
                -1].position
            await next_channel.edit(
                category=self.available_category,
                position=current_bottom_available,
                sync_permissions=True,
            )
            self.available_channel_ids.append(next_channel.id)

            # Rotate active channel to occupied
            current_top_occupied = self.occupied_category.channels[0].position
            await channel.edit(
                category=self.occupied_category,
                position=current_top_occupied,
                sync_permissions=True,
            )

        author: nextcord.Member = message.author
        await author.add_roles(self.get_role("receiving_help"))
        schedule(
            "remove-help-role",
            datetime.timedelta(minutes=15),
            self.remove_help_role,
            author.id,
        )

        beginner = self.get_emoji("beginner")
        intermediate = self.get_emoji("intermediate")
        expert = self.get_emoji("expert")

        await channel.send(
            f"{author.mention} You've claimed this channel! Make sure to clearly ask your question and provide as many "
            f"details as you can *(code, errors, etc.)*, someone will try to help you when they get a chance.\n\nDon't "
            f"forget to give some kudos to show your appreciation by reacting with {beginner}, {intermediate}, or "
            f"{expert}!")
Beispiel #3
0
    async def mute(self, ctx, member: Member, duration, *, reason: str):
        if not (
            set(ctx.author.roles)
            & {self.get_role("jedi council"), self.get_role("mods")}
        ):
            return

        muted_role = utils.get(ctx.guild.roles, name="Muted")
        if muted_role in member.roles:
            await ctx.send(f"*{member.mention} is already muted*")
            return

        await member.add_roles(muted_role, reason="Mod Mute")

        minutes = self.parse_duration(duration)
        embed = self.build_mod_action_embed(
            ctx, member, reason, f"Muted for {self.format_duration(minutes)}"
        )
        message = await ctx.send(embed=embed)

        successfully_dmd = await self.send_dm(
            member, embed, ctx.message, "You've been muted on the Beginner.py server.\n"
        )
        if not successfully_dmd:
            reason += "\n*Unable to DM user*"

        await self.log_action(
            "MUTE",
            member,
            ctx.author,
            reason,
            message,
            Duration=self.format_duration(minutes),
        )

        schedule(
            "unmute-member", timedelta(minutes=minutes), self.unmute_member, member.id
        )

        self.save_action(
            "MUTE",
            member,
            ctx.author,
            message=reason,
            reference=message.id,
            link=message.jump_url,
        )
Beispiel #4
0
    async def sus(self, ctx: nextcord.ext.commands.Context):
        members = [ctx.author]
        if ctx.author.guild_permissions.manage_messages:
            members = ctx.message.mentions

        role = nextcord.utils.get(ctx.guild.roles, name="🚨sus🚨")
        for user in members:
            if isinstance(user, nextcord.Member):
                if role not in user.roles:
                    await user.add_roles(role)
                    schedule(
                        "remove-sus",
                        timedelta(days=1),
                        self.remove_sus,
                        user.id,
                        ctx.guild.id,
                    )
                await ctx.send(f"🚨 {user.mention} is sus 🚨")
Beispiel #5
0
    async def remind(self, ctx: nextcord.ext.commands.Context, duration: str,
                     *, message: str):
        minutes = 0
        hours = 0
        days = 0
        if duration.casefold().endswith("d"):
            days = int(duration[:-1])
        elif duration.casefold().endswith("h"):
            hours = int(duration[:-1])
        elif duration.casefold().endswith("m"):
            minutes = int(duration[:-1])
        elif duration.isdigit():
            minutes = int(duration)
        else:
            await ctx.send(
                f"{ctx.author.mention} durations must be of the format `123d`, `123h`, or `123m`/`123`.",
                delete_after=15,
            )
            return

        if minutes < 1 and hours < 1 and days < 1:
            await ctx.send(
                f"{ctx.author.mention} cannot set a reminder for less than a minute",
                delete_after=15,
            )
            return

        time_duration = datetime.timedelta(days=days,
                                           hours=hours,
                                           minutes=minutes)
        scheduled = schedule(
            f"reminder-{ctx.author.id}",
            time_duration,
            self.reminder_handler,
            message,
            ctx.message.id,
            ctx.channel.id,
        )
        if scheduled:
            await ctx.send(f"{ctx.author.mention} a reminder has been set",
                           delete_after=15)
        else:
            await ctx.send(
                f"{ctx.author.mention} you already have a reminder scheduled",
                delete_after=15,
            )
Beispiel #6
0
    async def bump_handler(self, ctx: nextcord.ext.commands.Context,
                           action: str):
        time_since = time() - self._last_bump_notice
        if not action.casefold() == "bump":
            return

        self.logger.info(
            f"{ctx.author} bumped after {time_since:0.3f} seconds")
        self.log_bump(f"Bumped", ctx.author)
        await ctx.send(f"🟢 {ctx.author.display_name} bumped", delete_after=10)

        async with self._bump_lock:
            if task_scheduled("disboard-bump-reminder"):
                await ctx.send(
                    embed=nextcord.Embed(
                        color=YELLOW,
                        description=
                        f"{ctx.author.mention} please wait until the next bump reminder",
                        title="Please Wait",
                    ),
                    delete_after=20,
                )
                self.log_bump(f"Bump already scheduled", ctx.author)
                return

            if not self.disboard.status == nextcord.Status.online:
                await ctx.send(embed=(nextcord.Embed(
                    color=RED,
                    description=
                    (f"Whoa {self.disboard.mention} appears to be offline right now! "
                     "I'll monitor the bump bot's status and notify everyone when it comes back online."
                     ),
                    title="Bump Failed - Offline",
                ).set_thumbnail(
                    url=
                    "https://cdn.discordapp.com/emojis/651959497698574338.png?v=1"
                )))
                self.log_bump("Bot is not online", ctx.author)
                return

            self.log_bump("Waiting for bump reminder", ctx.author)
            await ctx.send("Watching for the bump confirmation...",
                           delete_after=30)

            next_bump_timer = await self.get_next_bump_timer()

            next_bump = (timedelta(seconds=next_bump_timer)
                         if next_bump_timer > 0 else timedelta(hours=2))
            self.log_bump(
                f"Reminder set to go off in {':'.join(map(str, divmod(next_bump.total_seconds(), 60)))} (m:s)",
                ctx.author,
            )
            schedule("disboard-bump-reminder", next_bump, self.bump_reminder)
            await self.clear_channel()

            message = f"Successfully bumped!"
            thumbnail = "https://cdn.discordapp.com/emojis/711749954837807135.png?v=1"
            if next_bump.total_seconds() <= 7000:
                self.log_bump(
                    f"Server already bumped {next_bump.total_seconds()} <= 7000",
                    ctx.author,
                )
                message = f"Server was already bumped. {ctx.author.mention} try again at the next bump reminder."
            title = (f"Thanks {ctx.author.display_name}!"
                     if next_bump.total_seconds() > 7000 else "Already Bumped")
            color = BLUE if next_bump.total_seconds() > 7000 else YELLOW

            if next_bump_timer == -1:
                self.log_bump("Bump didn't go through", ctx.author)
                message = f"Bump did not go through. Try again in a little while."
                title = f"Bump Did Not Go Through"
                color = YELLOW
                thumbnail = (
                    "https://cdn.discordapp.com/emojis/651959497698574338.png?v=1"
                )

            next_bump_message = []
            next_bump_hour = int(next_bump.total_seconds() // 3600)
            next_bump_minutes = int(next_bump.total_seconds() // 60 % 60)
            if next_bump_hour > 0:
                next_bump_message.append(
                    f"{next_bump_hour} hour{'s' if next_bump_hour > 1 else ''}"
                )
            if next_bump_minutes > 0:
                next_bump_message.append(
                    f"{next_bump_minutes} minute{'s' if next_bump_minutes > 1 else ''}"
                )

            await ctx.send(embed=(nextcord.Embed(
                color=color,
                description=
                f"{message} Next bump in {' & '.join(next_bump_message)}",
                title=title,
                timestamp=datetime.utcnow() + next_bump,
            ).set_thumbnail(url=thumbnail).set_footer(text="Next bump")))
            self.log_bump(f"Next bump in {':'.join(next_bump_message)}",
                          ctx.author)

            if next_bump.total_seconds() > 7000:
                self.log_bump("Gave bump points", ctx.author)
                await self.award_points(ctx.message)