Last active
January 13, 2021 14:40
-
-
Save nedludd0/c94a2491da397eed5af86c73c0a12d16 to your computer and use it in GitHub Desktop.
borg_pyrogram.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| SINGLETON CLASS ENCAPSULATING A PYROGRAM TELEGRAM CLIENT | |
| Credit: https://gist.github.com/skeeved/79dfe5652b20182586bb55c3cbc94250 | |
| """ | |
| """ Config """ | |
| from os import environ | |
| BOT_TOKEN = environ.get('BOT_TOKEN') | |
| API_ID = environ.get('API_ID') | |
| API_HASH = environ.get('API_HASH') | |
| WORKDIR = environ.get('WORKDIR') | |
| """ Borg pattern singleton """ | |
| from pyrogram import Client | |
| import sys | |
| class PyrogramClientClass: | |
| __state = {} | |
| def __init__(self): | |
| self.__dict__ = self.__state | |
| if not hasattr(self, 'client'): | |
| self.client = Client('Example-Name-BOT', bot_token = BOT_TOKEN, api_id = API_ID, api_hash = API_HASH, workdir = WORKDIR) | |
| if __name__ == '__main__': | |
| pyrogram_client_obj = PyrogramClientClass().client | |
| pyrogram_client_obj.start() | |
| msg_sent = pyrogram_client_obj.send_message("TG_ID", "MESSAGE TEXT") | |
| pyrogram_client_obj.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment