예제 #1
0
def parse_args():
    parser = argparse.ArgumentParser(description="Unoficial CLI for dict.cc. "\
        "It supports translations between the following languages: {}".format(
        ", ".join(AVAILABLE_LANGUAGES)))
    parser.add_argument("input_language",
                        type=str,
                        help="Input language",
                        choices=AVAILABLE_LANGUAGES.keys())
    parser.add_argument("output_language",
                        type=str,
                        help="Output language",
                        choices=AVAILABLE_LANGUAGES.keys())
    parser.add_argument("word",
                        type=ensure_unicode,
                        help=("Word to translate (use quotation marks for "
                              "phrases like \"free beer\")."))
    parser.add_argument("--max-results",
                        "-n",
                        type=int,
                        default=10,
                        help="Number of results to display. -1 for no limit.")
    parser.add_argument("--color",
                        "-c",
                        type=str2bool,
                        default=True,
                        help="Use color in output.")
    args = parser.parse_args()

    if args.input_language == args.output_language:
        raise ValueError("Please choose different languages")

    return args
예제 #2
0
def parse_args():
    parser = argparse.ArgumentParser(description="Unoficial CLI for dict.cc. "\
        "It supports translations between the following languages: {}".format(
        ", ".join(AVAILABLE_LANGUAGES)))
    parser.add_argument("input_language", type=str, help="Input language",
        choices=AVAILABLE_LANGUAGES.keys())
    parser.add_argument("output_language", type=str, help="Output language",
        choices=AVAILABLE_LANGUAGES.keys())
    parser.add_argument("word", type=str, help="""Word to translate (use
                        quotation marks for phrases like \"free beer\").""")
    parser.add_argument("--max-results", type=int, default=10)
    args = parser.parse_args()

    if args.input_language == args.output_language:
        raise ValueError("Please choose different languages")

    return args
예제 #3
0
        if len(text) > 2000:
            text = text[:2000] + "…"
        embed.add_field(name=f"[{word_type}]", value=text, inline=False)

    await message.channel.send(embed=embed)


@register_command(
    'dict',
    description='Dict will show you translation for your input/output language.'
)
@add_argument('keyword', help="Keyword for translation.")
@add_argument('--in-lang',
              '-i',
              default="de",
              choices=AVAILABLE_LANGUAGES.keys(),
              help='Input language.')
@add_argument('--out-lang',
              '-o',
              default="en",
              choices=AVAILABLE_LANGUAGES.keys(),
              help="Output language.")
async def dict_cc(client, message, args):
    trans_tuples = run_dict(args.keyword, args.in_lang, args.out_lang)

    if not trans_tuples:
        return await message.channel.send('Nothing Found')

    quote = urllib.parse.quote(args.keyword)
    embed = discord.Embed(
        title=f"Search for '{args.keyword}' ({args.in_lang} ⇔ {args.out_lang})",