<commit_before>import discord
import os
import math
from discord.ext import commands

from .utils.chat_formatting import pagify
from .utils.chat_formatting import box
from .utils.dataIO import dataIO
from .utils import checks
from random import randint

from datetime import date, timedelta



class Flag:
    """Cog for organizing flags"""

    def __init__(self, bot):
        self.bot = bot
        self.path = "data/Fox-Cogs/flag/"
        self.file_path = "data/Fox-Cogs/flag/flag.json"
        self.the_data = dataIO.load_json(self.file_path)
        # self.tags = dataIO.load_json("cogs/tags.json")
        # self.clans = dataIO.load_json("cogs/clans.json")


    def save_data(self):
        """Saves the json"""
        dataIO.save_json(self.file_path, self.the_data)

    def _flag_template(self):
        return {
            'reason': None,
            'expireyear': None,
            'expiremonth': None,
            'expireday': None
            }
# ************************Flag command group start************************
    @commands.command(pass_context=True, no_pm=True)
    async def flag(self, ctx, user: discord.Member, *reason):
        """Flag a user"""
        server = ctx.message.server
        self._check_flags(server)
        # clashroyale = self.bot.get_cog('clashroyale')
        # if clashroyale is None:
            # await self.bot.say("Requires clashroyale cog installed")
            # return
            
        if user.id not in self.the_data[server.id]['flags']:
            self.the_data[server.id]['flags'][user.id] = []
        
        flag = self._flag_template()
        expiredate = date.today() 
        expiredate += timedelta(days=self.the_data[server.id]['days'])
        
        flag['reason'] = " ".join(reason)
        flag['expireyear'] = expiredate.year
        flag['expiremonth'] = expiredate.month
        flag['expireday'] = expiredate.day
        
        self.the_data[server.id]['flags'][user.id].append(flag)
        self.save_data()
        await self._list_flags(ctx, server, user)
    
@commands.command(pass_context=True, no_pm=True, aliases['flagclear'])
    async def clearflag(self, ctx, user: discord.Member):
        """Clears flags for a user"""
        server = ctx.message.server
        self._check_flags(server)

        self.the_data[server.id]['flags'][user.id] = []
        
        self.save_data()
        await self.bot.say("Success!") 
        
    @commands.group(pass_context=True, no_pm=True, aliases=['setflag'])
    async def flagset(self, ctx):
        """Manage settings for flagging"""
        server = ctx.message.server
        self._check_flags(server)
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)
            
        # clashroyale = self.bot.get_cog('clashroyale')
        # if clashroyale is None:<commit_msg>admin only<commit_after>import discord
import os
import math
from discord.ext import commands

from .utils.chat_formatting import pagify
from .utils.chat_formatting import box
from .utils.dataIO import dataIO
from .utils import checks
from random import randint

from datetime import date, timedelta



class Flag:
    """Cog for organizing flags"""

    def __init__(self, bot):
        self.bot = bot
        self.path = "data/Fox-Cogs/flag/"
        self.file_path = "data/Fox-Cogs/flag/flag.json"
        self.the_data = dataIO.load_json(self.file_path)
        # self.tags = dataIO.load_json("cogs/tags.json")
        # self.clans = dataIO.load_json("cogs/clans.json")


    def save_data(self):
        """Saves the json"""
        dataIO.save_json(self.file_path, self.the_data)

    def _flag_template(self):
        return {
            'reason': None,
            'expireyear': None,
            'expiremonth': None,
            'expireday': None
            }
# ************************Flag command group start************************
    @commands.command(pass_context=True, no_pm=True)
    async def flag(self, ctx, user: discord.Member, *reason):
        """Flag a user"""
        server = ctx.message.server
        self._check_flags(server)
        # clashroyale = self.bot.get_cog('clashroyale')
        # if clashroyale is None:
            # await self.bot.say("Requires clashroyale cog installed")
            # return
            
        if user.id not in self.the_data[server.id]['flags']:
            self.the_data[server.id]['flags'][user.id] = []
        
        flag = self._flag_template()
        expiredate = date.today() 
        expiredate += timedelta(days=self.the_data[server.id]['days'])
        
        flag['reason'] = " ".join(reason)
        flag['expireyear'] = expiredate.year
        flag['expiremonth'] = expiredate.month
        flag['expireday'] = expiredate.day
        
        self.the_data[server.id]['flags'][user.id].append(flag)
        self.save_data()
        await self._list_flags(ctx, server, user)
    
@commands.command(pass_context=True, no_pm=True, aliases['flagclear'])
    async def clearflag(self, ctx, user: discord.Member):
        """Clears flags for a user"""
        server = ctx.message.server
        self._check_flags(server)

        self.the_data[server.id]['flags'][user.id] = []
        
        self.save_data()
        await self.bot.say("Success!") 
    
    @checks.mod_or_permissions(administrator=True)
    @commands.group(pass_context=True, no_pm=True, aliases=['setflag'])
    async def flagset(self, ctx):
        """Manage settings for flagging"""
        server = ctx.message.server
        self._check_flags(server)
        if ctx.invoked_subcommand is None:
            await self.bot.send_cmd_help(ctx)
            
        # clashroyale = self.bot.get_cog('clashroyale')
        # if clashroyale is None:
{'fraction_non_alphanumeric': 0.1375173852573018, 'fraction_numerical': 0.0, 'mean_word_length': 2.4908980582524274, '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': '1141305', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1748, 'n_words': 357}