<commit_before>import discord
from discord.ext import commands
from tabulate import tabulate
from datetime import datetime

from models.character import Character
from models.member import Member
from models.historical import Historical
from models.server import Server
from utils import *

class Add:
    """Add commands."""

    def __init__(self, bot):
        self.bot = bot

    async def __get_rank_and_member(self, author, user, roles):
        if not user:
            discord_user = author
            rank = 'Officer' if ADMIN_USER in roles else 'Member'
        else:
            try:
                user_roles = [u.name for u in user.roles]
                rank = 'Officer' if ADMIN_USER in user_roles else 'Member'
            except Exception as e:
                rank = 'Member'
                print(e)
            discord_user = user
            if ADMIN_USER not in roles:
                await self.bot.say(codify("Only officers may perform this action"))
                return (None, None)
        
        return (rank, discord_user)

    def __get_server_and_member(self, discord_server, discord_user):
        member = Member.objects(discord=discord_user.id).first()
        server = Server.objects(id=discord_server.id).first()

        if not server:
            server = Server.create({
                'id': discord_server.id,
                'name': discord_server.name,
                'avatar': discord_server.avatar
            })

        if not member:
            member = Member.create({
                'discord': discord_user.id,
                'name': discord_user.name,
                'avatar': discord_user.avatar
            })

        # Checks if member being added is in the server
        server_member = Member.objects(servers=discord_server.id, discord=discord_user.id).first()
        if not server_member:
            server.members.append(member)
            server.save()
            member.servers.append(discord_server.id)
            member.save()

        return (server, member)

    @commands.command(pass_context=True)
    async def add(self,
                  ctx,
                  fam_name,
                  char_name,
                  level: int,
                  ap : int,
                  dp: int,
                  char_class,
                  user: discord.User = None):
        """Adds your primary character to the guild. This character is linked with your
        discord id and can only be updated by either that member or an officer.<commit_msg>Updates image retrievals to user URL instead of hash<commit_after>import discord
from discord.ext import commands
from tabulate import tabulate
from datetime import datetime

from models.character import Character
from models.member import Member
from models.historical import Historical
from models.server import Server
from utils import *

class Add:
    """Add commands."""

    def __init__(self, bot):
        self.bot = bot

    async def __get_rank_and_member(self, author, user, roles):
        if not user:
            discord_user = author
            rank = 'Officer' if ADMIN_USER in roles else 'Member'
        else:
            try:
                user_roles = [u.name for u in user.roles]
                rank = 'Officer' if ADMIN_USER in user_roles else 'Member'
            except Exception as e:
                rank = 'Member'
                print(e)
            discord_user = user
            if ADMIN_USER not in roles:
                await self.bot.say(codify("Only officers may perform this action"))
                return (None, None)
        
        return (rank, discord_user)

    def __get_server_and_member(self, discord_server, discord_user):
        member = Member.objects(discord=discord_user.id).first()
        server = Server.objects(id=discord_server.id).first()

        if not server:
            server = Server.create({
                'id': discord_server.id,
                'name': discord_server.name,
                'avatar': discord_server.icon_url or ''
            })

        if not member:
            member = Member.create({
                'discord': discord_user.id,
                'name': discord_user.name,
                'avatar': discord_user.avatar_url or ''
            })

        # Checks if member being added is in the server
        server_member = Member.objects(servers=discord_server.id, discord=discord_user.id).first()
        if not server_member:
            server.members.append(member)
            server.save()
            member.servers.append(discord_server.id)
            member.save()

        return (server, member)

    @commands.command(pass_context=True)
    async def add(self,
                  ctx,
                  fam_name,
                  char_name,
                  level: int,
                  ap : int,
                  dp: int,
                  char_class,
                  user: discord.User = None):
        """Adds your primary character to the guild. This character is linked with your
        discord id and can only be updated by either that member or an officer.
{'fraction_non_alphanumeric': 0.07672734390291643, 'fraction_numerical': 0.0, 'mean_word_length': 1.7696476964769647, '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': '1715294', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1306, 'n_words': 409}