Exemplo n.º 1
0
def main():
    for filename, text in get_billtext('fl'):
        logger.info('extracting sections: %r' % filename)
        # webbrowser.open('file:///%s' % filename)
        for section in extract_sections(text):
            section_text = section.content
            print section_text
            if 'repeal' in section_text.lower() or 'add' in section_text.lower():
                # import pdb;pdb.set_trace()
                tokens = parse(Lexer, Parser, None, section_text)
                import pdb;pdb.set_trace()
Exemplo n.º 2
0
    async def on_message(message: discord.Message):
        for mod in sorted(module_manager.modules.values(),
                          key=lambda x: x.on_message.priority):
            await mod.on_message(message, bot)
        if not message.content.startswith(cmd_prefix):
            return

        if message.author.bot:
            return
        args = message.content.split()
        cmd = args.pop(0)[len(cmd_prefix):].lower()

        if cmd not in module_manager.commands:
            # await bot.send_error_embed(message.channel, "Команда \"%s\" не найдена." % cmd,
            #                            "Команда не найдена")
            return

        command = module_manager.commands[cmd]
        if command.guild_lock and message.guild.id not in command.guild_lock:
            await bot.send_error_embed(
                message.channel,
                "Команда \"%s\" недоступна на данном сервере." % cmd,
                "Команда не найдена")
            return
        logger.info(
            "Выполнение команды %s от %s (%s)." %
            (repr(message.content), str(message.author), message.author.id))
        try:
            args_1, keys = parse(args)
            if not module_manager.check_permissions(message.author.guild_permissions, command.permissions) \
                    or not module_manager.check_sp_permissions(message.author.id, command.future_permissions):
                embed: discord.Embed = bot.get_error_embed(
                    "У вас недостаточно прав для выполнения данной команды",
                    "Нет прав!")
                required_perms = "\n".join(
                    perm.special_name for perm in
                    sorted(command.permissions, key=lambda x: x.value) +
                    sorted(command.future_permissions, key=lambda x: x.value))
                embed.add_field(name="Необходимые права:",
                                value=required_perms)
                await message.channel.send(embed=embed)
                await message.add_reaction(emoji_warn)
                return
            async with message.channel.typing():
                result = await command.execute(message, args_1, keys)
        except ParseError as e:
            await message.add_reaction(emoji_warn)
            await bot.send_error_embed(message.channel, str(e),
                                       "Ошибка разбора аргументов")
        except discord.Forbidden:
            await message.add_reaction(emoji_error)
            await bot.send_error_embed(message.channel, "У бота нет прав!")
        except AccessDeniedException:
            await message.add_reaction(emoji_warn)
            await bot.send_error_embed(
                message.channel,
                "У вас недостаточно прав для выполнения данной команды",
                "Нет прав!")
        except CommandException as e:
            await message.add_reaction(emoji_warn)
            await bot.send_error_embed(message.channel, str(e), e.title)
        except OpenComputersError as e:
            await bot.send_error_embed(message.channel,
                                       "```\n%s\n```" % str(e),
                                       "⚠ Криворукий уебан, у тебя ошибка! ⚠")
            await message.add_reaction(emoji_error)
        except Exception:
            await bot.send_error_embed(message.channel,
                                       "```\n%s\n```" % traceback.format_exc(),
                                       "⚠ Криворукий уебан, у тебя ошибка! ⚠")
            await message.add_reaction(emoji_error)
        else:
            if result == CommandResult.success:
                await message.add_reaction(emoji_ok)
            elif result == CommandResult.arguments_insufficient:
                embed: discord.Embed = bot.get_error_embed(
                    title="Недостаточно аргументов!")
                embed.add_field(name="%s%s %s" %
                                (cmd_prefix, command.name, command.arguments),
                                value=command.description)
                await message.channel.send(embed=embed)
                await message.add_reaction(emoji_warn)
Exemplo n.º 3
0
def main():
    from core.utils import parse
    from core.fl import Lexer, Parser
    for section in filter(None, s.splitlines()):
        tokens = parse(Lexer, Parser, None, section)
        print section
Exemplo n.º 4
0
def main():
    from core.utils import parse
    from core.fl import Lexer, Parser
    for section in filter(None, s.splitlines()):
        tokens = parse(Lexer, Parser, None, section)
        print section