Пример #1
0
  async def unload(self, ctx: commands.Context, extension: str):
    await ctx.message.delete()

    if extension in Config.protected_modules:
      await ctx.channel.send(embed=general_util.generate_error_message(Strings.populate_string("unable_to_unload_protected_cog", extension=extension)), delete_after=Config.base_error_duration)
      return

    if extension == "all":
      loaded_cogs = [cog.file for cog in self.bot.cogs.values()]

      final_embed = discord.Embed(title="Cog unload", color=discord.Color.green(), description="Failed cogs:")
      for cog in loaded_cogs:
        if cog not in Config.protected_modules:
          try:
            self.bot.unload_extension(f"cogs.{cog}")
            logger.info(f'{cog} unloaded')
          except Exception as e:
            final_embed.description += f"\n{str(cog)}"
            final_embed.colour = discord.Color.orange()
            await ctx.channel.send(embed=general_util.generate_error_message(Strings.populate_string("unable_to_unload_cog", cog=cog, e=e)), delete_after=Config.base_error_duration)

      await ctx.send(embed=final_embed, delete_after=Config.base_long_success_duration)
    else:
      try:
        self.bot.unload_extension(f"cogs.{extension}")
        logger.info(f'{extension} unloaded')
        await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("cog_unloaded", extension=extension)), delete_after=Config.base_success_duration)
      except Exception as e:
        await ctx.channel.send(embed=general_util.generate_error_message(Strings.populate_string("unable_to_unload_cog", cog=extension, e=e)), delete_after=Config.base_error_duration)
Пример #2
0
  async def grab_item(self, ctx: commands.Context, user: Union[discord.Member, discord.User, int], item_id: int, all:bool=False):
    await general_util.delete_message(self.bot, ctx)

    if isinstance(user, int):
      user_id = user
      user = await general_util.get_user(self.bot, user_id)
      if user is None:
        return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_user_doesnt_exist", id=user_id)), delete_after=Config.base_error_duration)

    item = self.item_repo.get_item_by_id(item_id)
    if item is None:
      return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_item_not_found", id=item_id)), delete_after=Config.base_error_duration)

    player = self.player_repo.get_player(user)
    inventory_slots:List[InventorySlot] = player.inventory

    for inventory_slot in inventory_slots:
      if inventory_slot.item.id == item.id:
        if all:
          self.player_repo.remove_all_from_inventory(int(player.user_id), item.id)
          return await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("rpg_items_grab_all_success", user=user.mention, item_name=item.name)), delete_after=Config.base_success_duration)
        else:
          self.player_repo.remove_from_inventory(int(player.user_id), item.id)
          return await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("rpg_items_grab_success", user=user.mention, item_name=item.name)), delete_after=Config.base_success_duration)
    await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_items_grab_item_not_in_inventory", user=user.mention, item_name=item.name)), delete_after=Config.base_error_duration)
Пример #3
0
  async def load(self, ctx: commands.Context, extension: str):
    await ctx.message.delete()

    if extension == "all":
      loaded_cogs = [cog.file for cog in self.bot.cogs.values()]
      cogs_in_folder = [cog[:-3].lower() for cog in os.listdir("cogs") if str(cog).endswith(".py") and "__init__" not in str(cog)]
      if len(loaded_cogs) == len(cogs_in_folder):
        await ctx.channel.send(embed=general_util.generate_error_message(Strings.all_cogs_already_loaded), delete_after=Config.base_error_duration)
        return

      final_embed = discord.Embed(title="Cog load", color=discord.Color.green(), description="Failed cogs:")
      for cog in cogs_in_folder:
        if str(cog) not in loaded_cogs and str(cog) not in Config.protected_modules:
          try:
            self.bot.load_extension(f"cogs.{str(cog)}")
            logger.info(f"{str(cog)} loaded")
            await asyncio.sleep(0)
          except Exception as e:
            final_embed.description += f"\n{str(cog)}"
            final_embed.colour = discord.Color.orange()
            await ctx.channel.send(embed=general_util.generate_error_message(Strings.populate_string("unable_to_load_cog", cog=str(cog), e=e)), delete_after=Config.base_error_duration)

      await ctx.send(embed=final_embed, delete_after=Config.base_long_success_duration)
    else:
      try:
        self.bot.load_extension(f"cogs.{extension}")
        logger.info(f"{extension} loaded")

        await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("cog_loaded", extension=extension)), delete_after=Config.base_success_duration)
      except Exception as e:
        await ctx.channel.send(embed=general_util.generate_error_message(Strings.populate_string("unable_to_load_cog", cog=extension, e=e)), delete_after=Config.base_error_duration)
