<commit_before>import os
import discord
from discord.ext import commands
from cogs.utils.dataIO import dataIO
from cogs.utils import checks
import datetime


class partnerapp:
    """Custom Cog for applications"""
    def __init__(self, bot):
        self.bot = bot
        self.settings = dataIO.load_json('data/partner/settings.json')
        for s in self.settings:
            self.settings[s]['usercache'] = []
    def save_json(self):
        dataIO.save_json("data/partner/settings.json", self.settings)

    @commands.group(name="psetup", pass_context=True, no_pm=True)
    async def psetup(self, ctx):
        """configuration settings"""
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)
    def initial_config(self, server_id):
        """makes an entry for the server, defaults to turned off"""
        if server_id not in self.settings:
            self.settings[server_id] = {'inactive': True,
                                        'output': [],
                                        'usercache': [],
                                        'usermin': 0,
                                        'partnermsg': 0,
                                        'multiout': False
                                        }
            self.save_json()
    @checks.admin_or_permissions(Manage_server=True)
    @psetup.command(name="auto", pass_context=True, no_pm=True)
    async def auto(self, ctx):
        """Use this command to setup Partner Applications"""
        author =ctx.message.author
        server = ctx.message.server
        msg1 = await self.bot.say("How many member does a server need to partner with your server?")
        usermin = await self.bot.wait_for_message(channel=msg1.channel, author=author, timeout=120)
        if usermin is not None:
            if server.id not in self.settings:
                self.initial_config(server.id)
            else:
                self.settings[server.id]['usermin'] = int(usermin.content)
                self.save_json()
        else:
            return await self.bot.say("You have entered an invalid response. Please try again. Only enter a number here!")
        msg2 = await self.bot.say("Where do you want me to put your applications? (Use the Channel ID here)")
        chan = await self.bot.wait_for_message(channel=msg2.channel, author=author, timeout=120)
        if server.id not in self.settings:
            self.initial_config(server.id)
        if chan in self.settings[server.id]['output']:
            return await self.bot.say("Channel already set as output")
        else:
            self.settings[server.id]['output'] = [chan]
            self.save_json()

        msg3 = await self.bot.say("What is your Partner Message? DO NOT include code marks. Paste your partner message only.")
        pmsg = await self.bot.wait_for_message(channel=msg3.channel, author=author, timout=160)
        if pmsg is not None:
            if server.id not in self.settings:
                self.initial_config(server.id)
            else:
                self.settings[server.id]['partnermsg'] = pmsg.content
                self.save_json()
        else:
            return await self.bot.say("You must enter a partner message. Do not include quotes or block text")


    @checks.admin_or_permissions(Manage_server=True)
    @psetup.command(name="roles", pass_context=True, no_pm=True)
    async def rolecreation(self, ctx):
        author = ctx.message.author
        server = ctx.message.server
        aprole = discord.utils.get(server.roles, name="Partner Applicant")
        partnerrole = discord.utils.get(server.roles, name="Partners")
        if partnerrole not in server.roles:
            await self.bot.create_role(server, name="Partners")
        if aprole not in server.roles:
            await self.bot.create_role(server, name="Partner Applicant")
        await self.bot.say("All done!")


    @checks.admin_or_permissions(Manage_server=True)
    @psetup.command(name="msg", pass_context=True, no_pm=True)
    async def pmsg(self, ctx,):
        """Set your servers Partner message"""
        server = ctx.message.server
        author = ctx.message.author
        msg = await self.bot.say("Please enter your Partner message, Do not include code blocks as they will be added"
                                 "by the bot later")
        pmsg = await self.bot.wait_for_message(channel=msg.channel, author=author, timeout=120)
        if pmsg is not None:
            try:
                if server.id not in self.settings:
                    self.initial_config(server.id)
                else:
                    self.settings[server.id]['partnermsg'] = pmsg.content
                    self.save_json()
                    await self.bot.say("Partner Message has been set")
            except AttributeError:
                pass
        else:
            await self.bot.say("You must enter a partner message. Do not include quotes or block text")

    @checks.admin_or_permissions(Manage_server=True)
    @psetup.command(name="channel", pass_context=True, no_pm=True)
    async def setoutput(self, ctx, chan=None):
        """sets the place to output application embed to when finished."""
        server = ctx.message.server
        if server.id not in self.settings:
            self.initial_config(server.id)
        if chan in self.settings[server.id]['output']:
            return await self.bot.say("Channel already set as output")
        for channel in server.channels:
            if str(chan) == str(channel.id):
                if self.settings[server.id]['multiout']:
                    self.settings[server.id]['output'].append(chan)
                    self.save_json()
                    return await self.bot.say("Channel added to output list")
                else:
                    self.settings[server.id]['output'] = [chan]
                    self.save_json()
                    return await self.bot.say("Channel set as output")
        await self.bot.say("I could not find a channel with that id")

    @checks.admin_or_permissions(Manage_server=True)
    @psetup.command(name="toggle", pass_context=True, no_pm=True)
    async def reg_toggle(self, ctx):
        """Toggles applications for the server"""
        server = ctx.message.server
        if server.id not in self.settings:
            self.initial_config(server.id)
        self.settings[server.id]['inactive'] = \
            not self.settings[server.id]['inactive']
        self.save_json()<commit_msg>revert<commit_after>import os
