async def snapshot_role(ctx, role: discord.Role, group: RoleGroup = None): """Adds role to the internal database""" if role.is_bot_managed() or role.is_integration() or role.is_premium_subscriber(): logger.info(f"Skipping role '{role}' as it's system role") raise commands.BadArgument(f"Role '{role}' is a system role") if not utils.can_manage_role(ctx.guild.me, role): logger.info(f"Skipping role '{role}' as bot cannot manage it") raise commands.BadArgument(f"Bot cannot manage role '{role}'") if await Role.exists(name=role.name): logger.info(f"Skipping role '{role}' as it already exists") raise commands.BadArgument(f"Role '{role}' already exists in DB") group = group or (await RoleGroup.get_or_create(name=utils.snapshot_role_group))[0] number = await db_utils.get_max_number(Role) await db_utils.reshuffle(Role, number) db_role = Role(name=role.name, color=role.color.value, number=number, archived=False, assignable=False, mentionable=role.mentionable, group=group) await db_role.save()
async def manage_roles_check( self, ctx: commands.Context, action: str, role: discord.Role = None, verbosity=Verbosity.ALL, error_title="default" ) -> int: # verbose toggle e.g. in multi-role changes """ Error checking to see if whatever action can be performed. Verbosity: 0: Nothing 1: Manage Roles barf embed 2: Everything Returns: 0: Humanity is fine Anything else: Alien invasion """ error_title = f"Couldn't {action} the role!" if error_title == "default" else error_title if not ctx.me.guild_permissions.manage_roles: # was originally gonna separate this all out but given discord rate-limits are stupid you can't work on the assumption that you"ve retained permissions if verbosity > Verbosity.SILENT: await self.bot.DefaultEmbedResponses.error_embed( self.bot, ctx, error_title, desc="Please give me **Manage Roles** permissions") return 3 if role: if role.managed or role.is_bot_managed( ) or role.is_premium_subscriber() or role.is_integration( ) or role.is_default(): """ Basically checks if the role is a nitro booster role, or is an integration-managed role. """ if verbosity == Verbosity.ALL: await self.bot.DefaultEmbedResponses.error_embed( self.bot, ctx, error_title, desc=f"A user cannot {action} this role") return 2 if ctx.me.top_role < role: if verbosity == Verbosity.ALL: await self.bot.DefaultEmbedResponses.error_embed( self.bot, ctx, error_title, desc=f"I can't add roles higher than me to members :sob:" if action == "add" else "I can't remove roles higher than me from members :sob:" ) return 1 return 0
async def roleinfo(self, ctx, role: discord.Role): embed = (discord.Embed(color=discord.Color.blurple()).set_author( name=f'Role Information: {str(role)}', icon_url=ctx.author.avatar_url)) embed.add_field(name='Creation Date:', value=role.created_at).add_field( name='Mentionable', value=role.mentionable) embed.add_field(name='Managed By Integration', value=role.is_integration()).add_field( name='Managed By Bot', value=role.is_bot_managed()) embed.add_field(name='Role Position', value=role.position).add_field(name='Role ID', value=f'`{role.id}`') await ctx.send(embed=embed)
async def role(self, ctx, *, role: discord.Role): query = f"""http://www.colourlovers.com/img/{hex(role.colour.value).replace("0x", "")}/100/100/""" embed = discord.Embed( colour=0x202225, title=f"Information about {role.name} (ID {role.id}!)") embed.set_thumbnail( url=query.replace("/img/0/100/100/", "/img/8B99A4/100/100/")) embed.add_field( name="Permissions", value= f"[{role.permissions.value}](https://discordapi.com/permissions.html#{role.permissions.value})", inline=True) embed.add_field(name="Hoisted", value=role.hoist, inline=True) embed.add_field(name="Position", value=f"{role.position}/{len(ctx.guild.roles)}", inline=True) embed.add_field(name="Mentionable", value=role.mentionable, inline=True) embed.add_field(name="Managed by 3rd party", value=role.managed, inline=True) embed.add_field(name="Is Managed", value=role.is_bot_managed(), inline=True) embed.add_field(name="Is the Boost Role", value=role.is_premium_subscriber(), inline=True) embed.add_field(name="Is an Integration", value=role.is_integration(), inline=True) embed.set_footer(text=f"Role created at {role.created_at}.") member_count = 0 members = "" for member in role.members: if member_count == 0: members += f"<@{member.id}>" else: members += f", <@{member.id}>" member_count += 1 try: embed.add_field(name=f"Role Members ({len(role.members)})", value=members, inline=False) except discord.errors.HTTPException: embed.add_field(name=f"Role Members ({len(role.members)})", value="There was too much to put here.", inline=False) await ctx.send(embed=embed)
async def role(self, ctx: commands.Context, r: discord.Role): """Shows role info""" emb = discord.Embed(title=r.name, color=r.color) emb.set_author(name=f'Color: #{r.color.value:X}') if r.is_bot_managed(): emb.description = 'Bot role: ' + self.bot.get_user( r.tags.bot_id).mention elif r.is_default(): emb.description = 'Default role' elif r.is_integration(): emb.description = 'Integration role: ❄ID ' + str( r.tags.integration_id) elif r.is_premium_subscriber(): emb.description = 'Nitro Boost role' emb.add_field(name='❄ ID', value=r.id) # noinspection PyTypeChecker emb.add_field(name='Member count', value=len(r.members)) emb.add_field(name='Displays separately', value=r.hoist) emb.add_field(name='Created at', value=r.created_at) emb.add_field(name='Permissions', value=f'0x{r.permissions.value:X}') emb.add_field(name='Position', value=r.position) await ctx.reply(embed=emb)
async def rinfo(self, ctx, *, role: discord.Role): """Get info about role""" em = discord.Embed( title=chat.escape(role.name, formatting=True), color=role.color if role.color.value else discord.Embed.Empty, ) em.add_field(name=_("ID"), value=role.id) em.add_field( name=_("Permissions"), value= "[{0}](https://cogs.fixator10.ru/permissions-calculator/?v={0})". format(role.permissions.value), ) em.add_field( name=_("Exists since"), value=get_markdown_timestamp(role.created_at, TimestampStyle.datetime_long), ) em.add_field(name=_("Color"), value=role.colour) em.add_field(name=_("Members"), value=str(len(role.members))) em.add_field(name=_("Position"), value=role.position) em.add_field(name=_("Managed"), value=bool_emojify(role.managed)) em.add_field(name=_("Managed by bot"), value=bool_emojify(role.is_bot_managed())) em.add_field(name=_("Managed by boosts"), value=bool_emojify(role.is_premium_subscriber())) em.add_field(name=_("Managed by integration"), value=bool_emojify(role.is_integration())) em.add_field(name=_("Hoist"), value=bool_emojify(role.hoist)) em.add_field(name=_("Mentionable"), value=bool_emojify(role.mentionable)) em.add_field(name=_("Mention"), value=role.mention + "\n`" + role.mention + "`") em.set_thumbnail( url= f"https://xenforo.com/community/rgba.php?r={role.colour.r}&g={role.color.g}&b={role.color.b}&a=255" ) await ctx.send(embed=em)
async def rolle(self, ctx, *, rolle: discord.Role): """ Viser info om en rolle """ if rolle.name == "@everyone": return await ctx.reply("Skriv inn en annen rolle enn `@everyone`") if str(rolle.color) != "#000000": color = rolle.color else: color = discord.Colour(0x99AAB5) hoisted = "Nei" mentionable = "Nei" if rolle.hoist: hoisted = "Ja" if rolle.mentionable: mentionable = "Ja" rolle_created_date = rolle.created_at.strftime("%d. %b. %Y - %H:%M") since_created_days = (ctx.message.created_at - rolle.created_at).days if since_created_days == 1: since_created_days_string = "dag" else: since_created_days_string = "dager" members = [] for member in rolle.members: members.append(f"{member.name}#{member.discriminator}") members = ", ".join(members) if len(members) > 1024: members = "For mange medlemmer for å vise her" if len(members) == 0: members = "**Ingen**" permissions = ", ".join([ permission for permission, value in iter(rolle.permissions) if value is True ]) embed = discord.Embed( title=rolle.name, description=f"{rolle.mention}\n**ID:** {rolle.id}", color=color) embed.set_author(name=rolle.guild.name, icon_url=rolle.guild.icon_url) embed.add_field(name="Fargekode", value=str(rolle.color)) embed.add_field(name="Opprettet", value=f"{rolle_created_date}\n{since_created_days} " + f"{since_created_days_string} siden") embed.add_field(name="Posisjon", value=rolle.position) embed.add_field(name="Nevnbar", value=mentionable) if rolle.is_bot_managed(): embed.add_field(name="Bot-håndert", value="Ja") if rolle.is_integration(): embed.add_field(name="Integrasjon", value="Ja") if rolle.is_premium_subscriber(): embed.add_field(name="Boost", value="Ja") embed.add_field(name="Vises separat i medlemsliste", value=hoisted) if permissions: embed.add_field(name="Tillatelser", value=permissions, inline=False) embed.add_field(name=f"Brukere med rollen ({len(rolle.members)})", value=members, inline=False) await ctx.reply(embed=embed)