コード例 #1
0
    async def profile(self, ctx, *, args="") -> None:
        """
        Return the karma profile of a member or self if no arguments.
        :param ctx: context of the invocation
        :param args: args provided to profile command, only take the first one.
        :return: None
        """
        if len(args) == 0:
            karma_member = KarmaMember(ctx.guild.id, ctx.message.author.id)
            embed = await self.build_profile_embed(karma_member, ctx.guild)
            if ctx.message.author.nick is None:
                embed.title = "Profile of {}".format(
                    ctx.message.author.name + "#" +
                    ctx.message.author.discriminator)
            else:
                embed.title = "Profile of {}".format(ctx.message.author.nick)
            embed.set_thumbnail(url=ctx.author.avatar_url)

            await ctx.channel.send(embed=embed)
        else:
            member_list = args.split()
            member_id = member_list[0]
            member_set = await convert_content_to_member_set(ctx, [member_id])
            for member in member_set:
                karma_member = KarmaMember(ctx.guild.id, member.id)
                embed = await self.build_profile_embed(karma_member, ctx.guild)
                if member.nick is None:
                    embed.title = "Profile of {}".format(member.name + "#" +
                                                         member.discriminator)
                else:
                    embed.title = "Profile of {}".format(member.nick)
                embed.set_thumbnail(url=member.avatar_url)
                await ctx.channel.send(embed=embed)
コード例 #2
0
 async def karma(self, ctx, *, args="") -> None:
     """
     Return the karma of all members provided to the karma command or self if no arguments.
     :param ctx: context of the invocation
     :param args: members to print the karma in the channel
     :return: None
     """
     return_msg = ""
     if len(args) == 0:
         karma_member = KarmaMember(ctx.guild.id, ctx.message.author.id)
         karma = self.karma_service.aggregate_member_by_karma(karma_member)
         if karma is None:
             return_msg += "{} has earned a total of {} karma\n".format(
                 ctx.message.author.name + "#" +
                 ctx.message.author.discriminator, 0)
         else:
             return_msg += "{} has earned a total of {} karma".format(
                 ctx.message.author.name + "#" +
                 ctx.message.author.discriminator,
                 karma,
             )
     else:
         member_set = await convert_content_to_member_set(ctx, args.split())
         for member in member_set:
             karma_member = KarmaMember(ctx.guild.id, member.id)
             karma = self.karma_service.aggregate_member_by_karma(
                 karma_member)
             if karma is None:
                 return_msg += "{} has earned a total of {} karma\n".format(
                     member.name + "#" + member.discriminator, 0)
             else:
                 return_msg += "{} has earned a total of {} karma\n".format(
                     member.name + "#" + member.discriminator, karma)
     await ctx.channel.send(return_msg)
コード例 #3
0
 async def remove_karma(self, message: discord.Message,
                        guild: discord.Guild, reason: str) -> None:
     """
     remove karma from everyone that is in the set of mentions of the message,
     providing a reason for the deletion.
     :param message: message to remove karma from
     :param guild: guild of the message
     :param reason: reason for deleting the karma (event_type)
     :return: None
     """
     # walk through the mention list which contains discord: Members
     for mention in set(message.mentions):
         member = mention
         karma_member = KarmaMember(guild.id, member.id, message.channel.id,
                                    message.id, 1)
         deletion_result = self.karma_service.delete_single_karma(
             karma_member)
         if deletion_result.deleted_count == 1:
             single_action_timer: KarmaSingleActionTimer = self._running_timers[
                 guild.id][message.author.id][member.id]
             if single_action_timer is not None and single_action_timer.is_started:
                 await single_action_timer.stop()
                 del self._running_timers[guild.id][message.author.id][
                     member.id]
                 self._members_on_cooldown[guild.id][
                     message.author.id].remove(member.id)
         await self.log_karma_removal(message, member, reason)
コード例 #4
0
 async def reset(self, ctx, *, args: str) -> None:
     """
     reset karma of the users provided to the command, both mentions and ids are valid.
     :param ctx: context of the invocation
     :param args: members provided to reset karma
     :return: None
     """
     # convert args to discord.Member
     member_set = await convert_content_to_member_set(ctx, args.split())
     for member in member_set:
         if member_has_role(
                 member,
                 roles()["admin"]) and ctx.message.author.id != int(
                     config["owner"]):
             await ctx.channel.send(
                 "You cannot reset the karma of an admin.")
         else:
             if member_has_role(
                     member,
                     roles()["moderator"]) and not member_has_role(
                         ctx.message.author,
                         roles()["admin"]):
                 await ctx.channel.send(
                     "Only admins can reset the karma of an moderator.")
             else:
                 self.karma_service.delete_all_karma(
                     KarmaMember(ctx.guild.id, member.id))
                 await ctx.channel.send("Removed all Karma from {}".format(
                     member.mention))
