Example #1
0
    async def lookup(self, ctx, query):
        """Looks up a guild member by family name or character name or pass in a user like @drawven"""
        try:
            mentions = ctx.message.mentions
            if len(mentions) >= 1:
                members = Character.primary_chars(member=mentions[0].id)
            else:
                members = Character.primary_chars(Q(fam_name__icontains = query) | Q(char_name__icontains = query),
                                         server = ctx.message.guild.id)

            rows = get_row(members, False)
            data = tabulate(rows,
                            HEADERS,
                            'simple',)

            if members.count() == 1:
                content = codify(data) +"\n" + members.first().gear_pic
                await send_or_display(ctx.message.guild.id, ctx.message.author, ctx, content)
            else:
                for page in paginate(data):
                    await send_or_display(ctx.message.guild.id, ctx.message.author, ctx, page)

        except Exception as e:
            print_error(e)
            await ctx.send("Something went horribly wrong")
Example #2
0
    async def class_search(self, ctx, char_class=""):
        """Looks up main characters by class"""
        try:

            if char_class.lower() == "dk":
                members = Character.primary_chars(Q(char_class__iexact = char_class)
                                            | Q(char_class__iexact = "dark")
                                            | Q(char_class__iexact = "darkknight")
                                            | Q(char_class__iexact = "dark knight"))
            elif char_class.lower() == "sorc":
                members = Character.primary_chars(Q(char_class__iexact = char_class)
                                            | Q(char_class__iexact = "sorceress"))
            else:
                members = Character.primary_chars(char_class__iexact = char_class)

            count = members(server = ctx.message.guild.id).count()
            rows = get_row(members(server = ctx.message.guild.id), False)

            data = tabulate(rows,
                            HEADERS,
                            'simple',)
            for page in paginate("Total Number of " + char_class + " on this server: " + str(count) + "\n\n" + data):
                await send_or_display(ctx.message.guild.id, ctx.message.author, ctx, page)

        except Exception as e:
            print_error(e)
            await ctx.send("Something went horribly wrong")
Example #3
0
    async def delete(self, ctx, fam_name=''):
        """Deletes users's main character from list. **officers can add an optional family name at the
        end to delete a certain user"""

        try:
            author = ctx.message.author
            if not fam_name:
                member = Character.primary_chars(member=author.id).first()
            else:
                member = Character.primary_chars(
                    fam_name__icontains=fam_name,
                    server=ctx.message.guild.id).first()
                roles = [u.name for u in author.roles]
                if ADMIN_USER not in roles:
                    await ctx.send("Only officers may perform this action")
                    return
            member.delete()
            info = [["Success Deleting User"], ["Character", member.char_name],
                    ["Family", member.fam_name]]
            logActivity(
                'Character {} has been deleted'.format(member.char_name),
                author.name)
            await ctx.send(codify(tabulate(info)))
        except Exception as e:
            print_error(e)
            await ctx.send(codify("Error deleting user"))
Example #4
0
    async def __get_member(self, author, user, server_id, ctx):
        author_roles = [u.name for u in author.roles]
        if not user:
            character = Character.primary_chars(member=author.id, server=server_id).first()
            rank = 'Officer' if ADMIN_USER in author_roles else 'Member'
        else:
            character = Character.primary_chars(member=user.id, server=server_id).first()
            rank = character.rank
            if ADMIN_USER not in author_roles:
                await ctx.send("Only officers may perform this action")
                return

        return (rank, character)
Example #5
0
    async def export(self, ctx):
        """Exports current guild data"""

        members = Character.primary_chars(server=ctx.message.server.id)
        rows = get_row(members, False)
        rows.insert(0, HEADERS)
        try:
            with open('./members.csv', 'w') as myfile:
                wr = csv.writer(myfile)
                wr.writerows(rows)

            if is_officer_mode(ctx.message.server.id):
                if is_user_officer(ctx.message.author.roles):
                    await self.bot.send_file(
                        ctx.message.author,
                        'members.csv',
                        content=codify('Member info attached'))
                    await self.bot.say(
                        codify('File sent. Please check your private messages')
                    )
                    return
                else:
                    await self.bot.say(codify(OFFICER_MODE_MESSAGE))
                    return
            await self.bot.upload('./members.csv')
        except Exception as e:
            print_error(e)
            await self.bot.say(codify('Could not export data'))
