<commit_before>import os
import discord
import asyncio
from discord.ext import commands
from cogs.utils.dataIO import dataIO
from .utils import checks
from cogs.utils.chat_formatting import box, pagify
import logging

log = logging.getLogger("red.PermHandler")


class PermHandler:
    """
    Save myself time with managing an alliance discord
    """

    __author__ = "mikeshardmind"
    __version__ = "2.1a"

    def __init__(self, bot):
        self.bot = bot
        self.settings = dataIO.load_json('data/permhandler/settings.json')

    def save_json(self):
        dataIO.save_json("data/permhandler/settings.json", self.settings)

    @checks.admin_or_permissions(Manage_server=True)
    @commands.group(name="permhandle", aliases=["phandle"],
                    pass_context=True, no_pm=True)
    async def permhandle(self, ctx):
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)

    def initial_config(self, server_id):
        """ensures the server has an entry"""

        if server_id not in self.settings:
            self.settings[server_id] = {'chans': [],
                                        'roles': [],
                                        'activated': False,
                                        'proles': []
                                        }
        if 'chans' not in self.settings[server_id]:
            self.settings[server_id]['chans'] = []
        if 'roles' not in self.settings[server_id]:
            self.settings[server_id]['roles'] = []
        if 'activated' not in self.settings[server_id]:
            self.settings[server_id]['chans'] = False
        if 'proles' not in self.settings[server_id]:
            self.settings[server_id]['proles'] = []
        if 'floor' not in self.settings[server_id]:
            self.settings[server_id]['floor'] = None
        if 'registers' not in self.settings[server_id]:
            self.settings[server_id]['registers'] = []
        self.save_json()

    @permhandle.command(name="listrolemembers", pass_context=True, no_pm=True)
    async def listrolemembers(self, ctx, role: discord.Role):
        """retrieves a list of all members of a role"""

        server = ctx.message.server
        author = ctx.message.author

        await self.bot.request_offline_members(server)
        members = list(server.members)
        members = [m for m in members if role in m.roles]
        output = "Members of role named: {}".format(role.name)

        for member in members:
            output += "\nID: {} Name: {}#{}".format(member.id, member.name,
                                                    member.discriminator)
            if member.nick:
                output += " Nick: {}".format(member.nick)

        for page in pagify(output, delims=["\n", ","]):
            await self.bot.send_message(author, box(page))

    @commands.command(name="signup", pass_context=True,
                      no_pm=True, hidden=True)
    async def signup(self, ctx, role: discord.Role):
        """Lets you sign up for certain roles if you have a priveleged role"""

        author = ctx.message.author
        server = ctx.message.server
        self.initial_config(server.id)
        roles = self.settings[server.id]['roles']
        registers = self.settings[server.id]['registers']
        role_list = [r for r in server.roles if r.id in roles]
        register_list = [r for r in server.roles if r.id in registers]

        if set(role_list).isdisjoint(author.roles):
            return await self.bot.say("Only alliance members may sign up for "
                                      "this role.")

        if role in author.roles:
            return await self.bot.say("You already have that role!")
        if role not in register_list:
            return await self.bot.say("That role is not available for signup.")

        await self.bot.add_roles(author, role)
        await self.bot.say("Role assigned.")

    @checks.admin_or_permissions(Manage_server=True)
    @permhandle.command(name="addregister", pass_context=True, no_pm=True)
    async def addregister(self, ctx, role: discord.Role):
        """adds a register-able role"""

        server = ctx.message.server
        self.initial_config(server.id)
        if role.id in self.settings[server.id]['registers']:
            return await self.bot.say("Already in roles")
        self.settings[server.id]['registers'].append(role.id)
        self.save_json()<commit_msg>minor phrasing changes<commit_after>import os
import discord
import asyncio
from discord.ext import commands
from cogs.utils.dataIO import dataIO
from .utils import checks
from cogs.utils.chat_formatting import box, pagify
import logging

log = logging.getLogger("red.PermHandler")


class PermHandler:
    """
    Save myself time with managing an alliance discord
    """

    __author__ = "mikeshardmind"
    __version__ = "2.1a"

    def __init__(self, bot):
        self.bot = bot
        self.settings = dataIO.load_json('data/permhandler/settings.json')

    def save_json(self):
        dataIO.save_json("data/permhandler/settings.json", self.settings)

    @checks.admin_or_permissions(Manage_server=True)
    @commands.group(name="permhandle", aliases=["phandle"],
                    pass_context=True, no_pm=True)
    async def permhandle(self, ctx):
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)

    def initial_config(self, server_id):
        """ensures the server has an entry"""

        if server_id not in self.settings:
            self.settings[server_id] = {'chans': [],
                                        'roles': [],
                                        'activated': False,
                                        'proles': []
                                        }
        if 'chans' not in self.settings[server_id]:
            self.settings[server_id]['chans'] = []
        if 'roles' not in self.settings[server_id]:
            self.settings[server_id]['roles'] = []
        if 'activated' not in self.settings[server_id]:
            self.settings[server_id]['chans'] = False
        if 'proles' not in self.settings[server_id]:
            self.settings[server_id]['proles'] = []
        if 'floor' not in self.settings[server_id]:
            self.settings[server_id]['floor'] = None
        if 'registers' not in self.settings[server_id]:
            self.settings[server_id]['registers'] = []
        self.save_json()

    @permhandle.command(name="listrolemembers", pass_context=True, no_pm=True)
    async def listrolemembers(self, ctx, role: discord.Role):
        """retrieves a list of all members of a role"""

        server = ctx.message.server
        author = ctx.message.author

        await self.bot.request_offline_members(server)
        members = list(server.members)
        members = [m for m in members if role in m.roles]
        output = "Members of role named: {}".format(role.name)

        for member in members:
            output += "\nID: {} Name: {}#{}".format(member.id, member.name,
                                                    member.discriminator)
            if member.nick:
                output += " Nick: {}".format(member.nick)

        for page in pagify(output, delims=["\n", ","]):
            await self.bot.send_message(author, box(page))

    @commands.command(name="signup", pass_context=True,
                      no_pm=True, hidden=True)
    async def signup(self, ctx, role: discord.Role):
        """Lets you sign up for certain roles if you have a priveleged role"""

        author = ctx.message.author
        server = ctx.message.server
        self.initial_config(server.id)
        roles = self.settings[server.id]['roles']
        registers = self.settings[server.id]['registers']
        role_list = [r for r in server.roles if r.id in roles]
        register_list = [r for r in server.roles if r.id in registers]

        if set(role_list).isdisjoint(author.roles):
            return await self.bot.say("You do not meet the requirements  "
                                      "to signup for this role.")

        if role in author.roles:
            return await self.bot.say("You already have that role!")
        if role not in register_list:
            return await self.bot.say("That role is not available for signup.")

        await self.bot.add_roles(author, role)
        await self.bot.say("Role assigned.")

    @checks.admin_or_permissions(Manage_server=True)
    @permhandle.command(name="addregister", pass_context=True, no_pm=True)
    async def addregister(self, ctx, role: discord.Role):
        """adds a register-able role"""

        server = ctx.message.server
        self.initial_config(server.id)
        if role.id in self.settings[server.id]['registers']:
            return await self.bot.say("Already in roles")
        self.settings[server.id]['registers'].append(role.id)
        self.save_json()
{'fraction_non_alphanumeric': 0.11442619287071182, 'fraction_numerical': 0.00044697731590121804, 'mean_word_length': 2.2451051486584483, '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': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '90423', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2509, 'n_words': 633}