Exemple #1
0
 def decorator(func):
     if not disable_edited:
         bot.add_event_handler(func, events.MessageEdited(**args))
     bot.add_event_handler(func, events.NewMessage(**args))
     if client2:
         client2.add_event_handler(func, events.NewMessage(**args))
     if client3:
         client3.add_event_handler(func, events.NewMessage(**args))
     try:
         LOAD_PLUG[file_test].append(func)
     except Exception:
         LOAD_PLUG.update({file_test: [func]})
     return func
Exemple #2
0
    def decorator(func):
        async def wrapper(check):
            # Ignore Fwds
            if check.fwd_from:
                return
            # Works Only In Groups
            if group_only and not check.is_group:
                await check.respond("`Are you sure this is a group?`")
                return
            # Works Only in Channel
            if chnnl_only and not check.is_channel:
                await check.respond("This Command Only Works In Channel!")
                return
            # Works Only in Private Chat
            if pm_only and not check.is_private:
                await check.respond("`This Cmd Only Works On PM!`")
                return
            # Don't Give Access To Others Using Inline Search.
            if check.via_bot_id and check.out:
                return
            try:
                await func(check)
            except events.StopPropagation:
                raise events.StopPropagation
            except KeyboardInterrupt:
                pass
            except BaseException as e:
                sedprint.exception(str(e))
                if not disable_errors:
                    TZ = pytz.timezone(Config.TZ)
                    datetime_tz = datetime.now(TZ)
                    text = "ERROR - REPORT\n\n"
                    text += datetime_tz.strftime(
                        "Date : %Y-%m-%d \nTime : %H:%M:%S")
                    text += "\nGroup ID: " + str(check.chat_id)
                    text += "\nSender ID: " + str(check.sender_id)
                    text += "\n\nEvent Trigger:\n"
                    text += str(check.text)
                    text += "\n\nTraceback info:\n"
                    text += str(format_exc())
                    text += "\n\nError text:\n"
                    text += str(sys.exc_info()[1])
                    file = open("error.log", "w+")
                    file.write(text)
                    file.close()
                    try:
                        await check.client.send_file(
                            Config.PRIVATE_GROUP_ID,
                            "error.log",
                            caption="Error LoG, Please Forward To @FridayChat!",
                        )
                    except:
                        await check.client.send_file(
                            bot.uid,
                            "error.log",
                            caption="Error LoG, Please Forward To @FridayChat!",
                        )
                    os.remove("error.log")

        bot.add_event_handler(wrapper, events.NewMessage(**args))
        if client2:
            client2.add_event_handler(wrapper, events.NewMessage(**args))
        if client3:
            client3.add_event_handler(wrapper, events.NewMessage(**args))
        return wrapper
Exemple #3
0
    def decorator(func):
        async def wrapper(check):
            if not PRIVATE_GROUP_ID:
                send_to = check.chat_id
            else:
                send_to = PRIVATE_GROUP_ID

            if not trigger_on_fwd and check.fwd_from:
                return

            if groups_only and not check.is_group:
                await check.respond("`I don't think this is a group.`")
                return

            try:
                await func(check)

            # Thanks to @kandnub for this HACK.
            # Raise StopPropagation to Raise StopPropagation
            # This needed for AFK to working properly

            except events.StopPropagation:
                raise events.StopPropagation
            # This is a gay exception and must be passed out. So that it doesnt spam chats
            except KeyboardInterrupt:
                pass
            except BaseException:

                # Check if we have to disable it.
                # If not silence the log spam on the console,
                # with a dumb except.

                if not disable_errors:
                    date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

                    text = "**USERBOT ERROR REPORT**\n"
                    link = "[PaperplaneExtended Support Chat](https://t.me/PaperplaneExtendedSupport)"
                    text += "If you want to, you can report it"
                    text += f"- just forward this message to {link}.\n"
                    text += "Nothing is logged except the fact of error and date\n"

                    ftext = "========== DISCLAIMER =========="
                    ftext += "\nThis file uploaded ONLY here,"
                    ftext += "\nwe logged only fact of error and date,"
                    ftext += "\nwe respect your privacy,"
                    ftext += "\nyou may not report this error if you've"
                    ftext += "\nany confidential data here, no one will see your data\n"
                    ftext += "================================\n\n"
                    ftext += "--------BEGIN USERBOT TRACEBACK LOG--------\n"
                    ftext += "\nDate: " + date
                    ftext += "\nChat ID: " + str(check.chat_id)
                    ftext += "\nSender ID: " + str(check.sender_id)
                    ftext += "\n\nEvent Trigger:\n"
                    ftext += str(check.text)
                    ftext += "\n\nTraceback info:\n"
                    ftext += str(format_exc())
                    ftext += "\n\nError text:\n"
                    ftext += str(sys.exc_info()[1])
                    ftext += "\n\n--------END USERBOT TRACEBACK LOG--------"

                    command = 'git log --pretty=format:"%an: %s" -10'

                    ftext += "\n\n\nLast 10 commits:\n"

                    process = await asyncsubshell(command,
                                                  stdout=asyncsub.PIPE,
                                                  stderr=asyncsub.PIPE)
                    stdout, stderr = await process.communicate()
                    result = str(stdout.decode().strip()) + str(
                        stderr.decode().strip())

                    ftext += result

                    file = open("error.log", "w+")
                    file.write(ftext)
                    file.close()

                    if LOGSPAMMER:
                        await check.client.respond(
                            "`Sorry, my fridaybot has crashed.\
                        \nThe error logs are stored in the fridaybot's log chat.`"
                        )

                    await check.client.send_file(send_to,
                                                 "error.log",
                                                 caption=text)
                    remove("error.log")
            else:
                pass

        if not disable_edited:
            bot.add_event_handler(wrapper, events.MessageEdited(**args))
        bot.add_event_handler(wrapper, events.NewMessage(**args))
        if starkclient:
            starkclient.add_event_handler(wrapper, events.NewMessage(**args))
        if warnerclient:
            warnerclient.add_event_handler(wrapper, events.NewMessage(**args))
        return wrapper