Ejemplo n.º 1
0
async def _add(ctx, user: User, reason: str, days: int = None):
    user.blacklisted_on.add(await ctx.db_guild,
                            properties={
                                'UTC': time.time(),
                                'reason': utils.escaped(reason),
                                'days': days,
                                'guild': ctx.guild.id
                            })

    await user.async_push()

    if days is not None:
        for_days = ctx.translate("for [days] days").format(days)
    else:
        for_days = ""

    conf_msg = ctx.translate("user blacklisted").format(for_days)

    member: discord.Member = ctx.guild.get_member(user.id)

    try:
        await member.send(
            ctx.translate("[user] just blacklisted you").format(
                str(ctx.author), str(ctx.guild), reason))
    except discord.Forbidden:
        warning_note = ctx.translate("but user doesn't allow direct messages")
        conf_msg = f"{conf_msg}\n{warning_note}"

    await ctx.send(conf_msg)
    await (await ctx.db_guild).log(
        ctx.translate("[user] blacklisted [user] [reason]").format(
            str(ctx.author), str(member), utils.escaped(reason)))
Ejemplo n.º 2
0
async def ban(ctx, user: User, reason: str, days: int = None):
    if user.id == ctx.guild.owner_id:
        raise InvalidAction("Guild owner cannot be banned.")

    db_ban = BanMixin()
    prepare_outlaw(db_ban, escaped(reason), user, ctx, days=days)
    graph.create(db_ban)

    if days is not None:
        for_days = ctx.translate("for [days] days").format(days)
    else:
        for_days = ""

    conf_msg = ctx.translate("user banned").format(for_days)

    member: discord.Member = ctx.guild.get_member(user.id)

    try:
        await member.send(
            ctx.translate("[user] just banned you").format(
                str(ctx.author), ctx.guild.name, for_days, escaped(reason)))
    except discord.Forbidden:
        warning_note = ctx.translate("but user doesn't allow direct messages")
        conf_msg = f"{conf_msg}\n{warning_note}"

    await member.ban(reason=reason, delete_message_days=1)

    UnbanTimer(ctx, days, member, reason=ctx.translate("ban time expired"))

    await ctx.send(conf_msg)
    await ctx.db_guild.log(
        ctx.translate(
            "[user] banned [user][for days] because of [reason]").format(
                str(ctx.author), str(member), for_days, db_ban.reason))
Ejemplo n.º 3
0
async def kick(ctx, user: User, reason: str):
    if user.id == ctx.guild.owner_id:
        raise InvalidAction("Guild owner cannot be kicked.")

    db_kick = KickMixin()
    prepare_outlaw(db_kick, escaped(reason), user, ctx)
    graph.create(db_kick)

    conf_msg = ctx.translate("user kicked")

    member: discord.Member = ctx.guild.get_member(user.id)

    try:
        await member.send(
            ctx.translate("[user] just kicked you").format(
                str(ctx.author), ctx.guild.name, escaped(reason)))
    except discord.Forbidden:
        warning_note = ctx.translate("but user doesn't allow direct messages")
        conf_msg = f"{conf_msg}\n{warning_note}"

    await member.kick(reason=reason)

    await ctx.send(conf_msg)
    await ctx.db_guild.log(
        ctx.translate("[user] kicked [user] because of [reason]").format(
            str(ctx.author), str(member), db_kick.reason))
Ejemplo n.º 4
0
async def _create(ctx, t: Ticket, content: str):
    """ This is to create new responses/to answer tickets. """

    if t.scope_enum == enums.Scope.CHANNEL and ctx.channel != t.channel and not ctx.may_fully_access(
            t):
        await ctx.send(ctx.translate("the related ticket is channel scope"))
        return None

    elif t.scope_enum == enums.Scope.PRIVATE and not ctx.may_fully_access(t):
        await ctx.send(ctx.translate("this is a private ticket"))
        return None

    elif t.state_enum == enums.State.CLOSED:
        await ctx.send(ctx.translate("this ticket is closed"))
        return None

    if t.scope_enum == enums.Scope.PRIVATE:
        try:
            await ctx.message.delete()
        except discord.Forbidden:
            pass

    utc = time.time()

    resp = Response()

    author = User.from_discord_user(ctx.author)
    resp.created_by.add(author, properties={'UTC': utc})

    resp.located_on.add(ctx.db_guild)

    resp.refers_to.add(t)

    resp.content = escaped(content)

    resp.deleted = False
    resp.updated = utc

    highest_id = graph.run(
        "MATCH (r:Response)-[:REFERS_TO]->(t:Ticket {uuid: '%s'}) RETURN max(r.id)"
        % t.uuid).evaluate()
    if highest_id is None:
        highest_id = 0

    resp.id = highest_id + 1
    resp.uuid = uuid.uuid4().hex

    graph.create(resp)

    await ctx.send(ctx.translate("response created").format(resp.full_id))

    resp_msg = ctx.translate(
        "[user] just responded to your ticket [ticket]").format(
            ctx.author.name, ctx.author.discriminator, t.id)

    await notify_author(ctx, resp_msg, t, embed=response_embed(ctx, resp))
    await resp.guild.log(
        ctx.translate("[user] created response [response]").format(
            ctx.author, f"{resp.ticket.id}-{resp.id}"))
Ejemplo n.º 5
0
async def report(ctx, user: User, reason: str):
    db_author: User = ctx.db_author

    if user in [r.affected_user for r in db_author.issued_reports]:
        await ctx.send(ctx.translate("you already reported this user"))
    elif db_author.id == user.id:
        await ctx.send(ctx.translate("you cannot report yourself"))
        return

    else:
        db_guild = ctx.db_guild

        report_node = ReportMixin()
        report_node.reason = escaped(reason)
        report_node.utc = time.time()
        report_node.uuid = uuid.uuid4().hex
        report_node.issued_on.add(db_guild)
        report_node.issued_by.add(db_author)
        report_node.applies_to.add(user)

        graph.create(report_node)

        await ctx.send(ctx.translate("user reported"))

        if len(user.reports) == 3:
            msg_addition = ctx.translate("user has been reported three times now")
        else:
            msg_addition = ""

        await notify_supporters(
            ctx.bot,
            ctx.translate("[user] reported [user] because of [reason]"
                          ).format(ctx.author, user.discord, escaped(reason)
                                   ) + msg_addition,
            db_guild
        )

        await db_guild.log(
            ctx.translate("[user] has been reported because of [reason]").format(user.discord, escaped(reason))
        )

    try:
        await ctx.message.delete()
    except discord.Forbidden:
        pass
Ejemplo n.º 6
0
def prepare_outlaw(ol, reason, user, ctx, **properties):
    setattr(ol, "uuid", uuid.uuid4().hex)
    setattr(ol, "utc", time.time())
    setattr(ol, "reason", escaped(reason))
    getattr(ol, "applies_to").add(user)
    getattr(ol, "executed_by").add(ctx.db_author)
    getattr(ol, "executed_on").add(ctx.db_guild)

    for p in properties:
        setattr(ol, p, properties[p])
Ejemplo n.º 7
0
async def warn(ctx, user: User, reason: str):
    db_warning = WarningMixin()
    prepare_outlaw(db_warning, escaped(reason), user, ctx)
    graph.create(db_warning)

    conf_msg = ctx.translate("user warned")

    member = ctx.guild.get_member(user.id)

    try:
        await member.send(
            ctx.translate("[user] just warned you").format(
                str(ctx.author), ctx.guild.name, escaped(reason)))
    except discord.Forbidden:
        warning_note = ctx.translate("but user doesn't allow direct messages")
        conf_msg = f"{conf_msg}\n{warning_note}"

    await ctx.send(conf_msg)
    await ctx.db_guild.log(
        ctx.translate("[user] warned [user] because of [reason]").format(
            str(ctx.author), str(member), db_warning.reason))
Ejemplo n.º 8
0
async def _edit(ctx, resp: Response, content: str):
    """ This is to edit a specific response. """

    if resp.author.id != ctx.author.id:
        await ctx.send(ctx.translate("you are not allowed to perform this action"))

    else:
        resp.updated = time.time()

        resp.content = escaped(content)

        await resp.async_push()

        await ctx.send(ctx.translate("response edited"))
        await resp.guild.log(ctx.translate("[user] edited response [response]").format(
            ctx.author, f"{resp.ticket.id}-{resp.id}"
        ))