Пример #4
0
  async def add_filter_channel(self, ctx: commands.Context, channel: Union[discord.TextChannel, int]):
    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)

    channel_ids = reposter.mode_channel_ids.split(";") if reposter.mode_channel_ids is not None else []

    if len(channel_ids) >= Config.reposter_filter_channel_limit:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_add_filter_channel_limit_reached), delete_after=Config.base_error_duration)

    if isinstance(channel, discord.TextChannel):
      if str(channel.id) in channel_ids:
        return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_add_filter_channel_already_added), delete_after=Config.base_error_duration)
    else:
      tmp_chan = await general_util.get_text_channel(ctx.guild, channel)
      if tmp_chan is None:
        return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("reposter_add_filter_channel_invalid_id", id=channel)), delete_after=Config.base_error_duration)
      channel = tmp_chan

    if str(channel.id) == reposter.repost_channel_id:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_add_filter_channel_filter_same_as_repost), delete_after=Config.base_error_duration)

    channel_ids.append(str(channel.id))
    channel_ids_string = ";".join(channel_ids)
    reposter.mode_channel_ids = channel_ids_string
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_add_filter_channel_success", channel=channel.name)), delete_after=Config.base_success_duration)
Пример #5
0
    async def remove_channel_from_whitelist(
        self,
        ctx: discord.CommandInteraction,
        channel_name: str = commands.Param(
            description=Strings.warden_channel_remove_channel_description,
            autocomplete=text_channels_autocomplete)):
        channel = discord.utils.get(ctx.guild.channels, name=channel_name)
        if channel is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.populate_string("warden_channel_doesnt_exist",
                                        name=channel_name)),
                                  delete_after=Config.base_error_duration)

        settings = self.warden_repo.get_warden_settings(ctx.guild)
        if str(channel.id) not in settings.whitelist_channel_ids:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.populate_string("warden_channel_is_not_in_whitelist",
                                        name=channel_name)),
                                  delete_after=Config.base_error_duration)

        channel_ids = settings.whitelist_channel_ids.split(";")
        channel_ids.remove(str(channel.id))
        channels_string = ";".join(channel_ids)
        settings.whitelist_channel_ids = channels_string
        self.warden_repo.update()

        await ctx.send(
            embed=general_util.generate_success_message("Settings updated"),
            delete_after=Config.base_success_duration)
