Exemple #1
0
  async def add_filter_emoji(self, ctx: commands.Context, emoji: Union[int, discord.Emoji, discord.PartialEmoji, str]):
    await general_util.delete_message(self.bot, ctx)

    if isinstance(emoji, int):
      emoji = general_util.get_emoji_from_id(general_util.emoji_id_from_emoji(emoji), ctx.guild, self.bot)
      if emoji is None:
        return await ctx.send(embed=general_util.generate_error_message(Strings.karma_invalid_emoji), delete_after=Config.base_error_duration)

    reposter = self.repost_settings_repo.get_repost_settings(ctx.guild.id)
    if reposter is None:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_no_reposter), delete_after=Config.base_error_duration)

    emoji_ids = reposter.emoji_ids.split(";") if reposter.emoji_ids is not None else []
    if len(emoji_ids) >= Config.reposter_filter_emoji_limit:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_add_filter_emoji_limit_reached), delete_after=Config.base_error_duration)

    emoji_id = general_util.emoji_id_from_emoji(emoji)

    if emoji_id in emoji_ids:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_add_filter_emoji_emoji_already_added), delete_after=Config.base_error_duration)

    emoji_ids.append(emoji_id)
    emoji_ids_string = ";".join(emoji_ids)
    reposter.emoji_ids = emoji_ids_string
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_add_filter_emoji_success", emoji=emoji)), delete_after=Config.base_success_duration)
  def get_or_create_emoji(emoji:Union[str, discord.Emoji, discord.PartialEmoji], guild:discord.Guild) -> Karma_emoji:
    emoji_id = general_util.emoji_id_from_emoji(emoji)

    emoji_item = KarmaRepo.get_emoji_by_id(emoji_id)
    if emoji_item is None:
      emoji_item = KarmaRepo.__create_emoji(emoji, guild)
    return emoji_item
 def get_guild_emoji_stats_for_emoji(
     guild: discord.Guild, emoji: Union[discord.Emoji, discord.PartialEmoji,
                                        str]) -> GuildEmojiStats:
     emoji_id = general_util.emoji_id_from_emoji(emoji)
     item = session.query(GuildEmojiStats).filter(
         GuildEmojiStats.guild_id == str(guild.id),
         GuildEmojiStats.emoji_id == emoji_id).one_or_none()
     if item is None:
         item = StatsRepo.__create_guild_emoji_stats_for_emoji(guild, emoji)
     return item
 def get_member_emoji_stats_for_emoji(
     user: discord.Member, emoji: Union[discord.Emoji, discord.PartialEmoji,
                                        str]
 ) -> MemberEmojiStats:
     emoji_id = general_util.emoji_id_from_emoji(emoji)
     item = session.query(MemberEmojiStats).filter(
         MemberEmojiStats.user_id == str(user.id),
         MemberEmojiStats.guild_id == str(user.guild.id),
         MemberEmojiStats.emoji_id == emoji_id).one_or_none()
     if item is None:
         item = StatsRepo.__create_member_emoji_stats(user, emoji_id)
     return item
  def __create_emoji(emoji:Union[discord.Emoji, discord.PartialEmoji, str], guild:discord.Guild) -> Karma:
    if not GuildRepo.guild_exist(guild.id):
      GuildRepo.create_guild(guild)

    emoji_id = general_util.emoji_id_from_emoji(emoji)
    if not EmojiDataRepo.emoji_data_exist(emoji_id):
      EmojiDataRepo.create_emoji_data(emoji)

    with emoji_access_lock:
      item = Karma_emoji(emoji_ID=emoji_id, guild_id=str(guild.id))
      session.add(item)
      session.commit()
    return item
