<commit_before>
import discord
from discord.ext import commands

from typing import Optional

from modules import utilities
from utilities import checks

def setup(bot):
	bot.add_cog(Permissions(bot))

class Permissions(commands.Cog):
	
	def __init__(self, bot):
		self.bot = bot
		
		self.bot.loop.create_task(self.initialize_database())
	
	async def initialize_database(self):
		await self.bot.connect_to_database()
		await self.bot.db.execute("CREATE SCHEMA IF NOT EXISTS permissions")
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.everyone (
				guild_id		BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, permission)
			)
			"""
		)
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.roles (
				guild_id		BIGINT, 
				role_id			BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, role_id, permission)
			)
			"""
		)
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.users (
				guild_id		BIGINT, 
				user_id			BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, user_id, permission)
			)
			"""
		)
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@checks.is_permitted()
	async def setpermission(self, ctx):
		'''Set a permission'''
		await ctx.send_help(ctx.command)
	
	@setpermission.command(name = "everyone")
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_everyone(self, ctx, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.everyone (guild_id, permission, setting)
			VALUES ($1, $2, $3)
			ON CONFLICT (guild_id, permission) DO
			UPDATE SET setting = $3
			""", 
			ctx.guild.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for everyone", 
								title = "Permission Updated")
	
	@setpermission.command(name = "role")
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_role(self, ctx, role: discord.Role, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.roles (guild_id, role_id, permission, setting)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (guild_id, role_id, permission) DO
			UPDATE SET setting = $4
			""", 
			ctx.guild.id, role.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for the role, {role.mention}", 
								title = "Permission Updated")
	
	@setpermission.command(name = "user", aliases = ["member"])
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_user(self, ctx, user: discord.Member, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.users (guild_id, user_id, permission, setting)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (guild_id, user_id, permission) DO
			UPDATE SET setting = $4
			""", 
			ctx.guild.id, user.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for {user.mention}", 
								title = "Permission Updated")
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission(self, ctx, user: Optional[discord.Member], permission: Optional[str]):
		'''Get a permission'''
		if user and permission:
			await ctx.invoke(self.getpermission_user, user, permission)
		else:
			await ctx.send_help(ctx.command)
	
	@getpermission.command(name = "everyone")
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_everyone(self, ctx, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, type = "everyone")
		await ctx.embed_reply(f"{permission} is set to {setting} for everyone")
	
	@getpermission.command(name = "role")
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_role(self, ctx, role: discord.Role, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, 
											type = "role", id = role.id)
		await ctx.embed_reply(f"{permission} is set to {setting} for the role, {role.mention}")
	
	@getpermission.command(name = "user", aliases = ["member"])
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_user(self, ctx, user: discord.Member, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, id = user.id)
		await ctx.embed_reply(f"{permission} is set to {setting} for {user}")
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@checks.is_permitted()
	async def getpermissions(self, ctx):<commit_msg>[Discord] Improve getpermission user command response<commit_after>
import discord
from discord.ext import commands

from typing import Optional

from modules import utilities
from utilities import checks

def setup(bot):
	bot.add_cog(Permissions(bot))

class Permissions(commands.Cog):
	
	def __init__(self, bot):
		self.bot = bot
		
		self.bot.loop.create_task(self.initialize_database())
	
	async def initialize_database(self):
		await self.bot.connect_to_database()
		await self.bot.db.execute("CREATE SCHEMA IF NOT EXISTS permissions")
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.everyone (
				guild_id		BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, permission)
			)
			"""
		)
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.roles (
				guild_id		BIGINT, 
				role_id			BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, role_id, permission)
			)
			"""
		)
		await self.bot.db.execute(
			"""
			CREATE TABLE IF NOT EXISTS permissions.users (
				guild_id		BIGINT, 
				user_id			BIGINT, 
				permission		TEXT, 
				setting			BOOL, 
				PRIMARY KEY		(guild_id, user_id, permission)
			)
			"""
		)
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@checks.is_permitted()
	async def setpermission(self, ctx):
		'''Set a permission'''
		await ctx.send_help(ctx.command)
	
	@setpermission.command(name = "everyone")
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_everyone(self, ctx, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.everyone (guild_id, permission, setting)
			VALUES ($1, $2, $3)
			ON CONFLICT (guild_id, permission) DO
			UPDATE SET setting = $3
			""", 
			ctx.guild.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for everyone", 
								title = "Permission Updated")
	
	@setpermission.command(name = "role")
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_role(self, ctx, role: discord.Role, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.roles (guild_id, role_id, permission, setting)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (guild_id, role_id, permission) DO
			UPDATE SET setting = $4
			""", 
			ctx.guild.id, role.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for the role, {role.mention}", 
								title = "Permission Updated")
	
	@setpermission.command(name = "user", aliases = ["member"])
	@commands.guild_only()
	@checks.is_permitted()
	async def setpermission_user(self, ctx, user: discord.Member, permission: str, setting: Optional[bool]):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		await self.bot.db.execute(
			"""
			INSERT INTO permissions.users (guild_id, user_id, permission, setting)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (guild_id, user_id, permission) DO
			UPDATE SET setting = $4
			""", 
			ctx.guild.id, user.id, self.bot.all_commands[permission].name, setting
		)
		await ctx.embed_reply(f"{permission} set to {setting} for {user.mention}", 
								title = "Permission Updated")
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission(self, ctx, user: Optional[discord.Member], permission: Optional[str]):
		'''Get a permission'''
		if user and permission:
			await ctx.invoke(self.getpermission_user, user, permission)
		else:
			await ctx.send_help(ctx.command)
	
	@getpermission.command(name = "everyone")
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_everyone(self, ctx, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, type = "everyone")
		await ctx.embed_reply(f"{permission} is set to {setting} for everyone")
	
	@getpermission.command(name = "role")
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_role(self, ctx, role: discord.Role, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, 
											type = "role", id = role.id)
		await ctx.embed_reply(f"{permission} is set to {setting} for the role, {role.mention}")
	
	@getpermission.command(name = "user", aliases = ["member"])
	@commands.guild_only()
	@checks.is_permitted()
	async def getpermission_user(self, ctx, user: discord.Member, permission: str):
		if permission not in self.bot.all_commands:
			return await ctx.embed_reply(f"Error: {permission} is not a command")
		setting = await ctx.get_permission(self.bot.all_commands[permission].name, id = user.id)
		await ctx.embed_reply(f"{permission} is set to {setting} for {user.mention}")
	
	@commands.group(invoke_without_command = True, case_insensitive = True)
	@checks.is_permitted()
	async def getpermissions(self, ctx):
{'fraction_non_alphanumeric': 0.12135218415805692, 'fraction_numerical': 0.0025376110204821463, 'mean_word_length': 4.312951372171401, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '211879', 'n_tokens_mistral': 4144, 'n_tokens_neox': 3679, 'n_words': 932}