コード例 #5
0
ファイル: profile.py プロジェクト: hhhapz/aura
    async def karma(self, ctx, *, args='') -> None:
        """
        Return the karma of all members provided to the karma command or self if no arguments.
        :param ctx: context of the invocation
        :param args: members to print the karma in the channel
        :return: None
        """
        result = ''
        members = [KarmaMember(ctx.guild.id, ctx.message.author.id)]
        if len(args) != 0:
            members = await convert_content_to_member_set(ctx, args.split())

        for member in members:
            karma_member = KarmaMember(ctx.guild.id, member.id)
            karma = self.karma_service.aggregate_member_by_karma(karma_member)
            result += '{} has earned a total of {} karma\n'.format(
                member.name + '#' + member.discriminator,
                0 if karma is None else karma)

        await ctx.channel.send(result)
コード例 #6
0
ファイル: profile.py プロジェクト: ianagbip1oti/aura
 async def profile(self, ctx):
     guild_id: str = str(ctx.message.guild.id)
     guild = self.bot.get_guild(int(guild_id))
     if len(ctx.message.mentions) == 0:
         karma_member = KarmaMember(guild_id, ctx.message.author.id)
         embed = await self.build_profile_embed(karma_member, guild)
         embed.title = "Profile of {}".format(
             ctx.message.author.name + "#" +
             ctx.message.author.discriminator)
         embed.set_thumbnail(url=ctx.author.avatar_url)
         await ctx.channel.send(embed=embed)
     elif len(ctx.message.mentions) == 1:
         message = ctx.message
         member = message.mentions[0]
         if not self.bot.get_user(self.bot.user.id).mentioned_in(
                 message) and guild.get_member(
                     member.id).mentioned_in(message):
             karma_member = KarmaMember(guild_id, member.id)
             embed = await self.build_profile_embed(karma_member, guild)
             embed.title = "Profile of {}".format(member.name + "#" +
                                                  member.discriminator)
             embed.set_thumbnail(url=member.avatar_url)
             await ctx.channel.send(embed=embed)
コード例 #7
0
ファイル: profile.py プロジェクト: ianagbip1oti/aura
 async def karma(self, ctx):
     guild_id: str = str(ctx.message.guild.id)
     guild = self.bot.get_guild(int(guild_id))
     message = ctx.message
     member = message.mentions[0]
     if not self.bot.get_user(
             self.bot.user.id).mentioned_in(message) and guild.get_member(
                 member.id).mentioned_in(message):
         karma_member = KarmaMember(guild_id, member.id)
         karma = self.karma_service.aggregate_member_by_karma(karma_member)
         if karma is None:
             await ctx.channel.send(
                 '{} has earned a total of {} karma'.format(
                     member.name + '#' + member.discriminator, 0))
         else:
             await ctx.channel.send(
                 '{} has earned a total of {} karma'.format(
                     member.name + '#' + member.discriminator, karma))
     elif len(ctx.message.mentions) == 0:
         karma_member = KarmaMember(guild_id, ctx.message.author.id)
         karma = self.karma_service.aggregate_member_by_karma(karma_member)
         await ctx.channel.send('{} has earned a total of {} karma'.format(
             ctx.message.author.name + '#' + ctx.author.discriminator,
             karma))
コード例 #8
0
 async def give_karma(self, message: discord.Message, guild: discord.Guild,
                      member: discord.Member, inc: bool):
     if guild.get_member(member.id).mentioned_in(message):
         karma_member = KarmaMember(guild.id, member.id, message.channel.id,
                                    message.id)
         self.karma_service.upsert_karma_member(karma_member, inc)
         if inc:
             if member.nick is None:
                 await self.bot.get_channel(
                     int(config['channel']['log'])
                 ).send('{} earned karma in {}'.format(
                     member.name + '#' + member.discriminator,
                     message.channel.mention))
             else:
                 await self.bot.get_channel(
                     int(config['channel']['log'])
                 ).send('{} ({}) earned karma in {}'.format(
                     member.name + '#' + member.discriminator, member.nick,
                     message.channel.mention))
         await self.cooldown_user(guild.id, message.author.id)
コード例 #9
0
class KarmaChange(unittest.TestCase):
    karma_source = mongomock.MongoClient().db.karma
    karma_service = KarmaMemberService(karma_source)
    karma_member = KarmaMember("1", "1", "1", "1")

    def test_karma_increased(self):
        self.karma_service.upsert_karma_member(self.karma_member)
        assert self.karma_service.aggregate_member_by_karma(
            self.karma_member) == 1
        self.karma_service.upsert_karma_member(self.karma_member)
        assert self.karma_service.aggregate_member_by_karma(
            self.karma_member) == 2
        for doc in self.karma_service.aggregate_member_by_channels(
                self.karma_member):
            assert doc["karma"] == 2

    def test_karma_reset(self):
        self.karma_service.delete_all_karma(self.karma_member)
        assert self.karma_service.aggregate_member_by_karma(
            self.karma_member) is None
