<commit_before>
import discord
from discord.ext import commands

from operator import attrgetter

from utilities import checks

async def setup(bot):
	await bot.add_cog(Role(bot))

class Role(commands.Cog):
	"""Role"""
	
	def __init__(self, bot):
		self.bot = bot
	
	async def cog_check(self, ctx):
		guild_only = await commands.guild_only().predicate(ctx)
		not_forbidden = await checks.not_forbidden().predicate(ctx)
		return guild_only and not_forbidden
	
	@commands.group(aliases = ["roles"], invoke_without_command = True, case_insensitive = True)
	async def role(self, ctx):
		"""Role"""
		await ctx.send_help(ctx.command)
	
	# TODO: check role hierarchy
	# TODO: reason options?
	
	@role.command(name = "color", aliases = ["colour"])
	async def role_color(self, ctx, role: discord.Role, *, color: discord.Color = None):
		'''The color of a role'''
		if color:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(color = color)
			await ctx.embed_reply(role.mention + " has been recolored")
		else:
			await ctx.embed_reply(role.mention + "'s color is {}".format(role.color))
	
	@role.command(name = "create", aliases = ["make", "new"])
	@commands.bot_has_guild_permissions(manage_roles = True)
	@commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner())
	async def role_create(self, ctx, *, name: str = ""):
		'''Creates a role'''
		# TODO: Add more options
		role = await ctx.guild.create_role(name = name)
		await ctx.embed_reply(role.mention + " created")
	
	@role.command(name = "default")
	async def role_default(self, ctx, *, role: discord.Role):
		'''Whether a role is the default role or not'''
		await ctx.embed_reply(role.mention + " is {}the default role".format("" if role.is_default() else "not "))
	
	@role.command(name = "hoisted", aliases = ["hoist"])
	async def role_hoisted(self, ctx, role: discord.Role, hoist: bool = None):
		'''Whether a role is displayed separately from other members or not'''
		if hoist is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(hoist = hoist)
			await ctx.embed_reply(role.mention + " has been {}hoisted".format("" if hoist else "un"))
		else:
			await ctx.embed_reply(role.mention + " is {}hoisted".format("" if role.hoist else "not "))
	
	@role.command(name = "id")
	async def role_id(self, ctx, *, role: discord.Role):
		'''The ID of a role'''
		await ctx.embed_reply(role.id)
	
	@role.command(name = "managed")
	async def role_managed(self, ctx, *, role: discord.Role):
		'''Indicates if the role is managed by the guild through some form of integrations such as Twitch'''
		await ctx.embed_reply(role.mention + " is {}managed".format("" if role.managed else "not "))
	
	@role.command(name = "mentionable")
	async def role_mentionable(self, ctx, role: discord.Role, mentionable: bool = None):
		'''Whether a role is mentionable or not'''
		if mentionable is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(mentionable = mentionable)
			await ctx.embed_reply(role.mention + " is now {}mentionable".format("" if mentionable else "not "))
		else:
			await ctx.embed_reply(role.mention + " is {}mentionable".format("" if role.mentionable else "not "))
	
	@role.command(name = "name")
	async def role_name(self, ctx, role: discord.Role, *, name: str = ""):
		'''The name of a role'''
		if name:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(name = name)
			await ctx.embed_reply(role.mention + " has been renamed")
		else:
			await ctx.embed_reply(role.name)
	
	@role.command(name = "position")
	async def role_position(self, ctx, role: discord.Role, position: int = None):
		'''
		The position of a role
		This number is usually positive
		The bottom role has a position of 0
		'''
		if position is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(position = position)
			await ctx.embed_reply(role.mention + "'s position has been set to {}".format(position))
		else:
			await ctx.embed_reply(role.mention + "'s position is {}".format(role.position))
	
	# TODO: move to server cog
	@role.command(name = "positions")
	async def role_positions(self, ctx):
		'''
		WIP
		Positions of roles in the server
		'''
		await ctx.embed_reply(', '.join("{}: {}".format(role.mention, role.position) for role in sorted(ctx.guild.roles[1:], key = attrgetter("position"), reverse = True)))

<commit_msg>[Discord] Improve command method names in Role cog<commit_after>
import discord
from discord.ext import commands

from operator import attrgetter

from utilities import checks