Пример #6
0
    async def handle_reaction_add(self, ctx: ReactionContext):
        if self.bot.user.id in (ctx.member.id, ctx.message.author.id):
            return

        if not isinstance(ctx.emoji, str):
            return

        if ctx.emoji not in self.flag_to_code.keys():
            return

        if ctx.guild.id in self.guilds_usage.keys() and self.guilds_usage[
                ctx.guild.id] >= Config.translate_usage_limit_per_10_mins:
            return await ctx.channel.send(
                embed=general_util.generate_error_message(
                    Strings.populate_string(
                        "translate_on_cooldown",
                        limit=Config.translate_usage_limit_per_10_mins)),
                delete_after=Config.base_error_duration)

        if self.translator.get_usage().any_limit_exceeded:
            return await ctx.channel.send(
                embed=general_util.generate_error_message(
                    Strings.translate_api_limit_exceeded),
                delete_after=Config.base_error_duration)

        trg_lan = self.flag_to_code[ctx.emoji]
        if trg_lan.upper() not in self.supp_list:
            return await ctx.channel.send(
                embed=general_util.generate_error_message(
                    Strings.translate_unsupported_language),
                delete_after=Config.base_error_duration)

        if ctx.message.content is not None and ctx.message.content != "":
            if len(ctx.message.content) > 1000:
                return await ctx.channel.send(
                    embed=general_util.generate_error_message(
                        Strings.populate_string(
                            "translate_message_too_large",
                            message_url=ctx.message.jump_url)),
                    delete_after=Config.base_error_duration)

            if ctx.guild.id in self.guilds_usage.keys():
                self.guilds_usage[ctx.guild.id] += 1
            else:
                self.guilds_usage[ctx.guild.id] = 1

            result = str(
                self.translator.translate_text(ctx.message.content,
                                               target_lang=trg_lan.upper()))
            translate_result = discord.Embed(
                color=discord.Color.dark_blue(),
                description=str(result) +
                f"\n\n[Original]({ctx.message.jump_url})",
                title=f"Translation to {trg_lan.upper()}")
            general_util.add_author_footer(translate_result, ctx.member)
            await ctx.channel.send(embed=translate_result)
Пример #7
0
  async def _leave_s(self, ctx:commands.Context, sid: int):
    server = self.bot.get_guild(sid)

    if server:
      try:
        await server.leave()
        await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("system_server_left", name=server.name)), delete_after=Config.base_success_duration)
      except:
        await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("system_server_left_failed", name=server.name)), delete_after=Config.base_error_duration)
    else:
      await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("system_leave_server_id_not_found", sid=sid)), delete_after=Config.base_error_duration)
Пример #8
0
    async def warden_scan(
        self,
        ctx: discord.CommandInteraction,
        limit: str = commands.Param(
            description=Strings.warden_scan_limit_description, default="all"),
        channel: str = commands.Param(
            description=Strings.warden_scan_channel_description,
            default=None,
            autocomplete=text_channels_autocomplete)):
        if channel is None:
            channel = ctx.channel
        else:
            channel = discord.utils.get(ctx.guild.channels, name=channel)
            if channel is None:
                return await ctx.send(
                    embed=general_util.generate_error_message(
                        Strings.populate_string("warden_channel_doesnt_exist",
                                                name=channel)),
                    delete_after=Config.base_error_duration)

        guild_warden_settings = self.warden_repo.get_warden_settings(ctx.guild)
        if str(channel.id) not in guild_warden_settings.whitelist_channel_ids:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.populate_string("warden_channel_is_not_in_whitelist",
                                        name=channel.name)),
                                  delete_after=Config.base_error_duration)

        if limit.isnumeric():
            limit = int(limit)
        elif limit == "all":
            limit = None
        else:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.warden_scan_bad_limit_format),
                                  delete_after=Config.base_error_duration)

        messages = await channel.history(limit=limit).flatten()

        ctr_hashes = 0
        now = time.time()
        for i, message in enumerate(messages):
            if len(message.attachments) == 0:
                continue

            hashes = [x async for x in self.generate_message_hash(message)]
            ctr_hashes += len(hashes)

        await ctx.send(
            content="**SCAN COMPLETE**\n\n"
            f"Processed **{len(messages)}** messages.\n"
            f"Computed **{ctr_hashes}** hashes in {(time.time() - now):.1f} seconds.",
            delete_after=Config.base_long_success_duration)
