Esempio n. 1
0
async def warn(ctx,
               musr: typing.Union[discord.Member, str] = None,
               *,
               reason: str = None):
    # Check if reason is None
    if reason is None:
        return await ctx.send("_🚫 Reason must be supplied!_")

    # Check if the musr object was properly parsed as a Member object
    if isinstance(musr, discord.Member):
        # ignore if self
        if ctx.author == musr:
            return

        # Fail if user is invincible
        if len([r for r in musr.roles if r.id in config.invincibleroles]) > 0:
            return await ctx.send("_🚫 You can't warn invincible users_")

        # Put it in the database
        db.AddInfraction(musr.id, Measure.WARN, reason, ctx.author.id)

        # Log it
        await log.log(
            bot,
            f"{musr.mention} was warned by {ctx.author.mention} with reason: {reason}",
            to_channel=True,
            footertxt=f"User ID: {musr.id}",
            color=COLOR.ATTENTION_WARN.value)

        # Send feedback
        await ctx.send(f"✅ {musr} was warned | {reason}")
    else:
        await ctx.send("🚫 Couldn't parse user properly")
Esempio n. 2
0
async def on_member_ban(guild, user):
    # Check if user was banned with a command (preventing duplicates)
    if user.id in bot.recentrmv:
        return

    # Get reason. Author cannot be tracked (is recorded as 0)
    ban = await guild.fetch_ban(user)
    reason = ban.reason

    # Put it in the database
    db.AddInfraction(user.id, Measure.BAN, reason, 0)

    await log.log(bot,
                  f"{user} was banned with reason: {reason}",
                  to_channel=True,
                  footertxt=f"User ID: {user.id}",
                  color=COLOR.ATTENTION_BAD.value)
Esempio n. 3
0
async def kick(ctx,
               musr: typing.Union[discord.Member, str] = None,
               *,
               reason: str = None):
    # Check if the musr object was properly parsed as a User object
    if isinstance(musr, discord.Member):

        # ignore if self
        if ctx.author == musr:
            return

        # Fail if user is invincible
        if (len([r
                 for r in musr.roles if r.id in config.invincibleroles]) > 0):
            await ctx.send("_🚫 You can't kick invincible users_")
            return

        # Put it in the database
        db.AddInfraction(musr.id, Measure.KICK, reason, ctx.author.id)
        report_infraction(
            bot, Infraction(musr.id, Measure.KICK, reason, ctx.author.id))

        # Add it to the recentrmv list
        bot.recentrmv.append(musr.id)

        await musr.send(f"You were kicked from {ctx.guild} • {reason}")

        # Use the hammer: Kick the user
        await ctx.guild.kick(musr, reason=reason)

        # Log it
        await log.log(
            bot,
            f"{musr} was kicked by {ctx.author} with reason: {reason}",
            to_channel=True,
            footertxt=f"User ID: {musr.id}",
            color=COLOR.ATTENTION_BAD.value)

        # Send feedback
        await ctx.send(f"✅ {musr} was kicked | {reason}")
    else:
        await ctx.send("🚫 Couldn't parse user properly")
Esempio n. 4
0
async def mute(ctx,
               musr: typing.Union[discord.Member, str] = None,
               duration: str = "30m",
               *,
               reason: str = "No reason supplied"):
    # Check if the musr object was properly parsed as a User object
    if isinstance(musr, discord.Member):
        # ignore if self
        if ctx.author == musr:
            return

        alts = db.GetAlts(musr.id)

        # Fail if user is invincible:
        if (len([r
                 for r in musr.roles if r.id in config.invincibleroles]) > 0):
            await ctx.send("_🚫 You can't mute invincible users_")
            return

        alts = db.GetAlts(musr.id)

        # Fail if user is invincible:
        if len([r for r in musr.roles if r.id in config.invincibleroles]) > 0:
            return await ctx.send("_🚫 You can't mute invincible users_")

        # Put it in the database
        db.AddInfraction(musr.id, Measure.MUTE, reason, ctx.author.id)

        # Try to get the role
        mr = ctx.guild.get_role(config.mutedrole)

        # Bot couldn't find the correct role
        if mr is None:
            raise errors.RoleNotFoundError("Muted role not found!",
                                           "Update ID in config file")

        try:
            ti = markdown.add_time_from_str(duration)
            db.SetMuteMember(musr.id, ti)
        except TypeError:
            return await ctx.send("Wrong formatting used!")

        # Assign the muted role
        await musr.add_roles(mr, reason=reason)

        await musr.send(
            f"You were muted in {ctx.guild} for {markdown.duration_to_text(duration)} • {reason}"
        )

        # Log it
        await log.log(
            bot,
            f"{musr} was muted by {ctx.author} with reason: {reason}",
            to_channel=True,
            footertxt=f"User ID: {musr.id}",
            color=COLOR.ATTENTION_BAD.value)

        # Send feedback
        await ctx.send(
            f"✅ {musr} was muted for {markdown.duration_to_text(duration)} | {reason}"
        )
    else:
        await ctx.send("🚫 Couldn't parse user properly")