async def voicekick(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).kick_members: target = get_broad_target(pld) if target: if cmd.bot.user.id != target.id: if pld.msg.author.id != target.id: above_hier = hierarchy_permit(pld.msg.author, target) is_admin = pld.msg.author.permissions_in( pld.msg.channel).administrator if above_hier or is_admin: above_me = hierarchy_permit(pld.msg.guild.me, target) if above_me: if target.voice: tvc = target.voice.channel tempvc = discord.utils.find( lambda x: x.name == 'Kick Hall', pld.msg.guild.channels) if not tempvc: tempvc = await pld.msg.guild.create_voice_channel( 'Kick Hall') await target.move_to(tempvc) await tempvc.delete() remove_title = f'👢 {target.name} has been removed from {tvc.name}.' response = discord.Embed(color=0xc1694f, title=remove_title) else: response = GenericResponse( f'{target.name} is not in a voice channel.' ).error() else: response = GenericResponse( 'Target is above my highest role.').denied() else: response = GenericResponse( 'Can\'t kick someone equal or above you.').denied( ) else: response = GenericResponse( 'You can\'t kick yourself.').error() else: response = GenericResponse('I can\'t kick myself.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse( 'Access Denied. Kick permissions needed.').denied() await pld.msg.channel.send(embed=response)
async def issuewarning(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.guild_permissions.manage_messages: target = get_broad_target(pld) if target: if target.id != pld.msg.author.id: if not target.bot: reason = ' '.join(pld.args[1:]) if pld.args[1:] else None warn_data = warning_data(pld.msg.author, target, reason) warn_iden = warn_data.get('warning').get('id') await cmd.db[cmd.db.db_nam].Warnings.insert_one(warn_data) response = GenericResponse( f'Warning {warn_iden} issued to {target.name}.').ok() await make_incident(cmd.db, pld.msg.guild, pld.msg.author, target, reason) log_embed = make_log_embed(pld.msg.author, target, warn_iden, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_warnings') await check_auto_punish(cmd, pld, target) guild_icon = str( pld.msg.guild.icon_url ) if pld.msg.guild.icon_url else discord.Embed.Empty to_target = discord.Embed(color=0xFFCC4D) to_target.add_field(name='âš You received a warning.', value=f'Reason: {reason}') to_target.set_footer(text=f'From {pld.msg.guild.name}', icon_url=guild_icon) # noinspection PyBroadException try: await target.send(embed=to_target) except Exception: pass else: response = GenericResponse('You can\'t warn bots.').error() else: response = GenericResponse('You can\'t warn yourself.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse( 'Access Denied. Manage Messages needed.').denied() await pld.msg.channel.send(embed=response)
async def kick(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).kick_members: target = get_broad_target(pld) if target: if cmd.bot.user.id != target.id: if pld.msg.author.id != target.id: above_hier = hierarchy_permit(pld.msg.author, target) is_admin = pld.msg.author.permissions_in(pld.msg.channel).administrator if above_hier or is_admin: above_me = hierarchy_permit(pld.msg.guild.me, target) if above_me: reason = ' '.join(pld.args[1:]) if pld.args[1:] else None response = discord.Embed(color=0xc1694f, title='👢 The user has been removed.') response_title = f'{target.name}#{target.discriminator}' response.set_author(name=response_title, icon_url=user_avatar(target)) to_target = discord.Embed(color=0xc1694f) to_target.add_field(name='👢 You have been kicked.', value=f'Reason: {reason}') guild_icon = str(pld.msg.guild.icon_url) if pld.msg.guild.icon_url else discord.Embed.Empty to_target.set_footer(text=f'From: {pld.msg.guild.name}.', icon_url=guild_icon) try: await target.send(embed=to_target) except discord.Forbidden: pass author = f'{pld.msg.author.name}#{pld.msg.author.discriminator}' await target.kick(reason=f'By {author}: {reason}') log_embed = generate_log_embed(pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_kicks') else: response = denied('Target is above my highest role.') else: response = denied('Can\'t kick someone equal or above you.') else: response = error('You can\'t kick yourself.') else: response = error('I can\'t kick myself.') else: response = error('No user targeted.') else: response = denied('Access Denied. Kick permissions needed.') await pld.msg.channel.send(embed=response)
async def hardunmute(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_channels: target = get_broad_target(pld) if target: hierarchy_me = hierarchy_permit(pld.msg.guild.me, target) if hierarchy_me: hierarchy_auth = hierarchy_permit(pld.msg.author, target) if hierarchy_auth: reason = ' '.join(pld.args[1:]) if pld.args[1:] else None await make_incident(cmd.db, pld.msg.guild, pld.msg.author, target, reason) ongoing = discord.Embed(color=0x696969, title='⛓ Editing permissions...') ongoing_msg = await pld.msg.channel.send(embed=ongoing) for channel in pld.msg.guild.channels: if isinstance(channel, discord.TextChannel) or isinstance( channel, discord.CategoryChannel): try: # noinspection PyTypeChecker await channel.set_permissions(target, overwrite=None, reason=reason) except discord.Forbidden: pass log_embed = generate_log_embed(pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_mutes') response = ok( f'{target.display_name} has been hard-unmuted.') await ongoing_msg.delete() else: response = error('That user is equal or above you.') else: response = error('I can\'t mute a user equal or above me.') else: response = error('No user targeted.') else: response = denied('Access Denied. Manage Channels needed.') await pld.msg.channel.send(embed=response)
async def hardmute(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_channels: target = get_broad_target(pld) if target: hierarchy_me = hierarchy_permit(pld.msg.guild.me, target) if hierarchy_me: hierarchy_auth = hierarchy_permit(pld.msg.author, target) if hierarchy_auth: ongoing = discord.Embed(color=0x696969, title='⛓ Editing permissions...') ongoing_msg = await pld.msg.channel.send(embed=ongoing) timed = pld.args[-1].startswith('--time=') try: now = arrow.utcnow().int_timestamp endstamp = now + convert_to_seconds(pld.args[-1].split('=')[-1]) if timed else None except (LookupError, ValueError): err_response = GenericResponse('Please use the format HH:MM:SS.').error() await pld.msg.channel.send(embed=err_response) return for channel in pld.msg.guild.channels: if isinstance(channel, discord.TextChannel) or isinstance(channel, discord.CategoryChannel): try: await channel.set_permissions(target, send_messages=False, add_reactions=False) except (discord.Forbidden, discord.NotFound): pass try: await ongoing_msg.delete() except discord.NotFound: pass rarg = pld.args[1:-1] if timed else pld.args[1:] if pld.args[1:] else None reason = ' '.join(rarg) if rarg else None await make_incident(cmd.db, pld.msg.guild, pld.msg.author, target, reason) log_embed = generate_log_embed(pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_mutes') response = GenericResponse(f'{target.display_name} has been hard-muted.').ok() guild_icon = str(pld.msg.guild.icon_url) if pld.msg.guild.icon_url else discord.Embed.Empty to_target_title = '🔇 You have been hard-muted.' to_target = discord.Embed(color=0x696969) to_target.add_field(name=to_target_title, value=f'Reason: {reason}') to_target.set_footer(text=f'On: {pld.msg.guild.name}', icon_url=guild_icon) try: await target.send(embed=to_target) except (discord.Forbidden, discord.HTTPException): pass if endstamp: doc_data = {'server_id': pld.msg.guild.id, 'user_id': target.id, 'time': endstamp} await cmd.db[cmd.db.db_nam].HardmuteClockworkDocs.insert_one(doc_data) else: response = GenericResponse('That user is equal or above you.').error() else: response = GenericResponse('I can\'t mute a user equal or above me.').error() else: response = GenericResponse('No user targeted.').error() else: response = GenericResponse('Access Denied. Manage Channels needed.').denied() await pld.msg.channel.send(embed=response)
async def ban(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).ban_members: target = get_broad_target(pld) if target: timed = pld.args[-1].startswith('--time=') try: now = arrow.utcnow().timestamp endstamp = now + convert_to_seconds( pld.args[-1].split('=')[-1]) if timed else None except (LookupError, ValueError): err_response = error('Please use the format HH:MM:SS.') await pld.msg.channel.send(embed=err_response) return if len(pld.args) >= 2: try: if endstamp: clean_days = int(pld.args[-2]) else: clean_days = int(pld.args[-1]) except ValueError: clean_days = 0 else: clean_days = 0 clean_days = clean_days if clean_days in [0, 1, 7] else 0 if cmd.bot.user.id != target.id: if pld.msg.author.id != target.id: above_hier = hierarchy_permit(pld.msg.author, target) is_admin = pld.msg.author.permissions_in( pld.msg.channel).administrator if above_hier or is_admin: above_me = hierarchy_permit(pld.msg.guild.me, target) if above_me: rarg = pld.args[1:-1] if timed else pld.args[ 1:] if pld.args[1:] else None reason = ' '.join(rarg) if rarg else None response = discord.Embed( color=0x696969, title='🔨 The user has been banned.') response_title = f'{target.name}#{target.discriminator}' response.set_author(name=response_title, icon_url=user_avatar(target)) guild_icon = str( pld.msg.guild.icon_url ) if pld.msg.guild.icon_url else discord.Embed.Empty to_target = discord.Embed(color=0x696969) to_target.add_field( name='🔨 You have been banned.', value=f'Reason: {reason}') to_target.set_footer( text=f'From: {pld.msg.guild.name}.', icon_url=guild_icon) try: await target.send(embed=to_target) except discord.Forbidden: pass audit_reason = f'By {pld.msg.author.name}#{pld.msg.author.discriminator}: {reason}' await target.ban(reason=audit_reason, delete_message_days=clean_days) log_embed = generate_log_embed( pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_bans') if endstamp: doc_data = { 'server_id': pld.msg.guild.id, 'user_id': target.id, 'time': endstamp } await cmd.db[ cmd.db.db_nam ].BanClockworkDocs.insert_one(doc_data) else: response = denied( 'Target is above my highest role.') else: response = denied( 'Can\'t ban someone equal or above you.') else: response = error('You can\'t ban yourself.') else: response = error('I can\'t ban myself.') else: response = error('No user targeted.') else: response = denied('Access Denied. Ban permissions needed.') await pld.msg.channel.send(embed=response)