Пример #9
0
  async def create_item(self, ctx: commands.Context, name:str, level_req:int, rarity:int, *, additional_info:Optional[str]=None):
    await general_util.delete_message(self.bot, ctx)

    name = name.replace("_", " ")
    if level_req < 0:
      return await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_create_invalid_level_req), delete_after=Config.base_error_duration)

    if rarity not in RarityEnum.val_list():
      return await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_create_invalid_rarity), delete_after=Config.base_error_duration)

    description = None
    icon_path = None
    item_slot = None
    sell_value = None

    if additional_info is not None:
      additional_info_parts = additional_info.split(";")

      for add_inf_part in additional_info_parts:
        info_pair = add_inf_part.split(":")
        key = info_pair[0]
        val = info_pair[1]

        if key == "description":
          description = val
        elif key == "icon_path":
          icon_path = val
        elif key == "slot":
          if not val.isnumeric():
            return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_items_create_key_not_numeric", key=key)), delete_after=Config.base_error_duration)

          val = int(val)
          if val not in ItemSlotEnum.val_list():
            return await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_create_invalid_slot), delete_after=Config.base_error_duration)

          item_slot = val
        elif key == "sell_value":
          if not val.isnumeric():
            return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_items_create_key_not_numeric", key=key)), delete_after=Config.base_error_duration)

          val = int(val)
          if val < 0:
            return await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_create_sell_value_negative), delete_after=Config.base_error_duration)

          sell_value = val

    item = self.item_repo.create_item(name, level_req, rarity, description=description, icon_path=icon_path, item_slot=item_slot, sell_value=sell_value)
    embed = rpg_util.generate_item_embed(item)
    general_util.add_author_footer(embed, ctx.author)

    await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Пример #10
0
    async def role_giver_disable(self, ctx: commands.Context,
                                 role_giver_id: int):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.get_role_giver_by_id(role_giver_id)
        if role_giver is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_exist),
                                  delete_after=Config.base_error_duration)

        if role_giver.guild_ID != str(ctx.guild.id):
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_belong_to_this_guild),
                                  delete_after=Config.base_error_duration)

        if not role_giver.enabled:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_disable_already_disabled),
                                  delete_after=Config.base_error_duration)

        role_giver.enabled = False
        await self.delete_role_giver_instance(role_giver)
        self.role_giver_repo.update()
        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_disable_success",
                                    id=role_giver.id)),
                       delete_after=Config.base_success_duration)
Пример #11
0
    async def edit_reminder_message(self, ctx: commands.Context,
                                    reminder_id: int, *, message: str):
        await general_util.delete_message(self.bot, ctx)

        reminder = self.reminder_repo.get_reminder_by_id(reminder_id)
        if reminder is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.reminder_invalid_id),
                                  delete_after=Config.base_error_duration)

        if reminder.user_ID == str(
                ctx.author.id) or ctx.author.id in Config.developer_ids:
            await self.update_reminder_in_database(reminder,
                                                   ctx,
                                                   message=message)
            await self.update_reminder_message(reminder)

            await ctx.send(embed=general_util.generate_success_message(
                Strings.populate_string("reminder_edit_success",
                                        id=reminder.id)),
                           delete_after=Config.base_success_duration)
        else:
            await ctx.send(embed=general_util.generate_error_message(
                Strings.reminder_missing_permission),
                           delete_after=Config.base_error_duration)
Пример #12
0
 async def warden_delete(self, ctx: discord.CommandInteraction):
     self.warden_repo.delete_warden_settings_by_guild_id(ctx.guild.id)
     await self.clear_old_attachements_task()
     await ctx.send(embed=general_util.generate_success_message(
         Strings.populate_string("warden_delete_success",
                                 guild_name=ctx.guild.name)),
                    delete_after=Config.base_success_duration)
Пример #13
0
    async def set_description(self, ctx: commands.Context, role_giver_id: int,
                              *, description: str):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.get_role_giver_by_id(role_giver_id)
        if role_giver is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_exist),
                                  delete_after=Config.base_error_duration)

        if role_giver.guild_ID != str(ctx.guild.id):
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_belong_to_this_guild),
                                  delete_after=Config.base_error_duration)

        if role_giver.enabled:
            await self.delete_role_giver_instance(role_giver)
            role_giver.enabled = False

        if len(description) > 4000:
            self.role_giver_repo.update()
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_description_too_long),
                                  delete_after=Config.base_error_duration)

        role_giver.description = description
        self.role_giver_repo.update()

        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_description_success",
                                    description=description,
                                    id=role_giver.id)),
                       delete_after=Config.base_success_duration)
