web.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pcbot 作者: pckv 项目源码 文件源码
def define(message: discord.Message, term: Annotate.LowerCleanContent):
    """ Defines a term using Urban Dictionary. """
    json = await utils.download_json("http://api.urbandictionary.com/v0/define", term=term)
    assert json["list"], "Could not define `{}`.".format(term)

    definitions = json["list"]
    msg = ""

    # Send any valid definition (length of message < 2000 characters)
    for definition in definitions:
        # Format example in code if there is one
        if definition.get("example"):
            definition["example"] = "```{}```".format(definition["example"])

        # Format definition
        msg = "**{word}**:\n{definition}{example}".format(**definition)

        # If this definition fits in a message, break the loop so that we can send it
        if len(msg) <= 2000:
            break

    # Cancel if the message is too long
    assert len(msg) <= 2000, "Defining this word would be a bad idea."

    await client.say(message, msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号