Пример #1
0
    async def sub(self,
                  ctx,
                  method,
                  member: discord.Member,
                  points: int,
                  *,
                  message: str = None):
        if not await self.rep_cog_on(ctx):
            return
        if message is None:
            message = 'No additional information given.'

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        bot_spam = database.get_spam(ctx.guild)

        message = f'**{ctx.author.display_name}** removed {points} {method} point(s) from **{member.display_name}**.\n'\
                  f'> {message}'

        if method == 'pos':
            database.sub_pos(member, points)
            await bot_spam.send(embed=tools.single_embed(message))
            await self.assign_new_role(member)

        if method == 'neg':
            database.sub_neg(member, points)
            await bot_spam.send(embed=tools.single_embed_neg(message))

        await ctx.send(
            embed=tools.single_embed(f'Your changes have been updated.'))
Пример #2
0
 async def on_guild_join(self, guild):
     spam = await guild.system_channel
     msg = f'{self.client.user.display_name} has joined {guild.name}'
     await spam.send(embed=tools.single_embed(msg))
     database.add_guild(guild)
     for member in guild.members:
         database.add_member(member)
Пример #3
0
    async def on_message(self, message):
        try:
            # check message contents for keywords that indicate a user is being thanked
            if len(message.content) < 1:
                return
            if message.author.bot:
                return
            if message.guild is None:
                return
            if not database.karma_cog(message.guild):
                return
            keywords = ['thanks', 'thank', 'cheers', 'ty']
            msg = [word.lower() for word in message.content.split(' ') if word != '@everyone']

            # remove punctuation that prevent keywords from being recognized
            content = [''.join(character for character in word if character not in string.punctuation) for word in msg]
            mentioned_members = [member for member in message.guild.members if member.mentioned_in(message) and not member.bot and member != message.author]
            if len(mentioned_members) < 1:
                return
            if any(word in keywords for word in content):
                if await database.karma_too_soon(message):
                    pass
                else:
                    for member in mentioned_members:
                        if not database.in_members_table(member):
                            database.add_member(member)
                        database.add_karma(member, 1)
                        database.update_karma_timer(message.author)
                    msg = f':tada: {", ".join([f"**{m.display_name}**" for m in mentioned_members])} earned 1 karma'
                    embed = discord.Embed(color=discord.Color.blue(), description=msg)
                    await message.channel.send(embed=embed)
        except Exception as e:
            print('on message karma', e)
Пример #4
0
    async def assign_new_role(member: discord.Member):
        # send new role notifications to general
        chan = None
        channels = [c for c in member.guild.channels if 'general']
        for c in channels:
            if 'general' in c.name:
                chan = c
        if chan is None:
            chan = database.get_spam(member.guild)
        if not database.in_members_table(member):
            database.add_member(member)
        pos, neg = database.get_rep(member)

        with open('files/ranks.json') as f:
            ranks = json.load(f)["host ranks"]
        for rank, reviews in ranks.items():
            if pos >= reviews:
                if rank not in [role.name for role in member.guild.roles]:
                    await member.guild.create_role(name=rank, hoist=True)
                role = discord.utils.get(member.guild.roles, name=rank)
                if role.name not in [r.name for r in member.roles]:
                    await member.add_roles(role)
                    await chan.send(embed=tools.single_embed(
                        f':tada: {member.mention} has earned the **{role}** role!'
                    ))