async def setup(bot):
	await bot.add_cog(Role(bot))

class Role(commands.Cog):
	"""Role"""
	
	def __init__(self, bot):
		self.bot = bot
	
	async def cog_check(self, ctx):
		guild_only = await commands.guild_only().predicate(ctx)
		not_forbidden = await checks.not_forbidden().predicate(ctx)
		return guild_only and not_forbidden
	
	@commands.group(aliases = ["roles"], invoke_without_command = True, case_insensitive = True)
	async def role(self, ctx):
		"""Role"""
		await ctx.send_help(ctx.command)
	
	# TODO: check role hierarchy
	# TODO: reason options?
	
	@role.command(aliases = ["colour"])
	async def color(self, ctx, role: discord.Role, *, color: discord.Color = None):
		'''The color of a role'''
		if color:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(color = color)
			await ctx.embed_reply(role.mention + " has been recolored")
		else:
			await ctx.embed_reply(role.mention + "'s color is {}".format(role.color))
	
	@role.command(aliases = ["make", "new"])
	@commands.bot_has_guild_permissions(manage_roles = True)
	@commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner())
	async def create(self, ctx, *, name: str = ""):
		'''Creates a role'''
		# TODO: Add more options
		role = await ctx.guild.create_role(name = name)
		await ctx.embed_reply(role.mention + " created")
	
	@role.command()
	async def default(self, ctx, *, role: discord.Role):
		'''Whether a role is the default role or not'''
		await ctx.embed_reply(role.mention + " is {}the default role".format("" if role.is_default() else "not "))
	
	@role.command(aliases = ["hoist"])
	async def hoisted(self, ctx, role: discord.Role, hoist: bool = None):
		'''Whether a role is displayed separately from other members or not'''
		if hoist is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(hoist = hoist)
			await ctx.embed_reply(role.mention + " has been {}hoisted".format("" if hoist else "un"))
		else:
			await ctx.embed_reply(role.mention + " is {}hoisted".format("" if role.hoist else "not "))
	
	@role.command()
	async def id(self, ctx, *, role: discord.Role):
		'''The ID of a role'''
		await ctx.embed_reply(role.id)
	
	@role.command()
	async def managed(self, ctx, *, role: discord.Role):
		'''Indicates if the role is managed by the guild through some form of integrations such as Twitch'''
		await ctx.embed_reply(role.mention + " is {}managed".format("" if role.managed else "not "))
	
	@role.command()
	async def mentionable(self, ctx, role: discord.Role, mentionable: bool = None):
		'''Whether a role is mentionable or not'''
		if mentionable is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(mentionable = mentionable)
			await ctx.embed_reply(role.mention + " is now {}mentionable".format("" if mentionable else "not "))
		else:
			await ctx.embed_reply(role.mention + " is {}mentionable".format("" if role.mentionable else "not "))
	
	@role.command()
	async def name(self, ctx, role: discord.Role, *, name: str = ""):
		'''The name of a role'''
		if name:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(name = name)
			await ctx.embed_reply(role.mention + " has been renamed")
		else:
			await ctx.embed_reply(role.name)
	
	@role.command()
	async def position(self, ctx, role: discord.Role, position: int = None):
		'''
		The position of a role
		This number is usually positive
		The bottom role has a position of 0
		'''
		if position is not None:
			await commands.check_any(commands.has_guild_permissions(manage_roles = True), commands.is_owner()).predicate(ctx)
			await commands.bot_has_guild_permissions(manage_roles = True).predicate(ctx)
			await role.edit(position = position)
			await ctx.embed_reply(role.mention + "'s position has been set to {}".format(position))
		else:
			await ctx.embed_reply(role.mention + "'s position is {}".format(role.position))
	
	# TODO: move to server cog
	@role.command()
	async def positions(self, ctx):
		'''
		WIP
		Positions of roles in the server
		'''
		await ctx.embed_reply(', '.join("{}: {}".format(role.mention, role.position) for role in sorted(ctx.guild.roles[1:], key = attrgetter("position"), reverse = True)))


{'fraction_non_alphanumeric': 0.13509240043482557, 'fraction_numerical': 0.00039529597786342526, 'mean_word_length': 4.859872611464968, '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': '767587', 'n_tokens_mistral': 3595, 'n_tokens_neox': 3359, 'n_words': 880}