Beispiel #1
0
# You should have received a copy of the GNU General Public License
# along with TG-UserBot.  If not, see <https://www.gnu.org/licenses/>.

from logging import StreamHandler

from userbot import (__copyright__, __license__, client, ROOT_LOGGER,
                     verifyLoggerGroup)
from userbot.helper_funcs.log_formatter import CustomFormatter
from userbot.utils.helpers import printUser, printVersion
from userbot.utils.pluginManager import PluginManager

handler = StreamHandler()

handler.setFormatter(CustomFormatter())
ROOT_LOGGER.addHandler(handler)

print(__copyright__)
print("Licensed under the terms of the " + __license__)

if __name__ == "__main__":
    client.pluginManager = PluginManager(client)
    client.pluginManager.import_all()
    client.pluginManager.add_handlers()
    client.start()

    verifyLoggerGroup(client)
    printUser(client.loop.run_until_complete(client.get_me()))
    printVersion(client.version, client.prefix)

    client.run_until_disconnected()
Beispiel #2
0
                LOGGER.warning(
                    f"Fixed DC ID in session from {client.session.dc_id}"
                    f" to {option.id}")
            client.session.set_dc(option.id, option.ip_address, option.port)
            client.session.save()
            break
    try:
        client.start()
    except (AuthKeyError, InvalidBufferError):
        client.session.delete()
        LOGGER.error(
            "Your old session was invalid and has been automatically deleted! "
            "Run the script again to generate a new session.")
        sys.exit(1)

    userbot.verifyLoggerGroup(client)
    helpers.printUser(client.loop.run_until_complete(client.get_me()))
    helpers.printVersion(client.version, client.prefix)
    client.loop.create_task(helpers.isRestart(client))

    try:
        if sys.platform.startswith('win'):
            client.loop.call_later(0.1, wakeup)  # Needed for SIGINT handling
        client.loop.run_until_complete(client.disconnected)
        if client.reconnect:
            LOGGER.info("Client was disconnected, restarting the script.")
            helpers.restarter(client)
    except NotImplementedError:
        pass
    except KeyboardInterrupt:
        print()