Пример #5
0
    async def rep(self, ctx, member: discord.Member = None):
        if await self.can_bypass_cooldown(ctx):
            self.rep.reset_cooldown(ctx)
        if not await self.rep_cog_on(ctx):
            return
        turnip_emoji = self.client.get_emoji(694822764699320411)
        if turnip_emoji is None:
            turnip_emoji = ':star:'

        if member is None:
            member = ctx.author

        if not database.in_members_table(member):
            database.add_member(member)

        pos, neg = database.get_rep(member)
        reviews_given = database.get_reviews_given(member)
        reviewer_rank = await tools.get_reviewer_rank(reviews_given)
        last_reviewer, last_review = database.get_review(member)

        if pos + neg < 1:
            rating = 0
        else:
            rating = int(pos / (pos + neg) * 100)
        if rating == 0:
            stars = 'No Rating'
        elif rating < 30:
            stars = f'{turnip_emoji}'
        elif 30 <= rating < 50:
            stars = f'{turnip_emoji} ' * 2
        elif 50 <= rating < 70:
            stars = f'{turnip_emoji} ' * 3
        elif 70 <= rating < 90:
            stars = f'{turnip_emoji} ' * 4
        else:
            stars = f'{turnip_emoji} ' * 5

        host_rank = await tools.get_host_rank(member)

        msg = f'**Rating**: {stars}\n' \
              f'**Host Rank**: {host_rank}\n'\
              f'**Positive Reviews**: {pos}\n'\
              f'**Negative Reviews**: {neg}\n'\
              f'**Total Reviews**: {neg + pos}\n' \
              f'**Reviews Submitted**: {reviews_given} (rank: {reviewer_rank})\n\n'

        if last_reviewer is not None:
            reviewer = discord.utils.get(ctx.guild.members,
                                         id=int(last_reviewer))
            msg += f':tada: **Last Review from __{reviewer.display_name}__**\n' f'"{last_review}"'

        embed = discord.Embed(title=f'{member.display_name}',
                              color=member.color,
                              description=msg)
        embed.set_image(url=mae_banner)
        embed.set_thumbnail(url=member.avatar_url)
        await ctx.send(embed=embed)
Пример #6
0
async def get_host_rank(member):
    try:
        if not database.in_members_table(member):
            database.add_member(member)
        pos, neg = database.get_rep(member)

        with open('files/ranks.json') as f:
            ranks = json.load(f)["host ranks"]
        rank_list = []
        for rank, reviews in ranks.items():
            if pos >= reviews:
                role = discord.utils.get(member.guild.roles, name=rank)
                if role.name in [r.name for r in member.roles]:
                    rank_list.append(role.name)
        return rank_list[-1]
    except IndexError:
        return None
Пример #7
0
    async def pos(self, ctx, member: discord.Member, *, review: str = None):
        if await self.can_bypass_cooldown(ctx):
            self.pos.reset_cooldown(ctx)
        if not await self.rep_cog_on(ctx):
            return
        if ctx.author == member:
            msg = f'You cannot give yourself a review, {ctx.author.display_name}. *Snort!*'
            await ctx.send(embed=tools.single_embed(msg), delete_after=15)
            return

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        database.add_pos(member)
        pos, neg = database.get_rep(member)

        message = f'**{member.display_name}** gained 1 positive review from **{ctx.author.display_name}**!\n\n'
        if review is None:
            review = f'Sadly, {ctx.author.display_name} did not leave a message. :pig: *Snort!*'
        message += f'**{ctx.author.display_name}** said: \n"{review}"'

        database.add_review(member, ctx.author, review)
        database.add_reviews_given(ctx.author)

        # create embed and post it in the review channel
        embed = discord.Embed(color=discord.Color.green(), description=message)
        embed.set_thumbnail(url=member.avatar_url)
        time = tools.format_date_long(datetime.now())
        embed.set_footer(
            text=f'{member.display_name} now has {pos} positive reviews! {time}'
        )
        review_chan = database.get_review_channel(ctx.guild)
        await review_chan.send(embed=embed)

        await self.assign_new_role(member)

        # notify the user if the current channel is not the review channel
        if ctx.channel.id != review_chan.id:
            await ctx.send(embed=tools.single_embed(
                f'Thank you, **{ctx.author.display_name}**!\n'
                f'Your review has been received and posted in '
                f'{review_chan.mention}.'))

        await ctx.message.delete()
Пример #8
0
    async def on_member_join(self, member):
        # add member to the database
        database.add_member(member)

        # if admin cog is not set, do not give autorole
        if not database.admin_cog(member.guild):
            return
        autorole = database.get_autorole(member.guild)
        if autorole is not None:
            try:
                await member.add_roles(autorole)
                spam = database.get_spam(member.guild)
                msg = f'{member.display_name} was given the role {autorole.name}'
                await spam.send(embed=tools.single_embed(msg))
                print(
                    f'* Giving {member.display_name} the autorole {autorole.name}'
                )
            except Exception as e:
                spam = database.get_spam(member.guild)
                msg = f'Unable to give {member.display_name} the role {autorole.name}'
                await spam.send(embed=tools.single_embed(msg))
                print(
                    f'* Unable to give {member.display_name} the role {autorole.name}: {e}'
                )

        # store nickname
        nicknames = [n[0] for n in database.get_member_nick_history(member)]
        if member.name not in nicknames:
            database.add_member_nick_history(member, member.name)

        # update the server statistics
        try:
            member_stats = self.client.get_channel(706099708434841621)
            members = [m for m in member.guild.members if not m.bot]
            await member_stats.edit(name=f'Members: {len(members)}')
        except Exception as e:
            print(f'Could not update server stats: {e}')

        # alert general on every 1000th member
        if len([m for m in member.guild.members if not m.bot]) % 1000 == 0:
            chan = self.client.get_channel(694013862667616310)
            msg = f'Welcome {member.mention} as our {len(member.guild.members)}th member!'
            await chan.send(embed=tools.single_embed(msg))