Example #6
0
    async def attach_pic(self, ctx, url: str = None):
        """
        Command to attach a picture to your character.
        When someone looks you up, the attached picture is displayed
        """
        try:
            author = ctx.message.author
            attachments = ctx.message.attachments
            character = Character.primary_chars(member=author.id).first()
            if not character:
                await ctx.send(
                    'Could not find a main character for user {}'.format(
                        author.name))
                return

            if url:
                response = upload(url, tags=PIC_TAG)
            else:
                if not attachments:
                    await ctx.send(
                        'You must either attach a picture or provide a url')
                    return
                response = upload(attachments[0].url, tags=PIC_TAG)

            character.gear_pic = response['url']
            character.save()
            logActivity(
                '{} has updated picture for {}'.format(
                    character.fam_name.title(), character.char_name),
                ctx.message.author.name)
            await ctx.send(codify("Picture added successfully"))
        except Exception as e:
            print(e)
            await ctx.send("Picture could not be added")
Example #7
0
    async def under(self, ctx, num=400):
        """List all the main characters under a certain gear score"""
        try:
            members = Character.primary_chars(gear_score__lte = num, server = ctx.message.server.id)
            rows = get_row(members, False)
            data = tabulate(rows,
                            HEADERS,
                           'simple',)

            for page in paginate(data):
                await send_or_display(ctx.message.server.id, ctx.message.author, self.bot, page)
        except Exception as e:
            print_error(e)
            await self.bot.say("Something went horribly wrong")
Example #8
0
    async def ap(self, ctx, num=100):
        """ - Sorts list by AP with optional limit"""
        try:
            members = Character.primary_chars(server=ctx.message.server.id).order_by('-ap')
            rows = get_row(members, True, num)

            data = tabulate(rows,
                            HEADERS,
                            'simple',)

            for page in paginate(data):
                await send_or_display(ctx.message.server.id, ctx.message.author, self.bot, page)
        except Exception as e:
            await self.bot.say("Could not retrieve list")
            print_error(e)
Example #9
0
    async def list(self,ctx,num=100):
        """List all the main characters and their gear score with optional limit.
        Example. gsbot list returns first 100 by default  and gsbot list 5 first 5 sorted by
        gear score"""
        try:
            members = Character.primary_chars(server=ctx.message.server.id)
            rows = get_row(members, True, num)

            data = tabulate(rows,
                            HEADERS,
                           'simple',)
            
            for page in paginate(data):
                await send_or_display(ctx.message.server.id, ctx.message.author, self.bot, page)
        except Exception as e:
            await self.bot.say(codify('Could not list members'))
            print_error(e)
Example #10
0
    async def fame(self, ctx, num=100):
        """ - Sorts list by Fame (as it relates to renown score) with optional limit"""
        try:
            members = Character.primary_chars(
                server=ctx.message.guild.id).order_by('-fame')
            rows = get_row(members, True, num)
            data = tabulate(
                rows,
                HEADERS,
                'simple',
            )

            for page in paginate(data):
                await send_or_display(ctx.message.guild.id, ctx.message.author,
                                      ctx, page)
        except Exception as e:
            await ctx.send(codify("Could not retrieve list"))
            print_error(e)
Example #11
0
    async def lvl(self, ctx, num=100):
        """ - Sorts list by level and progress with optional limiter"""
        try:
            members = Character.primary_chars(
                server=ctx.message.guild.id).order_by('-level', '-progress')
            rows = get_row(members, True, num)

            data = tabulate(
                rows,
                HEADERS,
                'simple',
            )

            for page in paginate(data):
                await send_or_display(ctx.message.guild.id, ctx.message.author,
                                      ctx, page)
        except Exception as e:
            await ctx.send("Could not retrieve list")
            print_error(e)
Example #12
0
    async def info(self, ctx):
        """List important gear score info. Lowest, highest_gs, average, newest(not yet), oldest,
        total users, total officers, total members"""

        try:
            info = []
            members = Character.primary_chars(server=ctx.message.server.id)
            if members:
                officers = members(rank='Officer')
                average_gs = members.average('gear_score')
                lowest_gs = members.order_by('+gear_score').first()
                highest_gs = members.first()
                count = members.count()
                officer_count = officers.count()
                member_count = count - officer_count
                info.append([' Gear Score '])
                info.append(['-------------------------'])
                info.append(['Average', round(average_gs, 2)])
                info.append([
                    'Lowest', lowest_gs.gear_score,
                    lowest_gs.fam_name.title(),
                    lowest_gs.char_name.title()
                ])
                info.append([
                    'Highest', highest_gs.gear_score,
                    highest_gs.fam_name.title(),
                    highest_gs.char_name.title()
                ])
                info.append([''])
                info.append(['-------------------------'])
                info.append(['Counts '])
                info.append(['-------------------------'])
                info.append(['Total Officers', officer_count])
                info.append(['Total Members', member_count])
                info.append(['Guild Total', count])
                data = tabulate(info)
            else:
                data = "No members yet to display info. Try adding some members :D"

            await self.bot.say(codify(data))
        except Exception as e:
            print(e)
            await self.bot.say("Could not retrieve info")
