Esempio n. 1
0
async def initialize(bot, startup=False):
    #lock event handling while we get ready
    bot.locked = True
    try:
        #database
        GearbotLogging.info("Connecting to the database.")
        DatabaseConnector.init()
        bot.database_connection = DatabaseConnector.connection
        GearbotLogging.info("Database connection established.")

        Emoji.initialize(bot)
        Utils.initialize(bot)
        InfractionUtils.initialize(bot)
        bot.data = {
            "forced_exits": set(),
            "unbans": set(),
            "message_deletes": set(),
            "nickname_changes": set()
        }
        await GearbotLogging.initialize(bot, Configuration.get_master_var("BOT_LOG_CHANNEL"))
        if startup:
            c = await Utils.get_commit()
            bot.version = c
            GearbotLogging.info(f"GearBot spinning up version {c}")
            await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('ALTER')} GearBot spinning up version {c}")

        if bot.redis_pool is None:
            try:
                socket = Configuration.get_master_var("REDIS_SOCKET", "")
                if socket == "":
                    bot.redis_pool = await aioredis.create_redis_pool((Configuration.get_master_var('REDIS_HOST', "localhost"), Configuration.get_master_var('REDIS_PORT', 6379)), encoding="utf-8", db=0)
                else:
                    bot.redis_pool = await aioredis.create_redis_pool(socket, encoding="utf-8", db=0)
            except OSError:
                GearbotLogging.error("==============Failed to connect to redis==============")
                await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('NO')} Failed to connect to redis, caching unavailable")
            else:
                GearbotLogging.info("Redis connection established")
                await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('YES')} Redis connection established, let's go full speed!")

        if bot.aiosession is None:
            bot.aiosession = aiohttp.ClientSession()

        await Translator.initialize(bot)
        bot.being_cleaned.clear()
        await Configuration.initialize(bot)
        DashConfig.initialize(bot)
    except Exception as ex:
        #make sure we always unlock, even when something went wrong!
        bot.locked = False
        raise ex
    bot.locked = False
Esempio n. 2
0
 async def replace_guild_settings(self, message):
     guild_id, user_id = get_info(message)
     guild = self.bot.get_guild(guild_id)
     return DashConfig.update_config_section(guild,
                                             message["section"],
                                             message["modified_values"],
                                             guild.get_member(user_id),
                                             replace=True)
Esempio n. 3
0
    async def override_handler(self, message, t, text, voice):
        guild = self.bot.get_guild(message["guild_id"])

        if not DashConfig.is_numeric(message["role_id"]):
            raise ValidationException(dict(role_id="Not a valid id"))

        role = guild.get_role(int(message["role_id"]))
        if role is None:
            raise ValidationException(dict(role_id="Not a valid id"))
        if role.id == guild.id:
            raise ValidationException(
                dict(
                    role_id="The @everyone role can't be used for muting people"
                ))
        if role.managed:
            raise ValidationException(
                dict(
                    role_id=
                    "Managed roles can not be assigned to users and thus won't work for muting people"
                ))
        user = await Utils.get_user(message["user_id"])
        parts = {
            "role_name": Utils.escape_markdown(role.name),
            "role_id": role.id,
            "user": Utils.clean_user(user),
            "user_id": user.id
        }
        GearbotLogging.log_key(guild.id, f"config_mute_{t}_triggered", **parts)
        failed = []
        for channel in guild.text_channels:
            try:
                if text is None:
                    await channel.set_permissions(role,
                                                  reason=Translator.translate(
                                                      f'mute_{t}', guild.id),
                                                  overwrite=None)
                else:
                    await channel.set_permissions(role,
                                                  reason=Translator.translate(
                                                      f'mute_{t}', guild.id),
                                                  **text)
            except Forbidden as ex:
                failed.append(channel.mention)
        for channel in guild.voice_channels:
            try:
                if voice is None:
                    await channel.set_permissions(role,
                                                  reason=Translator.translate(
                                                      f'mute_{t}', guild.id),
                                                  overwrite=None)
                else:
                    await channel.set_permissions(role,
                                                  reason=Translator.translate(
                                                      f'mute_{t}', guild.id),
                                                  **voice)
            except Forbidden as ex:
                failed.append(
                    Translator.translate('voice_channel',
                                         guild.id,
                                         channel=channel.name))

        await asyncio.sleep(
            1
        )  # delay logging so the channel overrides can get querried and logged
        GearbotLogging.log_key(guild.id, f"config_mute_{t}_complete", **parts)

        out = '\n'.join(failed)
        GearbotLogging.log_key(
            guild.id,
            f"config_mute_{t}_failed",
            **parts,
            count=len(failed),
            tag_on=None if len(failed) is 0 else f'```{out}```')