Пример #9
0
    async def reset(self, ctx, member: discord.Member, *, message: str = None):
        if not await self.rep_cog_on(ctx):
            return
        if message is None:
            message = 'No additional information given.'

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        pos, neg = database.get_rep(member)
        database.reset(member)

        # staff_support_channel = self.client.get_channel(694036188813721610)
        staff_support_channel = database.get_administrative(ctx.guild)
        await staff_support_channel.send(embed=tools.single_embed(
            f'**{ctx.author.display_name}** reset '
            f'**{member.display_name}\'s** reviews to 0.\n'
            f'{member.display_name}\'s original score was {pos} pos and {neg} neg.\n'
            f'Log: {message}'))
Пример #10
0
    async def neg(self, ctx, member: discord.Member, *, message: str):
        # take message from user and send to staff support
        if await self.can_bypass_cooldown(ctx):
            self.neg.reset_cooldown(ctx)
        if not await self.rep_cog_on(ctx):
            return
        if ctx.author == member:
            msg = f'You cannot give yourself a review, {ctx.author.display_name}. :pig: *squee!*'
            await ctx.send(embed=tools.single_embed(msg))
            await ctx.message.delete()
            return
        # if len(ctx.message.attachments) < 1:
        #     msg = f'Your negative review is incomplete. Please attach a screenshot or picture verifying your claim.'
        #     await ctx.author.send(embed=tools.single_embed(msg))
        #     await ctx.message.delete()
        #     return

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        database.add_neg(member)
        database.add_reviews_given(ctx.author)

        staff_support_channel = database.get_administrative(ctx.guild)
        msg = f'**{member.display_name}** gained 1 negative review from '\
              f'**{ctx.author.display_name}**.\n\n'\
              f'**{ctx.author.display_name}** said:\n "{message}"'

        embed = discord.Embed(color=discord.Color.red(), description=msg)
        try:
            img = ctx.message.attachments[0].url
            embed.set_image(url=img)
        except IndexError:
            pass
        embed.set_thumbnail(url=member.avatar_url)
        await staff_support_channel.send(embed=embed)

        msg = f'Your review has been submitted and forwarded to staff. Thank you.'
        await ctx.send(embed=tools.single_embed_neg(msg), delete_after=30)
        await ctx.message.delete()
Пример #11
0
    async def top_reviewers(self, ctx):
        """ return a leaderboard with the top 10 karma leaders. If the requesting member is not in the top 10,
        their place will be added to the bottom of the leaderboard
        """
        if await self.can_bypass_cooldown(ctx):
            self.repboard.reset_cooldown(ctx)
        if not await self.rep_cog_on(ctx):
            return
        # turnip_emoji = self.client.get_emoji(694822764699320411)

        array = {}
        for member in ctx.guild.members:
            if member.bot:
                continue
            if not database.in_members_table(member):
                database.add_member(member)
            reviews_given = database.get_reviews_given(member)
            array[member.display_name] = reviews_given

        # sort users by most to least rep
        counter = 1
        leaderboard = []
        append_author = ''
        sorted_rep = OrderedDict(
            reversed(sorted(array.items(), key=lambda x: x[1])))
        for member, reviews in sorted_rep.items():
            reviewer_rank = await tools.get_reviewer_rank(reviews)
            msg = f'{counter}: **{member}** (*{reviewer_rank}*) - `{reviews}` points '
            leaderboard.append(msg)
            if ctx.author.display_name == member and counter > 10:
                append_author = f'\n----------------\n{counter}: **{member}** (*{reviewer_rank}*) - `{reviews}` points '
            counter += 1

        embed = discord.Embed(color=discord.Color.blue())
        embed.add_field(name=f'Top Reviewers :star:',
                        value='\n'.join(leaderboard[:10]) + append_author)
        embed.set_image(url=mae_banner)
        # embed.set_thumbnail(url="https://i.imgur.com/wl2MZIV.png")
        await ctx.send(embed=embed)