Exemple #1
0
 async def on_member_join(self, member):
     db_methods.insert_request(
         columns=('guild_id', 'member_id', 'member_name', 'activ',
                  'join_date'),
         values=(member.guild.id, member.id,
                 member.name + '#' + member.discriminator, True,
                 member.joined_at),
         table="member")
Exemple #2
0
async def on_ready():
    welcome_message = "я готов к использованию, если видишь меня онлайн на сервере.\nЧтобы узнать, что я могу введи .help"
    global FARGUS_TEAM
    FARGUS_TEAM = bot.get_guild(FARGUS_TEAM_GUILD_ID)
    global FARGUS_TEAM_OWNER
    FARGUS_TEAM_OWNER = FARGUS_TEAM.owner
    global log_channel
    log_channel = bot.get_channel(log_channel_id)
    global debug_channel
    debug_channel = bot.get_channel(debug_channel_id)

    db_methods.open_connection()
    db_exist_flag = db_methods.init_db()

    if not db_exist_flag:
        db_methods.insert_request(values=('default',
                                          '{"roll", "set_preset", role}', 5),
                                  columns=('preset_name', 'commands',
                                           'priority'),
                                  table='command_presets')
        for guild in bot.guilds:
            await init_guild(guild)
    #
    #
    # global bot_prefixes

    global permission_obj
    permission_obj = Permission()
    permission_obj.add_command_preset(FARGUS_TEAM_GUILD_ID, 'dev')

    global guild_prefixes_set
    guild_prefixes_set = permission_obj.get_prefixes_set()

    # global bot_prefixes
    bot.command_prefix = list(guild_prefixes_set)

    # if DEBUG:
    #     async for message in debug_channel.history(limit=1):
    #         if message.author.id != bot.user.id:
    #             await send_and_add_reaction_for_delete(debug_channel, welcome_message)
    #         else:
    #             if message.content != welcome_message:
    #                 await send_and_add_reaction_for_delete(debug_channel, welcome_message)
    #             else:
    #                 await message.delete()
    #                 await send_and_add_reaction_for_delete(debug_channel, welcome_message)
    bot.add_cog(BotEvents(bot, permission_obj, log_channel))
    # bot.add_cog(BotChecks(bot, permission_obj, log_channel, debug_channel, FARGUS_TEAM, FARGUS_TEAM_OWNER))
    print('== Ready! ', "=" * 50)
Exemple #3
0
async def create_preset(ctx, preset_name=None, *commands):
    # TODO: разрешить применять этот метод только разработчику
    if ctx.author.id == FARGUS_TEAM_OWNER.id:
        all_commands = [command.name for command in bot.commands]
        values = list()
        if preset_name is None:
            return
        for args_command in commands:
            if args_command in all_commands:
                values.append(args_command)

        if values:
            db_methods.insert_request(table='command_presets',
                                      columns=('preset_name', 'commands'),
                                      values=(preset_name,
                                              list_to_sql_array(values)))
            await send_and_add_reaction_for_delete(
                ctx.channel,
                'Добавлен присет - **{}**.\nВ него вошли команды: {}'.format(
                    preset_name, ", ".join(values)))
Exemple #4
0
async def init_guild(guild):
    db_guild = db_methods.select_request(columns=("guild_id", "bot_on_server"),
                                         where=("guild_id", guild.id),
                                         table="guild")
    if len(db_guild) == 1:
        print("guild detected", db_guild)
        # db_methods.update_request("guild", (
        #     ("owner_id", None), ("owner_name", None)), ("guild_id", guild.id))
        db_methods.delete_request("owner", ("guild_id", guild.id))
        db_methods.delete_request("member", ("guild_id", guild.id))
        db_methods.delete_request("guild", ("guild_id", guild.id))
        await init_guild(guild)

    else:
        # добавление гильдии
        print("guild don't detected\nlet's create!")
        guild_id = guild.id
        db_methods.insert_request(columns=("guild_id", 'guild_name',
                                           'bot_on_server', 'prefix'),
                                  values=(guild_id, guild.name, True, 'f.'),
                                  table='guild')

        # добавление всех членов гильдии
        guild_members = guild.members
        values = tuple(
            (guild_id, member.id, member.name + '#' + member.discriminator,
             True, member.joined_at) for member in guild_members)

        db_methods.insert_request(columns=("guild_id", "member_id",
                                           'member_name', 'activ',
                                           'join_date'),
                                  values=values,
                                  table='member')

        # добавление хозяина гильдии
        db_methods.insert_request(
            columns=('guild_id', 'owner_id', 'owner_name'),
            values=(guild_id, guild.owner.id,
                    guild.owner.name + "#" + guild.owner.discriminator),
            table="owners")
        # добавление для гильдии дефолтного пресета команд
        db_methods.insert_request(values=(guild_id, 'default'),
                                  columns=('guild_id', 'enable_preset'),
                                  table='enable_presets')
