Пример #1
0
async def unban_incident_scanner(ev: SigmaCommand, pld: UnbanPayload):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld:
    :type pld:
    """
    unban_entry = None
    now = arrow.utcnow().float_timestamp
    async for ali in pld.guild.audit_logs(limit=100,
                                          action=discord.AuditLogAction.unban):
        if ali.target.id == pld.user.id:
            kick_stamp = arrow.get(ali.created_at).float_timestamp
            if now - kick_stamp <= 5:
                unban_entry = ali
    if unban_entry:
        mod, reason = get_mod_and_reason(ev.bot, unban_entry, pld.guild)
        icore = get_incident_core(ev.db)
        incident = icore.generate('unban')
        incident.set_location(pld.guild)
        incident.set_moderator(mod)
        incident.set_target(unban_entry.target)
        if reason:
            incident.set_reason(reason)
        await icore.save(incident)
        incident_embed = incident.to_embed('🔨', 0x696969)
        await icore.report(pld.guild, incident_embed)
Пример #2
0
async def editincident(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        icore = get_incident_core(cmd.db)
        if len(pld.args) >= 2:
            lookup = pld.args[0]
            reason = ' '.join(pld.args[1:])
            incident = await icore.get_by_token(pld.msg.guild.id, lookup)
            if incident:
                if not len(reason) > 1000:
                    incident.edit(pld.msg.author, reason)
                    await icore.save(incident)
                    response = GenericResponse(
                        f'Incident {incident.id} updated.').ok()
                else:
                    response = GenericResponse(
                        'Reasons have a limit of 1000 characters.').error()
            else:
                response = GenericResponse(
                    'No incident with that ID was found.').error()
        else:
            response = GenericResponse('Invalid number of arguments.').error()
    else:
        response = GenericResponse(
            'Access Denied. Manage Messages needed.').denied()
    await pld.msg.channel.send(embed=response)
Пример #3
0
async def kick_incident_scanner(ev, pld):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.MemberPayload
    """
    kick_entry = None
    now = arrow.utcnow().float_timestamp
    async for ali in pld.member.guild.audit_logs(
            limit=100, action=discord.AuditLogAction.kick):
        if ali.target.id == pld.member.id:
            kick_stamp = arrow.get(ali.created_at).float_timestamp
            if now - kick_stamp <= 5:
                kick_entry = ali
    if kick_entry:
        mod, reason = get_mod_and_reason(ev.bot, kick_entry, pld.member.guild)
        icore = get_incident_core(ev.db)
        incident = icore.generate('kick')
        incident.set_location(pld.member.guild)
        incident.set_moderator(mod)
        incident.set_target(kick_entry.target)
        if reason:
            incident.set_reason(reason)
        await icore.save(incident)
        incident_embed = incident.to_embed('👢', 0xc1694f)
        await icore.report(pld.member.guild, incident_embed)
Пример #4
0
async def listincidents(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        icore = get_incident_core(cmd.db)
        identifier, incidents = None, None
        page = pld.args[-1] if len(pld.args) in [1, 3] else 1
        if len(pld.args) >= 2:
            identifier = pld.args[0].lower()
            if (pld.msg.mentions or identifier == 'variant') and identifier in identifiers:
                if identifier == 'moderator':
                    mod = pld.msg.mentions[0]
                    incidents = await icore.get_all_by_mod(pld.msg.guild.id, mod.id)
                    response = discord.Embed(color=0x226699)
                    incident_list, page = parse_incidents(incidents, page)
                    response.add_field(name=f'🗃️ Incidents initiated by {mod.name}', value=incident_list)
                elif identifier == 'target':
                    target = pld.msg.mentions[0]
                    incidents = await icore.get_all_by_target(pld.msg.guild.id, target.id)
                    response = discord.Embed(color=0x226699)
                    incident_list, page = parse_incidents(incidents, page)
                    response.add_field(name=f'🗃️ Incidents for {target.name}', value=incident_list)
                else:
                    variant = pld.args[1].lower()
                    if variant in variants:
                        incidents = await icore.get_all_by_variant(pld.msg.guild.id, variant)
                        response = discord.Embed(color=0x226699)
                        response.add_field(name='Details', value=f'```\nPage {page}\n```')
                        incident_list, page = parse_incidents(incidents, page)
                        response.add_field(name=f'🗃️ {identifier.title()} incidents', value=incident_list)
                    else:
                        response = GenericResponse('Invalid variant.').error()
            else:
                response = GenericResponse('Invalid identifier.').error()
        else:
            incidents = await icore.get_all(pld.msg.guild.id)
            response = discord.Embed(color=0x226699)
            incident_list, page = parse_incidents(incidents, page)
            response.add_field(name='🗃️ All incidents', value=incident_list)
        if not incidents and (identifier in identifiers or not identifier):
            if identifier:
                response = GenericResponse(f'No incidents found for that {identifier}.').error()
            else:
                response = GenericResponse('This server has no incidents.').error()
    else:
        response = GenericResponse('Access Denied. Manage Messages needed.').denied()
    await pld.msg.channel.send(embed=response)
Пример #5
0
async def make_incident(db, gld, ath, trg):
    """
    :type db: sigma.core.mechanics.database.Database
    :type gld: discord.Guild
    :type ath: discord.Member
    :type trg: discord.Member
    """
    icore = get_incident_core(db)
    inc = icore.generate('unwarn')
    inc.set_location(gld)
    inc.set_moderator(ath)
    inc.set_target(trg)
    await icore.save(inc)
    await icore.report(gld, inc.to_embed('âš ', 0xFFCC4D))
Пример #6
0
async def make_incident(db, gld, ath, trg, reason):
    """
    :type db: sigma.core.mechanics.database.Database
    :type gld: discord.Guild
    :type ath: discord.Member
    :type trg: discord.Member
    :type reason: str
    """
    icore = get_incident_core(db)
    inc = icore.generate('hardunmute')
    inc.set_location(gld)
    inc.set_moderator(ath)
    inc.set_target(trg)
    inc.set_reason(reason)
    await icore.save(inc)
    await icore.report(gld, inc.to_embed('🔊', 0x696969))
async def make_incident(db, pld, trg, action):
    """
    Makes and reports an incident for an Auto-Punishment.
    :type db: sigma.core.mechanics.database.Database
    :param pld:
    :type pld: sigma.core.mechanics.payload.CommandPayload
    :type trg: discord.Member
    :type action: str
    """
    icore = get_incident_core(db)
    incident = icore.generate(action)
    incident.set_location(pld.msg.guild)
    incident.set_moderator(pld.msg.author)
    incident.set_target(trg)
    incident.set_reason('Auto-Punished by Sigma')
    await icore.save(incident)
    icon = '🔊' if 'un' in action else '🔇'
    incident_embed = incident.to_embed(icon, 0x696969)
    await icore.report(pld.msg.guild, incident_embed)
Пример #8
0
async def make_incident(db: Database, gld: discord.Guild, ath: discord.Member,
                        trg: discord.Member):
    """

    :param db:
    :type db:
    :param gld:
    :type gld:
    :param ath:
    :type ath:
    :param trg:
    :type trg:
    """
    icore = get_incident_core(db)
    inc = icore.generate('unwarn')
    inc.set_location(gld)
    inc.set_moderator(ath)
    inc.set_target(trg)
    await icore.save(inc)
    await icore.report(gld, inc.to_embed('âš ', 0xFFCC4D))
Пример #9
0
async def viewincident(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        icore = get_incident_core(cmd.db)
        if len(pld.args) == 2:
            identifier = pld.args[0].lower()
            lookup = pld.args[1]
            if identifier in identifiers:
                if (identifier == 'order'
                        and lookup.isdigit()) or identifier == 'id':
                    if identifier == 'id':
                        incident = await icore.get_by_token(
                            pld.msg.guild.id, lookup)
                    else:
                        incident = await icore.get_by_order(
                            pld.msg.guild.id, int(lookup))
                    if incident:
                        icon, color = icons.get(incident.variant).values()
                        response = incident.to_embed(icon, color)
                    else:
                        response = GenericResponse(
                            f'No incident with that {identifier} found.'
                        ).error()
                else:
                    response = GenericResponse(
                        'Order must be a number.').error()
            else:
                response = GenericResponse('Invalid identifier.').error()
        else:
            response = GenericResponse('Invalid number of arguments.').error()
    else:
        response = GenericResponse(
            'Access Denied. Manage Messages needed.').denied()
    await pld.msg.channel.send(embed=response)
Пример #10
0
async def make_incident(db: Database, gld: discord.Guild, ath: discord.Member,
                        trg: discord.Member, reason: str):
    """

    :param db:
    :type db:
    :param gld:
    :type gld:
    :param ath:
    :type ath:
    :param trg:
    :type trg:
    :param reason:
    :type reason:
    """
    icore = get_incident_core(db)
    inc = icore.generate('hardunmute')
    inc.set_location(gld)
    inc.set_moderator(ath)
    inc.set_target(trg)
    inc.set_reason(reason)
    await icore.save(inc)
    await icore.report(gld, inc.to_embed('🔊', 0x696969))
Пример #11
0
async def exportincidents(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    file = None
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        if not Ongoing.is_ongoing(cmd.name, pld.msg.guild.id):
            Ongoing.set_ongoing(cmd.name, pld.msg.guild.id)
            icore = get_incident_core(cmd.db)
            response, target = None, None
            identifier, incidents = None, None
            title = '🗃️ Gathering all '
            if pld.args:
                if len(pld.args) == 2:
                    identifier = pld.args[0].lower()
                    if (pld.msg.mentions or identifier == 'variant') and identifier in identifiers:
                        if identifier == 'moderator':
                            target = pld.msg.mentions[0]
                            incidents = await icore.get_all_by_mod(pld.msg.guild.id, target.id)
                            title += f'incidents issued by {target.name}.'
                        elif identifier == 'target':
                            target = pld.msg.mentions[0]
                            incidents = await icore.get_all_by_target(pld.msg.guild.id, target.id)
                            title += f'incidents for {target.name}.'
                        else:
                            target = pld.args[1].lower()
                            if target in variants:
                                incidents = await icore.get_all_by_variant(pld.msg.guild.id, target)
                                title += f'{target} incidents.'
                            else:
                                response = GenericResponse('Invalid variant.').error()
                    else:
                        response = GenericResponse('Invalid identifier.').error()
            else:
                incidents = await icore.get_all(pld.msg.guild.id)
                title += 'incidents.'
            if not response:
                if incidents:
                    response = discord.Embed(color=0x226699, title=title)
                    response.set_footer(text='A text file will be sent to you shortly.')
                    if identifier:
                        modifier = f'{identifier.title()}: {target.title() if identifier == "variant" else target.name}'
                    else:
                        modifier = 'All'
                    file_name = make_export_file(pld.msg.guild.name, incidents, modifier)
                    file = discord.File(f'cache/{file_name}', file_name)
                else:
                    if identifier:
                        response = GenericResponse(f'No incidents found for that {identifier}.').error()
                    else:
                        response = GenericResponse('This server has no incidents.').error()
        else:
            response = GenericResponse('There is already one ongoing.').error()
    else:
        response = GenericResponse('Access Denied. Manage Messages needed.').denied()
    if Ongoing.is_ongoing(cmd.name, pld.msg.guild.id):
        Ongoing.del_ongoing(cmd.name, pld.msg.guild.id)
    await pld.msg.channel.send(embed=response)
    if file:
        try:
            await pld.msg.author.send(file=file)
        except (discord.NotFound, discord.Forbidden):
            denied_response = GenericResponse('I was unable to DM you, please adjust your settings.').error()
            await pld.msg.channel.send(pld.msg.author.mention, embed=denied_response)