Пример #14
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)
Пример #15
0
  async def items_list(self, ctx: commands.Context, item_id:Optional[int]=None):
    await general_util.delete_message(self.bot, ctx)

    if item_id is None:
      items = self.item_repo.get_all_items()

      items_embeds = []
      for item in items:
        embed = rpg_util.generate_item_embed(item)
        general_util.add_author_footer(embed, ctx.author)
        items_embeds.append(embed)

      if items_embeds:
        p_session = PaginatorSession(self.bot, ctx, pages=items_embeds)
        await p_session.run()
      else:
        await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_list_no_items), delete_after=Config.base_error_duration)
    else:
      item = self.item_repo.get_item_by_id(item_id)
      if item is None:
        return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_item_not_found", id=item_id)), delete_after=Config.base_error_duration)

      embed = rpg_util.generate_item_embed(item)
      general_util.add_author_footer(embed, ctx.author)
      await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Пример #16
0
 async def message(self, ctx: commands.Context, *, message: str = None):
     await ctx.message.delete()
     self.welcome_message_repo.update_welcome_message(ctx.guild, message)
     await ctx.channel.send(embed=generate_success_message(
         Strings.populate_string("set_welcome_message_success",
                                 message=message)),
                            delete_after=Config.base_success_duration)
Пример #17
0
    async def create_empty_role_giver_force(self, ctx: commands.Context):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.create_empty_role_giver(ctx.guild)
        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_create_success",
                                    id=role_giver.id)),
                       delete_after=Config.base_long_success_duration)
Пример #18
0
    async def role_giver_enable(self, ctx: commands.Context,
                                role_giver_id: int):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.get_role_giver_by_id(role_giver_id)
        if role_giver is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_exist),
                                  delete_after=Config.base_error_duration)

        if role_giver.guild_ID != str(ctx.guild.id):
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_belong_to_this_guild),
                                  delete_after=Config.base_error_duration)

        if role_giver.enabled:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_enable_already_enabled),
                                  delete_after=Config.base_error_duration)

        if role_giver.role_IDs is None or role_giver.role_IDs == "":
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_enable_no_roles),
                                  delete_after=Config.base_error_duration)

        if role_giver.channel_ID is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_enable_no_channel),
                                  delete_after=Config.base_error_duration)

        channel = await general_util.get_text_channel(
            ctx.guild, int(role_giver.channel_ID))
        if channel is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_enable_no_channel),
                                  delete_after=Config.base_error_duration)

        embed, number_of_roles = await generate_role_giver(
            role_giver, ctx.guild)
        if number_of_roles == 0:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_enable_no_roles),
                                  delete_after=Config.base_error_duration)

        general_util.add_author_footer(embed, ctx.author)
        instance_message = await ctx.send(embed=embed)

        for i in range(number_of_roles):
            await instance_message.add_reaction(reactions[i])

        role_giver.instance_message_ID = str(instance_message.id)
        role_giver.enabled = True
        self.role_giver_repo.update()

        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_enable_success",
                                    id=role_giver.id)),
                       delete_after=Config.base_success_duration)
Пример #19
0
  async def give_item(self, ctx: commands.Context, user:Union[discord.Member, discord.User, int], item_id:int):
    await general_util.delete_message(self.bot, ctx)

    if isinstance(user, int):
      user_id = user
      user = await general_util.get_user(self.bot, user_id)
      if user is None:
        return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_user_doesnt_exist", id=user_id)), delete_after=Config.base_error_duration)

    item = self.item_repo.get_item_by_id(item_id)
    if item is None:
      return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_item_not_found", id=item_id)), delete_after=Config.base_error_duration)

    player = self.player_repo.get_player(user)
    self.player_repo.add_to_inventory(int(player.user_id), item_id)

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("rpg_items_give_success", user=user.mention, item_name=item.name)), delete_after=Config.base_success_duration)
    await ctx.send(embed=rpg_util.generate_item_embed(item), delete_after=Config.base_success_duration)
