示例#1
0
async def urban_dictionary(_client, message):
    if len(message.text.split()) == 1:
        await message.edit("Usage: `ud example`")
        return
    text = message.text.split(None, 1)[1]
    response = requests.get(
        "http://api.urbandictionary.com/v0/define?term={}".format(text))
    if response.status_code == 200:
        data = response.json()
        word = json.dumps(data['list'][0]['word'])
        definition = json.dumps(data['list'][0]['definition'])
        example = json.dumps(data['list'][0]['example'])
        teks = "**Text: {}**\n**Meaning:**\n`{}`\n\n**Example:**\n`{}`".format(
            replace_text(word), replace_text(definition),
            replace_text(example))
        await message.edit(teks)
        return
    elif response.status_code == 404:
        await message.edit("Cannot connect to Urban Dictionary")
示例#2
0
async def character(client, message):
    cmd = message.command
    search_query = ""
    if len(cmd) > 1:
        search_query = " ".join(cmd[1:])
    elif message.reply_to_message and len(cmd) == 1:
        search_query = message.reply_to_message.text
    elif not message.reply_to_message and len(cmd) == 1:
        await message.edit("Usage: `character`")
        await asyncio.sleep(2)
        await message.delete()
        return
    await message.delete()
    jikan = jikanpy.jikan.Jikan()
    try:
        search_result = jikan.search("character", search_query)
    except jikanpy.APIException:
        await message.edit("Character not found.")
        return
    first_mal_id = search_result["results"][0]["mal_id"]
    character = jikan.character(first_mal_id)
    caption = f"[{character['name']}]({character['url']})"
    if character['name_kanji'] != "Japanese":
        caption += f" ({character['name_kanji']})\n"
    else:
        caption += "\n"

    if character['nicknames']:
        nicknames_string = ", ".join(character['nicknames'])
        caption += f"\n**Nicknames** : `{nicknames_string}`"
    about = character['about'].split(" ", 60)
    try:
        about.pop(60)
    except IndexError:
        pass
    about_string = ' '.join(about)
    mal_url = search_result["results"][0]['url']
    for entity in character:
        if character[entity] is None:
            character[entity] = "Unknown"
    caption += f"\n**About**: {about_string}"
    caption += f" [Read More]({mal_url})..."
    await client.send_photo(message.chat.id,
                            photo=character['image_url'],
                            caption=replace_text(caption),
                            reply_to_message_id=ReplyCheck(message),
                            parse_mode='markdown'
                        )
示例#3
0
async def cas(client, message):
    cmd = message.command

    user = ""
    if len(cmd) > 1:
        user = "******".join(cmd[1:])
    elif message.reply_to_message and len(cmd) == 1:
        user = message.reply_to_message.text
    elif not message.reply_to_message and len(cmd) == 1:
        await message.edit("`Usage: cas user_id`")
        await asyncio.sleep(2)
        await message.delete()
        return
    results = requests.get(f'https://api.cas.chat/check?user_id={user}').json()
    try:
        reply_text = f'`User ID: `{user}\n`Offenses: `{results["result"]["offenses"]}\n`Messages: `\n{results["result"]["messages"]}\n`Time Added: `{results["result"]["time_added"]}'
    except:
        reply_text = "`Record not found.`"
    await message.edit(replace_text(reply_text))
示例#4
0
async def character(client, message):
    res = ""
    cmd = message.command
    query = ""
    if len(cmd) > 1:
        query = " ".join(cmd[1:])
    elif message.reply_to_message and len(cmd) == 1:
        query = message.reply_to_message.text
    elif not message.reply_to_message and len(cmd) == 1:
        await message.edit("`cant find character.`")
        await asyncio.sleep(2)
        await message.delete()
        return
    try:
        search = jikan.search("character",
                              query).get("results")[0].get("mal_id")
    except APIException:
        message.edit("No results found!")
        return ""
    if search:
        try:
            res = jikan.character(search)
        except APIException:
            message.edit("Error connecting to the API. Please try again!")
            return ""
    if res:
        name = res.get("name")
        kanji = res.get("name_kanji")
        about = res.get("about")
        if len(about) > 4096:
            about = about[:4000] + "..."
        image = res.get("image_url")
        url = res.get("url")
        rep = f"<b>{name} ({kanji})</b>\n\n"
        rep += f"<a href='{image}'>\u200c</a>"
        rep += f"<i>{about}</i>\n"
        rep += f'Read More: <a href="{url}">MyAnimeList</a>'
        await message.edit(replace_text(rep))