Exemple #5
0
async def add_role_access(ctx, *args):
    keys = ('-all_commands', '-allc', 'all_roles', '-allr')

    all_command_flag = False
    all_roles_flag = False

    # all_roles = (role.name for role in ctx.guild.roles)
    all_commands = permission_obj.get_enable_commands_for_guild(ctx.guild)

    hold_roles = []
    hold_commands = []

    args = [str(arg).replace('.', ' ') for arg in args]

    for arg in args:
        if arg in keys:
            if not all_command_flag and arg in keys[:2]:
                all_command_flag = True
                hold_commands = all_commands
            elif not all_roles_flag and arg in keys[2:]:
                all_roles_flag = True
                hold_roles = (role.name for role in ctx.guild.roles)
            elif arg not in keys:
                await send_and_add_reaction_for_delete(
                    ctx.channel, "Вы ввели неверный ключ {}".format(arg))
            else:
                await send_and_add_reaction_for_delete(
                    ctx.channel,
                    'Ключ {} повторяется, я не могу это так оставить'.format(
                        arg))
        # if arg is role
        else:

            role = get_role_by_name(arg, ctx.guild.roles)

            if role:
                if all_roles_flag:
                    res = 'Вы уже использовали флаг "-all_roles" добавив все роли,' \
                          ' добавление роли {} избыточно'.format(arg)

                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return
                elif type(role) == list:
                    res = 'Не могу понять какую роль вы имели ввиду под "{}": {}'.format(
                        arg, ', '.join([one_role.name for one_role in role]))
                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return
                elif role in hold_roles:
                    res = 'Вы уже добавили роль "{}", добавление роли {} избыточно'.format(
                        role.name, arg)
                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return
                else:
                    hold_roles.append(role)
            # if arg is command
            else:

                if arg not in all_commands:
                    res = 'Не могу разобрать эту команду или роль "{}"'.format(
                        arg)
                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return

                elif all_command_flag:
                    res = 'Вы уже использовали флаг "-all_commands" ' \
                          'добавив все команды, добавление команды {} избыточно'.format(arg)
                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return

                elif arg in hold_commands:
                    res = 'Вы уже добавили команду "{}", повторное добавление избыточно'.format(
                        arg)
                    await send_and_add_reaction_for_delete(ctx.channel, res)
                    return
                else:
                    hold_commands.append(arg)

    if not hold_commands:
        res = 'Не было распознано не одной команды'
        await send_and_add_reaction_for_delete(ctx.channel, res)
        return
    elif not hold_roles:
        res = 'Не было распознано не одной роли'
        await send_and_add_reaction_for_delete(ctx.channel, res)
        return

        # exist_rows = db_methods.select_request(columns=('role_id', 'command_name'),
    #                                        table='role_white_list',
    #                                        where=('guild_id', ctx.guild.id))

    guild_white_list = permission_obj.db_guilds[ctx.guild.id]['white_role']
    for hold_role in hold_roles:
        if hold_role.id in guild_white_list.keys():
            new_commands = set(hold_commands).difference(
                guild_white_list[hold_role.id])
            guild_white_list[hold_role.id].update(new_commands)
        else:
            new_commands = set(hold_commands)
            guild_white_list[hold_role.id] = new_commands

        value = [[ctx.guild.id, hold_role.id, command]
                 for command in new_commands]
        if value:
            db_methods.insert_request(table='role_white_list',
                                      columns=('guild_id', 'role_id',
                                               'command_name'),
                                      values=value)