Beispiel #1
0
def rmemes(update, context):
    msg = update.effective_message
    chat = update.effective_chat

    SUBREDS = [
        "meirl",
        "dankmemes",
        "AdviceAnimals",
        "memes",
        "meme",
        "memes_of_the_dank",
        "PornhubComments",
        "teenagers",
        "memesIRL",
        "insanepeoplefacebook",
        "terriblefacebookmemes",
        "animememes",
        "Animemes",
        "memeeconomy",
    ]

    subreddit = random.choice(SUBREDS)
    res = r.get(f"https://meme-api.herokuapp.com/gimme/{subreddit}")

    if res.status_code != 200:  # Like if api is down?
        return msg.reply_text(st.API_ERR)
    res = res.json()

    keyb = [[InlineKeyboardButton(text=f"r/{res['subreddit']}", url=res["postLink"])]]
    try:
        context.bot.send_chat_action(chat.id, "upload_photo")
        context.bot.send_photo(
            chat.id,
            photo=res["url"],
            caption=(res["title"]),
            reply_markup=InlineKeyboardMarkup(keyb),
            timeout=60,
        )

    except BadRequest as excp:
        LOG.error(excp)
Beispiel #2
0
def sendlyrics(update, context):
    chat = update.effective_chat
    msg = update.effective_message
    user = update.effective_user
    artist = update.message.text

    try:
        song = SONGDICT[user.id]
    except KeyError:
        msg.reply_text(st.LYRICS_ERR)
        return -1
    rep = msg.reply_text("🔍 Looking for lyrics . . .")
    lyrics = genius.search_song(song, artist)
    if lyrics is None:
        msg.reply_text(st.LYRIC_NOT_FOUND)
        rep.delete()
        return -1
    try:
        msg.reply_text(f"🎸 <b>{song}</b> by <b>{artist}</b>:\n\n{lyrics.lyrics}")

    except BadRequest as excp:
        if excp.message == "Message is too long":
            msg.reply_text(st.LYRICS_TOO_BIG)
            with open("acute-lyrics.txt", "w+") as f:
                f.write(f"🎧 {song} by {artist}\n\n{lyrics.lyrics}")
            context.bot.sendDocument(
                chat_id=chat.id,
                document=open("acute-lyrics.txt", "rb"),
                caption=f"🎸 {song} - {artist}",
            )
            os.remove("acute-lyrics.txt")
        else:
            LOG.error(excp.message)

    rep.delete()
    del SONGDICT[user.id]
    return -1
Beispiel #3
0
def sendmusic(update, context):
    user = update.effective_user
    msg = update.effective_message
    chat = update.effective_chat

    artist = update.message.text
    try:
        song = MUSICDICT[user.id]["mn"]
        quality = MUSICDICT[user.id]["q"]
    except KeyError:
        msg.reply_text(st.LYRICS_ERR)
        return -1

    if quality == "🎧 320KBs":
        ql = "MP3_320"
    elif quality == "🎶 FLAC":
        ql = "FLAC"
    elif quality == "🎵 256KBs":
        ql = "MP3_256"

    try:
        context.bot.send_chat_action(chat.id, "upload_document")
        file = downloa.download_name(
            artist=artist,
            song=song,
            output="temp",
            quality=ql,
            recursive_quality=True,
            recursive_download=True,
            not_interface=True,
        )
    except (TrackNotFound, NoDataApi):
        msg.reply_text(st.MUSICNOTFOUND)
        return -1

    try:
        # Fetch correct details from metadata:
        aud = mutagen.File(file)
        title = aud.get("title")
        if title:
            title = str(title[0])
        artist = aud.get("artist")
        if artist:
            artist = str(artist[0])
        duration = aud.get("length")
        if duration:
            duration = int(duration[0])

        if Path(file).stat().st_size < 50000000:
            rep = msg.reply_text(st.UPLOAD_BOTAPI)
            context.bot.sendAudio(
                chat.id,
                open(file, "rb"),
                caption="Via @acutebot 🎸",
                title=title,
                performer=artist,
                duration=duration,
                timeout=120,
            )
        else:
            rep = msg.reply_text(st.UPLOAD_MTPROTO)
            send_file_pyro(context.bot.token, file, chat.id, title, artist,
                           duration)
        rep.delete()

    except Exception as e:
        LOG.error(e)

    if os.path.isfile(file):
        os.remove(file)
    del MUSICDICT[user.id]
    return ConversationHandler.END