Пример #20
0
    async def remove_role(self, ctx: commands.Context, role_giver_id: int,
                          role: Union[discord.Role, int, str]):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.get_role_giver_by_id(role_giver_id)
        if role_giver is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_exist),
                                  delete_after=Config.base_error_duration)

        if role_giver.guild_ID != str(ctx.guild.id):
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_belong_to_this_guild),
                                  delete_after=Config.base_error_duration)

        role_ids = role_giver.role_IDs.split(";") if (
            role_giver.role_IDs is not None
            and role_giver.role_IDs != "") else []
        if len(role_ids) == 0:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_remove_role_nothing_to_remove),
                                  delete_after=Config.base_error_duration)

        if isinstance(role, int):
            role = general_util.get_role(ctx.guild, role)
        elif isinstance(role, str):
            tmp_role = discord.utils.get(ctx.guild.roles, name=role)
            if tmp_role is None:
                roles = await ctx.guild.fetch_roles()
                tmp_role = discord.utils.get(roles, name=role)
            role = tmp_role

        if role is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_cant_find_role),
                                  delete_after=Config.base_error_duration)

        if str(role.id) not in role_ids:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_remove_role_not_in_roles),
                                  delete_after=Config.base_error_duration)

        if role_giver.enabled:
            await self.delete_role_giver_instance(role_giver)
            role_giver.enabled = False

        role_ids.remove(str(role.id))
        role_string = ";".join(role_ids)
        role_giver.role_IDs = role_string
        self.role_giver_repo.update()

        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_remove_role_success",
                                    name=role.name,
                                    id=role_giver.id)),
                       delete_after=Config.base_success_duration)
Пример #21
0
  async def reposter_create(self, ctx: commands.Context, repost_channel: discord.TextChannel):
    await general_util.delete_message(self.bot, ctx)

    if repost_channel.guild.id != ctx.guild.id:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_invalid_channel), delete_after=Config.base_error_duration)

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

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_create_success", chname=repost_channel.name)), delete_after=Config.base_success_duration)
Пример #22
0
    async def translate(self, ctx: commands.Context, target_language: str, *,
                        text: str):
        if len(text) > 1000:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.populate_string("translate_message_too_large",
                                        message_url=ctx.message.jump_url)),
                                  delete_after=Config.base_error_duration)

        if ctx.guild.id in self.guilds_usage.keys() and self.guilds_usage[
                ctx.guild.id] >= Config.translate_usage_limit_per_10_mins:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.populate_string(
                    "translate_on_cooldown",
                    limit=Config.translate_usage_limit_per_10_mins)),
                                  delete_after=Config.base_error_duration)

        if target_language.upper() not in self.supp_list:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.translate_unsupported_language),
                                  delete_after=Config.base_error_duration)

        if self.translator.get_usage().any_limit_exceeded:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.translate_api_limit_exceeded),
                                  delete_after=Config.base_error_duration)

        if ctx.guild.id in self.guilds_usage.keys():
            self.guilds_usage[ctx.guild.id] += 1
        else:
            self.guilds_usage[ctx.guild.id] = 1

        result = str(
            self.translator.translate_text(
                text, target_lang=target_language.upper()))

        translate_result = discord.Embed(
            color=discord.Color.dark_blue(),
            description=str(result) +
            f"\n\n[Original]({ctx.message.jump_url})",
            title=f"Translation to {target_language.upper()}")
        general_util.add_author_footer(translate_result, ctx.author)
        await ctx.send(embed=translate_result)