コード例 #10
0
    async def reset(self, ctx, *, args: str) -> None:
        """
        reset karma of the users provided to the command, both mentions and ids are valid.
        :param ctx: context of the invocation
        :param args: members provided to reset karma
        :return: None
        """
        # convert args to discord.Member
        member_set = await convert_content_to_member_set(ctx, args.split())
        for member in member_set:
            if member_has_role(member, roles()['admin']) and ctx.message.author.id != int(config['owner']):
                await ctx.channel.send(f'Skipping {member.display_name}, You cannot reset the karma of an admin.')
                continue

            if member_has_role(member, roles()['moderator']) \
                    and not member_has_role(ctx.message.author, roles()['admin']):
                await ctx.channel.send(f'Skipping {member.display_name}, ' +
                                       'Only admins can reset the karma of an moderator.')
                continue

            self.karma_service.delete_all_karma(KarmaMember(ctx.guild.id, member.id))
            await ctx.channel.send(f'Removed all Karma for {member.mention}')
コード例 #11
0
ファイル: profile.py プロジェクト: hhhapz/aura
    async def profile(self, ctx, *, args='') -> None:
        """
        Return the karma profile of a member or self if no arguments.
        :param ctx: context of the invocation
        :param args: args provided to profile command, only take the first one.
        :return: None
        """
        author = ctx.message.author
        if len(args) != 0:
            member_id = args.split()[0]
            member_set = await convert_content_to_member_set(
                ctx.guild.id, [member_id])
            if len(member_set) == 0:
                return
            karma_member = member_set.pop()
        else:
            karma_member = KarmaMember(ctx.guild.id, author.id)

        embed = await self.build_profile_embed(karma_member, ctx.guild)
        embed.title = 'Profile of {}'.format(
            author.name + '#' +
            author.discriminator if author.nick is None else author.nick)
        await ctx.channel.send(embed=embed)
コード例 #12
0
 async def give_karma(self, message: discord.Message,
                      guild: discord.Guild) -> None:
     """
     give karma to all the users in the message except the author, other bots or aura itself
     :param message: message containing the mentions
     :param guild: guild of the karma message
     :return: None
     """
     # walk through the mention list which contains discord: Members
     for mention in set(message.mentions):
         member = mention
         # filter out message author, aura and other bots
         if (member.id != message.author.id
                 and member.id != self.bot.user.id
                 and not self.bot.get_user(member.id).bot):
             # check if giver-receiver combo on cooldown
             if (member.id not in self._members_on_cooldown[guild.id][
                     message.author.id]):
                 karma_member = KarmaMember(guild.id, member.id,
                                            message.channel.id, message.id)
                 self.karma_service.upsert_karma_member(karma_member)
                 await self.cooldown_user(guild.id, message.author.id,
                                          member.id)
                 await self.notify_member_gain(message, member)
                 log.info("{} gave karma to {} in guild {}".format(
                     message.author.id, member.id, guild.id))
             else:
                 log.info(
                     "Sending configured cooldown response to {} in guild {}"
                     .format(message.author.id, guild.id))
                 if str(config["karma"]["time-emote"]).lower() == "true":
                     await message.add_reaction(
                         reaction_emoji()["karma_cooldown"])
                 if str(config["karma"]["time-message"]).lower() == "true":
                     await self.bot.get_channel(message.channel.id).send(
                         "Sorry {}, your karma for {} needs time to recharge"
                         .format(message.author.mention, member.name))
コード例 #13
0
    async def give_karma(self, message: discord.Message,
                         guild: discord.Guild) -> None:
        """
        give karma to all the users in the message except the author, other bots or aura itself
        :param message: message containing the mentions
        :param guild: guild of the karma message
        :return: None
        """
        # walk through the mention list which contains discord: Members
        for member in set(message.mentions):
            # filter out message author, aura and other bots
            a_id = message.author.id
            m_id = member.id
            if m_id == a_id or m_id == self.bot.user.id or self.bot.get_user(
                    member).bot:
                continue

            # check if giver-receiver combo on cooldown
            if m_id in self._members_on_cooldown[guild.id][a_id]:
                log.info(
                    f'Sending configured cooldown response to {a_id} in guild {guild.id}'
                )
                if str(config['karma']['time-emote']).lower() == "true":
                    await message.add_reaction(
                        reaction_emoji()['karma_cooldown'])

                if str(config['karma']['time-message']).lower() == "true":
                    await self.bot.get_channel(message.channel.id) \
                        .send(f'Sorry {message.author.mention}, your karma for {member.name} needs time to recharge')
                continue

            karma_member = KarmaMember(guild.id, member.id, message.channel.id,
                                       message.id)
            self.karma_service.upsert_karma_member(karma_member)
            await self.cooldown_user(guild.id, message.author.id, member.id)
            await self.notify_member_gain(message, member)
            log.info(f'{a_id} gave karma to {m_id} in guild {guild.id}')
コード例 #14
0
 async def reset(self, ctx, member):
     guild_id: str = str(ctx.message.guild.id)
     self.karma_service.delete_all_karma(KarmaMember(guild_id, member))
     await ctx.channel.send('Removed all Karma from {}'.format(member))