Exemple #6
0
  async def handle_reaction_add(self, ctx: ReactionContext):
    if isinstance(ctx.channel, discord.DMChannel):
      return

    # Check if there is not this bot involved
    if self.bot.user.id in (ctx.member.id, ctx.message.author.id):
      return

    # Check if author did not react to his message
    if ctx.member.id == ctx.message.author.id:
      return

    # Get settings
    reposter = self.repost_settings_repo.get_repost_settings(ctx.guild.id)
    if reposter is None:
      return

    # If reposter is disabled then don't repost anything
    if not reposter.enabled:
      return

    # Can't repost from repost channel
    if reposter.repost_channel_id == str(ctx.channel.id):
      return

    # Check if channel filter is met
    filter_channels = reposter.mode_channel_ids if reposter.mode_channel_ids is not None else []

    if reposter.blacklist_mode:
      if str(ctx.channel.id) in filter_channels:
        return
    else:
      if str(ctx.channel.id) not in filter_channels:
        return

    # Check if message was not reposted before
    if self.repost_repo.find_repost_by_original_message_id(ctx.message.id) is not None:
      return

    all_reactions: List[discord.Reaction] = ctx.message.reactions
    for reac in all_reactions:
      if not reposter.any_emoji:
        emoji_id = general_util.emoji_id_from_emoji(reac.emoji)
        emoji_ids = reposter.emoji_ids.split(";") if reposter.emoji_ids is not None else []
        if emoji_id not in emoji_ids:
          continue

      if reac.count >= reposter.emoji_threshold:
        return await self.__repost_message(ctx, all_reactions, reposter)
    def __create_guild_emoji_stats_for_emoji(
        guild: discord.Guild, emoji: Union[discord.Emoji, discord.PartialEmoji,
                                           str]) -> GuildEmojiStats:
        if not GuildRepo.guild_exist(guild.id):
            GuildRepo.create_guild(guild)

        emoji_id = general_util.emoji_id_from_emoji(emoji)
        if not EmojiDataRepo.emoji_data_exist(emoji_id):
            EmojiDataRepo.create_emoji_data(emoji)

        item = GuildEmojiStats(guild_id=str(guild.id), emoji_id=emoji_id)
        session.add(item)
        session.commit()

        return item
    def create_emoji_data(
            emoji: Union[discord.Emoji, discord.PartialEmoji,
                         str]) -> EmojiData:
        have_reources = isinstance(emoji, discord.Emoji) or isinstance(
            emoji, discord.PartialEmoji)
        resources = emoji.url if have_reources else None
        emoji_id = general_util.emoji_id_from_emoji(emoji)

        item = EmojiData(
            emoji_id=emoji_id,
            resource_url=resources,
            guild_id=str(emoji.guild_id) if isinstance(emoji, discord.Emoji)
            and emoji.guild_id is not None else None)
        session.add(item)
        session.commit()

        return item
    def __create_member_emoji_stats(
        user: discord.Member, emoji: Union[discord.Emoji, discord.PartialEmoji,
                                           str]
    ) -> MemberEmojiStats:
        if not UserRepo.guild_user_exist(user.id, user.guild.id):
            UserRepo.create_guild_user(user)

        emoji_id = general_util.emoji_id_from_emoji(emoji)
        if not EmojiDataRepo.emoji_data_exist(emoji_id):
            EmojiDataRepo.create_emoji_data(emoji)

        item = MemberEmojiStats(user_id=str(user.id),
                                guild_id=str(user.guild.id),
                                emoji_id=emoji_id)
        session.add(item)
        session.commit()

        return item
Exemple #10
0
  async def remove_filter_emoji(self, ctx: commands.Context, emoji: Union[int, discord.Emoji, discord.PartialEmoji, str]):
    await general_util.delete_message(self.bot, ctx)

    reposter = self.repost_settings_repo.get_repost_settings(ctx.guild.id)
    if reposter is None:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_no_reposter), delete_after=Config.base_error_duration)

    emoji_ids = reposter.emoji_ids.split(";") if reposter.emoji_ids is not None else []
    emoji_id = general_util.emoji_id_from_emoji(emoji)

    if emoji_id not in emoji_ids:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_remove_filter_emoji_emoji_not_in_filter_list), delete_after=Config.base_error_duration)

    emoji_ids.remove(emoji_id)
    emoji_ids_string = ";".join(emoji_ids)
    reposter.emoji_ids = emoji_ids_string
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_remove_filter_emoji_success", emoji=emoji)), delete_after=Config.base_success_duration)
Exemple #11
0
 def get_emoji_value(emoji:Union[discord.Emoji, discord.PartialEmoji, str]) -> int:
   emoji: Union[Karma_emoji, None] = KarmaRepo.get_emoji_by_id(general_util.emoji_id_from_emoji(emoji))
   value = emoji.value if emoji is not None else 0
   return int(value)
Exemple #12
0
  def remove_emoji(emoji:Union[str, discord.Emoji, discord.PartialEmoji]):
    emoji_id = general_util.emoji_id_from_emoji(emoji)

    with emoji_access_lock:
      session.query(Karma_emoji).filter(Karma_emoji.emoji_ID == emoji_id).delete()
      session.commit()
Exemple #13
0
 def get_emoji(emoji:Union[str, discord.Emoji, discord.PartialEmoji]) -> Union[Karma_emoji, None]:
   return KarmaRepo.get_emoji_by_id(general_util.emoji_id_from_emoji(emoji))
Exemple #14
0
 def remove_user_give_karma_by_emoji(user:Union[discord.Member, discord.User], emoji:Union[str, discord.Emoji, discord.PartialEmoji], write: bool = True):
   emoji_id = general_util.emoji_id_from_emoji(emoji)
   value = KarmaRepo.get_emoji_value(emoji_id)
   KarmaRepo.remove_user_give_karma(user, abs(value), True if value >= 0 else False, write)
Exemple #15
0
 def give_user_get_karma_by_emoji(user:Union[discord.Member, discord.User], emoji:Union[str, discord.Emoji, discord.PartialEmoji], write: bool = True):
   emoji_id = general_util.emoji_id_from_emoji(emoji)
   value = KarmaRepo.get_emoji_value(emoji_id)
   KarmaRepo.give_user_get_karma(user, value, write)