Beispiel #1
0
    async def notify_member_gain(self, message: discord.Message,
                                 member: discord.Member) -> None:
        """
        notify the member that he gained karma, configureable through configuration.
        :param message: the discord message, used to link to the message.
        :param member: the member to notify, if applicable.
        :return: None
        """
        if str(karma()['log']).lower() == 'true':
            log_message = '{}{} earned karma in {}. {}'.format(
                member.name + '#' + member.discriminator,
                f' ({member.nick})' if member.Nick is not None else '',
                message.channel.mention, message.jump_url)

            log_channel = self.bot.get_channel(int(config['channel']['log']))
            log_channel.send(log_message)

        if str(karma()['message']).lower() == 'true':
            result = f'Congratulations {member.mention}, you have earned karma from {member.author.mention}. '

            if str(karma()['self_delete']).lower() == 'true':
                result += revoke_message.format(message.author.mention)

            message_channel = self.bot.get_channel(message.channel.id)
            await message_channel.send(result)

        if str(karma()['emote']).lower() == 'true':
            await message.add_reaction(reaction_emoji()['karma_gain'])
            if str(karma()['self_delete']).lower() == 'true':
                await message.add_reaction(reaction_emoji()['karma_delete'])
Beispiel #2
0
    def create_feedback_fields(self, embed):
        emoji = reaction_emoji()

        def update_fmt(config_key, msg, emoji_key, fb=''):
            if str(config_key).lower() == 'true':
                fb += msg.format(emoji[emoji_key])
                return fb

        def update(config_key, msg, fb=''):
            if str(config_key).lower() == 'true':
                fb += msg
                return fb

        feedback = update_fmt(karma()['emote'],
                              'Aura will react with a {} to verify that you have given out karma. \n',
                              'karma_gain', '')

        feedback = update_fmt(karma()['time_emote'],
                              'Aura will react with a {} to show that at least one user is on a cooldown with you. \n',
                              'karma_cooldown', feedback)

        feedback = update_fmt(karma()['self_delete'],
                              'Aura will react with a {} for you to revert giving out the karma, by reacting to it.\n',
                              'karma_delete', feedback)

        feedback = update_fmt(blacklist()['emote'],
                              'Aura will react with a {} if you are blacklisted from giving out karma. \n',
                              'karma_blacklist', feedback)

        feedback = update(karma()['message'],
                          'Aura will congratulate the user(s) in chat.\n',
                          feedback)

        feedback = update(karma()['time_message'],
                          'Aura will remind you of the cooldown in the chat.\n',
                          feedback)

        feedback = update(blacklist()['dm'],
                          'Aura will contact you privately, if you are blacklisted.\n',
                          feedback)

        feedback = update(blacklist()['edit'],
                          'Aura will add karma, if message was not a valid karma message before editing it.\n' +
                          'Aura will remove karma, if message is not a valid karma message after editing it.',
                          feedback)

        embed.add_field(name='**Aura Feedback**', value=feedback)
        return embed
Beispiel #3
0
 async def on_message_edit(self, before: discord.Message,
                           after: discord.Message) -> None:
     """
     Will remove and add karma according to the state of the message before and afterwards.
     :param before: discord message before the edit
     :param after: discord message after the edit
     :return: None
     """
     if str(karma()["edit"]).lower() == "true":
         before_valid = await validate_message(before)
         after_valid = await validate_message(after)
         if before_valid and after_valid:
             print(
             )  # TODO implement search on message id to find all members thanked
         elif before_valid and not after_valid:
             # remove karma given out through karma message.
             log.info(
                 f"Removing karma because message: {after.id} not valid after edit"
             )
             await after.clear_reactions()
             await self.remove_karma(before, after.guild, "message edit")
         elif after_valid and not before_valid:
             # all new karma to give out
             log.info(
                 f"Adding karma because message: {after.id} is valid after edit"
             )
             await self.give_karma(after, after.guild)
Beispiel #4
0
 async def log_karma_removal(self, message: discord.Message,
                             member: discord.Member,
                             event_type: str) -> None:
     """
     log the karma removal of a user in a channel.
     :param message: the discord message which triggered the removal, can be None.
     :param member: the discord member whose removal is to be logged.
     :param event_type: the reason for the deletion
     :return: None
     """
     if karma()["log"]:
         if event_type == "message delete":
             await self.bot.get_channel(int(config["channel"]["log"])).send(
                 "karma for {} was removed through event: {} :: in {}".
                 format(
                     member.name + "#" + member.discriminator,
                     event_type,
                     message.channel.mention,
                 ))
         else:
             await self.bot.get_channel(int(config["channel"]["log"])).send(
                 "karma for {} was removed through event: {} :: in {} :: {}"
                 .format(
                     member.name + "#" + member.discriminator,
                     event_type,
                     message.channel.mention,
                     message.jump_url,
                 ))