import discord
from discord.ext import commands
from cogs.utils.dataIO import dataIO
from cogs.utils import checks
import datetime


class partnerapp:
    """Custom Cog for applications"""
    def __init__(self, bot):
        self.bot = bot
        self.settings = dataIO.load_json('data/partner/settings.json')
        for s in self.settings:
            self.settings[s]['usercache'] = []
    def save_json(self):
        dataIO.save_json("data/partner/settings.json", self.settings)

    @commands.group(name="pset", pass_context=True, no_pm=True)
    async def pset(self, ctx):
        """configuration settings"""
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)
            await self.bot.say("```In order for this cog to work you need to follow these steps. **NOTICE** You must have MANAGE SERVER perms in discord to setup this cog! \n"
                               "1. ``pset channel ID`` This is the channel **ID** that you want to output your applications to\n"
                               "2. ``pset roles`` This will create the roles needed for the cog to function correctly\n"
                               "3. ``pset msg`` Using this command will allow you to set your partner message that will be DMed to the applicant when their application is submitted. \n"
                               "4. ``pset toggle`` this will turn on the cog to start accepting applications"
                               "**If you cannot see these command set your admin and mod roles with set adminrole and set modrole**```")
    def initial_config(self, server_id):
        """makes an entry for the server, defaults to turned off"""
        if server_id not in self.settings:
            self.settings[server_id] = {'inactive': True,
                                        'output': [],
                                        'usercache': [],
                                        'partnermsg': 0,
                                        'multiout': False
                                        }
            self.save_json()

    @checks.admin_or_permissions(Manage_server=True)
    @pset.command(name="roles", pass_context=True, no_pm=True)
    async def rolecreation(self, ctx):
        author = ctx.message.author
        server = ctx.message.server
        aprole = discord.utils.get(server.roles, name="Partner Applicant")
        partnerrole = discord.utils.get(server.roles, name="Partners")
        if partnerrole not in server.roles:
            await self.bot.create_role(server, name="Partners")
        if aprole not in server.roles:
            await self.bot.create_role(server, name="Partner Applicant")
        await self.bot.say("All done!")


    @checks.admin_or_permissions(Manage_server=True)
    @pset.command(name="msg", pass_context=True, no_pm=True)
    async def pmsg(self, ctx,):
        """Set your servers Partner message"""
        server = ctx.message.server
        author = ctx.message.author
        msg = await self.bot.say("Please enter your Partner message, Do not include code blocks as they will be added"
                                 "by the bot later")
        pmsg = await self.bot.wait_for_message(channel=msg.channel, author=author, timeout=120)
        if pmsg is not None:
            try:
                if server.id not in self.settings:
                    self.initial_config(server.id)
                else:
                    self.settings[server.id]['partnermsg'] = pmsg.content
                    self.save_json()
                    await self.bot.say("Partner Message has been set")
            except AttributeError:
                pass
        else:
            await self.bot.say("You must enter a partner message. Do not include quotes or block text")

    @checks.admin_or_permissions(Manage_server=True)
    @pset.command(name="channel", pass_context=True, no_pm=True)
    async def setoutput(self, ctx, chan=None):
        """sets the place to output application embed to when finished."""
        server = ctx.message.server
        if server.id not in self.settings:
            self.initial_config(server.id)
        if chan in self.settings[server.id]['output']:
            return await self.bot.say("Channel already set as output")
        for channel in server.channels:
            if str(chan) == str(channel.id):
                if self.settings[server.id]['multiout']:
                    self.settings[server.id]['output'].append(chan)
                    self.save_json()
                    return await self.bot.say("Channel added to output list")
                else:
                    self.settings[server.id]['output'] = [chan]
                    self.save_json()
                    return await self.bot.say("Channel set as output")
        await self.bot.say("I could not find a channel with that id")

    @checks.admin_or_permissions(Manage_server=True)
    @pset.command(name="toggle", pass_context=True, no_pm=True)
    async def reg_toggle(self, ctx):
        """Toggles applications for the server"""
        server = ctx.message.server
        if server.id not in self.settings:
            self.initial_config(server.id)
        self.settings[server.id]['inactive'] = \
            not self.settings[server.id]['inactive']
        self.save_json()
{'fraction_non_alphanumeric': 0.10095302353040399, 'fraction_numerical': 0.002361474234629333, 'mean_word_length': 2.072020725388601, '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': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4406380', 'n_tokens_mistral': 3224, 'n_tokens_neox': 3151, 'n_words': 897}