Beispiel #1
0
def main():
    def stop_and_restart():
        updater.stop()
        os.execl(sys.executable, sys.executable, *sys.argv)

    def restart(update, context):
        context.bot.sendMessage(update.effective_chat.id, "Rebooted ✨")
        Thread(target=stop_and_restart).start()

    restart_handler = CommandHandler("reboot",
                                     restart,
                                     filters=Filters.user(DEV_ID))
    start_handler = CommandHandler("start", start)
    help_funcs_handler = CallbackQueryHandler(h_for_funcs, pattern=r"h_")
    help_handler = CallbackQueryHandler(help_button, pattern=r"help")
    back_btn_handler = CallbackQueryHandler(back_btn, pattern=r"back_btn")

    dp.add_handler(restart_handler)
    dp.add_handler(start_handler)
    dp.add_handler(help_funcs_handler)
    dp.add_handler(help_handler)
    dp.add_handler(back_btn_handler)

    LOG.info("%s", BANNER)

    # Start the bot.
    updater.start_polling(timeout=15, read_latency=4)
    updater.idle()
Beispiel #2
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 #3
0
def broadcast(update, context):
    to_send = update.effective_message.text.split(None, 1)
    if len(to_send) >= 2:
        users = sql.get_all_users() or []
        failed = 0
        for user in users:
            try:
                context.bot.sendMessage(int(user.user_id), to_send[1])
                sleep(0.1)
            except TelegramError:
                failed += 1
                LOG.warning(
                    "Couldn't send broadcast to %s, username %s",
                    str(user.user_id),
                    str(user.username),
                )

        update.effective_message.reply_text(
            "Broadcast complete. {} users failed to receive the message, probably "
            "due to being Blocked.".format(failed)
        )
Beispiel #4
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 #5
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
Beispiel #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# MIT License
# Copyright (c) 2020 Stɑrry Shivɑm // This file is part of AcuteBot
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.



from acutebot import LOG
from os.path import dirname, basename, isfile
import glob

def list_modules():
    mod_paths = glob.glob(dirname(__file__) + "/*.py")
    all_modules = [basename(f)[:-3] for f in mod_paths if isfile(f)
                   and f.endswith(".py")
                   and not f.endswith('__init__.py')]
    return all_modules

ALL_FUNCS = sorted(list_modules())
LOG.info("Modules loaded: %s", str(ALL_FUNCS))
__all__ = ALL_FUNCS + ["ALL_FUNCS"]