Beispiel #5
0
 async def on_reaction_add(self, reaction: discord.Reaction,
                           user: discord.User) -> None:
     """
     If the karma deletion is set, will remove all karma gained through the message,
     if the message author clicks it and then remove all reactions on the message
     :param reaction: reaction which was clicked
     :param user: user who added the reaction
     :return: None
     """
     if (self.karma_service.find_message(str(
             reaction.message.id)) is not None
             and reaction.message.author.id == user.id and reaction.me):
         if reaction.emoji == reaction_emoji()["karma_delete"]:
             if str(karma()["self_delete"]).lower() == "true":
                 log.info(
                     "Removing karma because the karma_delete emoji was clicked by author"
                 )
                 for other_reaction in reaction.message.reactions:
                     await clear_reaction(other_reaction)
                 await self.remove_karma(reaction.message,
                                         reaction.message.guild,
                                         "self emoji clear")
         elif reaction.emoji == reaction_emoji()["karma_gain"]:
             log.info(
                 "Removing other aura emoji because gain was clicked by author"
             )
             for other_reaction in reaction.message.reactions:
                 if reaction is not other_reaction:
                     await clear_reaction(other_reaction)
Beispiel #6
0
    async def on_reaction_add(self, reaction: discord.Reaction,
                              user: discord.User) -> None:
        """
        If the karma deletion is set, will remove all karma gained through the message,
        if the message author clicks it and then remove all reactions on the message
        :param reaction: reaction which was clicked
        :param user: user who added the reaction
        :return: None
        """
        if self.karma_service.find_message(str(reaction.message.id)) is None or \
                reaction.message.author.id != user.id or \
                not reaction.me:
            return

        if reaction.emoji == reaction_emoji()['karma_delete']:
            if str(karma()['self_delete']).lower() != 'true':
                return

            log.info(
                'Removing karma because the karma_delete emoji was clicked by author'
            )
            for other_reaction in reaction.message.reactions:
                await clear_reaction(other_reaction)

            await self.remove_karma(reaction.message, reaction.message.guild,
                                    'self emoji clear')
            return

        log.info('Removing aura emojis because gain was clicked by author')
        for other_reaction in reaction.message.reactions:
            if reaction is not other_reaction:
                await clear_reaction(other_reaction)
Beispiel #7
0
 def create_feedback_fields(self, embed):
     feedback = ""
     emoji = reaction_emoji()
     if str(karma()["emote"]).lower() == "true":
         feedback += "Aura will react with a {} to verify that you have given out karma. \n".format(
             emoji["karma_gain"]
         )
     if str(karma()["time-emote"]).lower() == "true":
         feedback += "Aura will react with a {} to show that at least one user is on a cooldown with you. \n".format(
             emoji["karma_cooldown"]
         )
     if str(karma()["self_delete"]).lower() == "true":
         feedback += "Aura will react with a {} for you to revert giving out the karma, by reacting to it.\n".format(
             emoji["karma_delete"]
         )
     if str(blacklist()["emote"]).lower() == "true":
         feedback += "Aura will react with a {} if you are blacklisted from giving out karma. \n".format(
             emoji["karma_blacklist"]
         )
     if str(karma()["message"]).lower() == "true":
         feedback += "Aura will congratulate the user/s in chat.\n"
     if str(karma()["time-message"]).lower() == "true":
         feedback += "Aura will remind you of the cooldown in the chat.\n"
     if str(blacklist()["dm"]).lower() == "true":
         feedback += "Aura will contact you privately, if you are blacklisted.\n"
     if str(karma()["edit"]).lower() == "true":
         feedback += "Aura will add karma, if message was not a valid karma message before editing it.\n"
         feedback += "Aura will remove karma, if message is not a valid karma message after editing it."
     embed.add_field(name="**Aura Feedback**", value=feedback)
     return embed
Beispiel #8
0
 async def notify_member_gain(self, message: discord.Message,
                              member: discord.Member) -> None:
     """
     notify the member that he gained karma, configureable through configuration.
     :param message: the discord message, used to link to the message.
     :param member: the member to notify, if applicable.
     :return: None
     """
     if str(karma()["log"]).lower() == "true":
         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,
                     message.jump_url,
                 ))
         else:
             await self.bot.get_channel(int(config["channel"]["log"])).send(
                 "{} ({}) earned karma in {}. {}".format(
                     member.name + "#" + member.discriminator,
                     member.nick,
                     message.channel.mention,
                     message.jump_url,
                 ))
     if str(karma()["message"]).lower() == "true":
         if str(karma()["self_delete"]).lower() == "true":
             await self.bot.get_channel(
                 message.channel.id
             ).send("Congratulations {}, you have earned karma from {}. ".
                    format(member.mention, message.author.mention) +
                    revoke_message.format(message.author.mention))
         else:
             await self.bot.get_channel(message.channel.id).send(
                 "Congratulations {}, you have earned karma from {}.".
                 format(member.mention, message.author.mention))
     if str(karma()["emote"]).lower() == "true":
         await message.add_reaction(reaction_emoji()["karma_gain"])
         if str(karma()["self_delete"]).lower() == "true":
             await message.add_reaction(reaction_emoji()["karma_delete"])
Beispiel #9
0
    async def log_karma_removal(
            self, message: discord.Message, member: discord.Member,
            event_type: str) -> None:  # TODO change event_type to enum
        """
        log the karma removal of a user in a channel.
        :param message: the discord message which triggered the removal, can be None.
        :param member: the discord member whose removal is to be logged.
        :param event_type: the reason for the deletion
        :return: None
        """
        if not karma()['log']:
            return

        result = f'karma for {member.name + "#" + member.discriminator} was removed through event: ' + \
                 f'{event_type} "" in {message.channel.mention}'
        if event_type == 'message delete':
            await self.bot.get_channel(int(config['channel']['log'])
                                       ).send(result)
            return

        result += f" :: {message.jump_url}"
        await self.bot.get_channel(int(config['channel']['log'])).send(result)