Пример #23
0
  async def reposter_toggle_channel_mode(self, ctx: commands.Context):
    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)

    reposter.blacklist_mode = not reposter.blacklist_mode
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_channel_mode_success", mode="Blacklist" if reposter.blacklist_mode else "Whitelist")), delete_after=Config.base_success_duration)
Пример #24
0
  async def reposter_emoji_any(self, ctx: commands.Context):
    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)

    reposter.any_emoji = not reposter.any_emoji
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_emoji_any_success", state="Enabled" if reposter.any_emoji else "Disabled")), delete_after=Config.base_success_duration)
Пример #25
0
 async def channel(self,
                   ctx: commands.Context,
                   *,
                   channel: discord.TextChannel = None):
     await ctx.message.delete()
     self.welcome_message_repo.update_welcome_channel(
         ctx.guild, channel.id if channel else None)
     await ctx.channel.send(embed=generate_success_message(
         Strings.populate_string(
             "set_welcome_channel_success",
             channel_name=(channel.name if channel else None))),
                            delete_after=Config.base_success_duration)
Пример #26
0
  async def reposter_threshold(self, ctx: commands.Context, threshold: int):
    await general_util.delete_message(self.bot, ctx)

    if threshold < 1:
      return await ctx.send(embed=general_util.generate_error_message(Strings.reposter_threshold_invalid_threshold), 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)

    reposter.emoji_threshold = threshold
    self.repost_settings_repo.update()

    await ctx.send(embed=general_util.generate_success_message(Strings.populate_string("reposter_threshold_success", value=threshold)), delete_after=Config.base_success_duration)
Пример #27
0
    async def create_empty_role_giver(self, ctx: commands.Context):
        await general_util.delete_message(self.bot, ctx)

        if self.role_giver_repo.get_number_of_guild_role_givers(
                ctx.guild.id) >= Config.rolegiver_limit:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_create_limit_reached),
                                  delete_after=Config.base_error_duration)

        role_giver = self.role_giver_repo.create_empty_role_giver(ctx.guild)
        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_create_success",
                                    id=role_giver.id)),
                       delete_after=Config.base_long_success_duration)
Пример #28
0
  async def create_effect(self, ctx: commands.Context, item_id:int, effect_id:int, ammount:int):
    await general_util.delete_message(self.bot, ctx)

    if not self.item_repo.item_exist(item_id):
      return await ctx.send(embed=general_util.generate_error_message(Strings.populate_string("rpg_item_not_found", id=item_id)), delete_after=Config.base_error_duration)

    if effect_id not in EffectEnum.val_list():
      return await ctx.send(embed=general_util.generate_error_message(Strings.rpg_items_effect_create_invalid_effect_id), delete_after=Config.base_error_duration)

    effect = self.item_repo.create_effect(item_id, effect_id, ammount)

    embed = rpg_util.generate_effect_embed(effect)
    general_util.add_author_footer(embed, ctx.author)

    await ctx.send(embed=embed, delete_after=Config.base_long_success_duration)
Пример #29
0
    async def get_sport(self, ctx: commands.Context, *, name: str):
        await self.check_cached_data()
        await ctx.message.delete()

        name = name.lower()

        for idx, sport in enumerate(self.cached_raw_sport_data):
            if name in sport.name.lower() or name in sport.shortcut.lower():
                return await ctx.send(
                    embed=self.cached_sport_pages[idx],
                    delete_after=Config.base_long_success_duration)

        await ctx.send(embed=general_util.generate_error_message(
            Strings.populate_string("vut_sports_sport_not_found",
                                    sport_name=name)),
                       delete_after=Config.base_error_duration)
Пример #30
0
    async def delete_title_giver_force(self, ctx: commands.Context,
                                       role_giver_id: int):
        await general_util.delete_message(self.bot, ctx)

        role_giver = self.role_giver_repo.get_role_giver_by_id(role_giver_id)
        if role_giver is None:
            return await ctx.send(embed=general_util.generate_error_message(
                Strings.role_giver_doesnt_exist),
                                  delete_after=Config.base_error_duration)

        await self.delete_role_giver_instance(role_giver)

        self.role_giver_repo.delete_role_giver_by_id(role_giver.id)
        await ctx.send(embed=general_util.generate_success_message(
            Strings.populate_string("role_giver_delete_success",
                                    id=role_giver.id)),
                       delete_after=Config.base_success_duration)