Example #13
0
    async def add(self,
                  ctx,
                  fam_name,
                  char_name,
                  level: int,
                  ap: int,
                  aap: 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.
        **Officers can add a user by tagging them at the end. eg @drawven**
        Note: Total gear score, renown score, and rank are auto calculated."""

        # Checks character name to make sure it is correct
        try:

            if not await check_character_name(self.bot, char_class):
                return
            author = ctx.message.author
            discord_server = ctx.message.server
            roles = [u.name for u in author.roles]
            rank, discord_user = await self.__get_rank_and_member(
                author, user, roles)
            server, member = self.__get_server_and_member(
                discord_server, discord_user)

            if rank is None or discord_user.id is None:
                return

            character = Character.primary_chars(member=discord_user.id).first()
            isPrimary = False if character else True

            character = Character.create({
                'rank':
                rank,
                'fam_name':
                fam_name.upper(),
                'char_name':
                char_name.upper(),
                'char_class':
                char_class.upper(),
                'server':
                discord_server.id,
                'level':
                level,
                'ap':
                ap,
                'aap':
                aap,
                'dp':
                dp,
                'gear_score':
                max(aap, ap) + dp,
                'renown_score':
                math.trunc((ap + aap) / 2 + dp),
                'primary':
                isPrimary,
                'member':
                discord_user.id,
            })
            member.characters.append(character)
            member.save()

            row = get_row([character], False)
            data = tabulate(row, HEADERS, 'simple')
            logActivity('{} has added a character'.format(character.fam_name),
                        user.name if user else author.name)
            await self.bot.say(
                codify("Success Adding Character for member {} :D\n\n".format(
                    discord_user.name.upper()) + data))

        except Exception as e:
            print_error(e)
            await self.bot.say("Something went horribly wrong")
Example #14
0
    async def reroll(self, ctx, new_char_name, level: int, ap: int, aap: int,
                     dp: int, new_char_class):
        """Just for someone special: Allows you to reroll your main character """

        author = ctx.message.author.id
        character = Character.primary_chars(member=author).first()
        date = datetime.now()
        if not character:
            await self.bot.say(
                "Can't reroll if you're not in the database :(, try adding a character first"
            )
            return

        if not await check_character_name(self.bot, new_char_class):
            return

        else:
            try:
                ## Adds historical data to database
                update = Historical.create({
                    'type':
                    "reroll",
                    'char_class':
                    character.char_class.upper(),
                    'timestamp':
                    date,
                    'level':
                    float(
                        str(character.level) + '.' +
                        str(round(character.progress))),
                    'ap':
                    character.ap,
                    'aap':
                    character.aap,
                    'dp':
                    character.dp,
                    'gear_score':
                    character.gear_score,
                    'renown_score':
                    character.renown_score,
                })

                historical_data = character.hist_data
                fame = character.fame or 0
                historical_data.append(update)

                character.update_attributes({
                    'char_name':
                    new_char_name.upper(),
                    'ap':
                    ap,
                    'aap':
                    aap,
                    'dp':
                    dp,
                    'level':
                    level,
                    'gear_score':
                    max(aap, ap) + dp,
                    'renown_score':
                    math.trunc((ap + aap) / 2 + dp) + fame,
                    'char_class':
                    new_char_class.upper(),
                    'updated':
                    date,
                    'hist_data':
                    historical_data
                })

                row = get_row([character], False)
                data = tabulate(row, HEADERS, 'simple')

                logActivity(
                    '{} has rerolled a character'.format(character.fam_name),
                    ctx.message.author.name)
                reminder = '\n\nRemember to add a new pic with gsbot attach_pic!'
                await self.bot.say(
                    codify("Success Rerolling\n\n" + data + reminder))

            except Exception as e:
                print_error(e)
                await self.bot.say("Could not reroll")