Beispiel #1
0
  async def reposter_show(self, ctx: commands.Context):
    await general_util.delete_message(self.bot, ctx)

    settings = self.repost_settings_repo.get_repost_settings(ctx.guild.id)
    if settings is None:
      embed = discord.Embed(title="Content reposter", description="*There is no content reposter*", color=discord.Color.orange())
      general_util.add_author_footer(embed, ctx.author)
      return await ctx.send(embed=embed, delete_after=Config.base_error_duration)

    embed = discord.Embed(title="Content reposter", description="**Enabled**" if settings.enabled else "**Disabled**", color=discord.Color.dark_blue())
    general_util.add_author_footer(embed, ctx.author)

    repost_channel = await general_util.get_text_channel(ctx.guild, int(settings.repost_channel_id))
    repost_channel_name = repost_channel.name if repost_channel is not None else "*Invalid*"
    embed.add_field(name="Repost channel", value=repost_channel_name)

    mode = "Whitelist" if not settings.blacklist_mode else "Blacklist"
    embed.add_field(name="Mode", value=mode)

    channels_title = "Blacklisted channels" if settings.blacklist_mode else "Whitelisted channels"
    if settings.mode_channel_ids is not None and settings.mode_channel_ids != "":
      channels_ids_string = settings.mode_channel_ids if settings.mode_channel_ids is not None else ""
      channel_ids = [int(chan_id) for chan_id in channels_ids_string.split(";") if chan_id != ""]
      channels_future = [general_util.get_text_channel(ctx.guild, chan_id) for chan_id in channel_ids]
      channels_result = await asyncio.gather(*channels_future)
      channels_result = [chan for chan in channels_result if chan is not None]
      channel_names = [chan.name for chan in channels_result]
      channel_names_print_string, _ = general_util.add_string_until_length(channel_names, 1000, "\n")
      test_database_ids = [str(chan.id) for chan in channels_result]
      test_database_string = ";".join(test_database_ids)
      if test_database_ids != settings.mode_channel_ids:
        # Modify database
        settings.mode_channel_ids = test_database_string
        self.repost_settings_repo.update()

      embed.add_field(name=channels_title, value=channel_names_print_string)
    else:
      embed.add_field(name=channels_title, value="*No channels set*")

    if not settings.any_emoji:
      emoji_ids = settings.emoji_ids.split(";") if settings.emoji_ids is not None else []
      emojis = []
      for emoji_id in emoji_ids:
        tmp_emoji = general_util.get_emoji_from_id(emoji_id, ctx.guild, self.bot)
        if tmp_emoji is not None:
          emojis.append(tmp_emoji)
        else:
          emojis.append(emoji_id)
      emojis = [str(emoji) for emoji in emojis if emoji is not None]
      emojis_string, _ = general_util.add_string_until_length(emojis, 1000, "\n")
      if emojis_string == "":
        emojis_string = "*No emojis*"
      embed.add_field(name="Emojis", value=emojis_string)
    else:
      embed.add_field(name="Emojis", value="Any")

    embed.add_field(name="Emojis threshold", value=str(settings.emoji_threshold))

    await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Beispiel #2
0
  async def list_recent(self, ctx: commands.Context, limit:Optional[int]=None):
    await general_util.delete_message(self.bot, ctx)

    audit_logs = self.audit_repo.get_recent_logs(limit=limit)
    log_strings = []

    for audit_log in audit_logs:
      user_name = audit_log.user.username if audit_log.user is not None else None

      if user_name is not None:
        display_name = audit_log.guild_user.display_name if audit_log.guild_user is not None else None
        if display_name is not None and display_name != user_name:
          user_name = f"{user_name} ({display_name})"

      guild_name = audit_log.guild.name if audit_log.guild is not None else None
      item_list = [str(audit_log.id), user_name, guild_name, audit_log.type.name, str(audit_log.created_at)]
      try:
        item_list.remove(None)
      except:
        pass

      log_strings.append(" - ".join(item_list))

    if not log_strings:
      return await ctx.send(embed=general_util.generate_error_message("*No audit logs*"), delete_after=Config.base_error_duration)

    final_texts = []
    while log_strings:
      tmp_text, log_strings = general_util.add_string_until_length(log_strings, 4000, "\n")
      final_texts.append(tmp_text)

    for text in final_texts:
      await ctx.send(f"```{text}```", delete_after=Config.base_long_success_duration)
Beispiel #3
0
  async def show_effect_enum(self, ctx: commands.Context):
    await general_util.delete_message(self.bot, ctx)

    effects = []
    for effect in EffectEnum:
      effects.append(f"{effect.value}: {effect.name}")

    description, _ = general_util.add_string_until_length(effects, 4000, "\n")
    embed = discord.Embed(title="Available effects", description=description, color=discord.Color.dark_blue())
    general_util.add_author_footer(embed, ctx.author)

    await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Beispiel #4
0
  async def actions_list(self, ctx: commands.Context):
    await general_util.delete_message(self.bot, ctx)

    action_index_list = ActionsEnum.val_list()

    actions_parts = []
    for action_val in action_index_list:
      actions_parts.append(f"**{action_val}**: {ActionsEnum.get_name(action_val)}")

    actions_string, _ = general_util.add_string_until_length(actions_parts, 4000, "\n")
    embed = discord.Embed(title="List of actions", color=discord.Color.dark_blue(), description=actions_string)
    general_util.add_author_footer(embed, ctx.author)

    await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Beispiel #5
0
def get_expected_rewards_string(rewards: Optional[List[ActionReward]],
                                length_limit: int = 4000,
                                header: bool = True) -> str:
    if rewards is None: return ""
    if not rewards: return ""

    reward_string_parts = []
    if header:
        reward_string_parts.append("**Expected rewards:**")

    for reward in rewards:
        tmp_str = reward_to_string(reward.reward)
        if tmp_str != "":
            if reward.action_id == ActionsEnum.WORK.value:
                tmp_str += " per hour"
            reward_string_parts.append(tmp_str)

    if len(reward_string_parts) == 1: return ""
    reward_string, _ = general_util.add_string_until_length(
        reward_string_parts, length_limit, "\n")
    return reward_string
Beispiel #6
0
    async def get_inventory(self, ctx: commands.Context, simple: bool = False):
        await general_util.delete_message(self.bot, ctx)

        inventory = self.player_repo.get_inventory(ctx.author.id)
        if not inventory:
            embed = discord.Embed(title=f"{ctx.author.display_name} Inventory",
                                  description="*Your inventory is empty*",
                                  color=discord.Color.blue())
            return await ctx.send(
                embed=embed, delete_after=Config.base_long_success_duration)

        if simple:
            parts = []
            for inventory_slot in inventory:
                parts.append(
                    rpg_util.generate_simple_item_text(inventory_slot.item))

            pages = []
            while parts:
                final_string, parts = general_util.add_string_until_length(
                    parts, 4000, "\n")
                page = discord.Embed(
                    title=f"{ctx.author.display_name} Inventory",
                    description=final_string,
                    color=discord.Color.blue())
                general_util.add_author_footer(page, ctx.author)
                pages.append(page)
        else:
            pages = []
            for inventory_slot in inventory:
                embed = rpg_util.generate_item_embed(inventory_slot.item)
                embed.title = f"{ctx.author.display_name} Inventory\n{inventory_slot.item.name}"
                general_util.add_author_footer(embed, ctx.author)
                pages.append(embed)

        p_session = PaginatorSession(self.bot,
                                     ctx,
                                     timeout=Config.base_long_success_duration,
                                     pages=pages)
        await p_session.run()