read from .env

This commit is contained in:
yair 2023-03-18 00:24:46 +02:00
parent cae44e0e3b
commit 4cfa3e9812

12
main.py
View File

@ -7,6 +7,7 @@ import base64
from PIL import Image, PngImagePlugin from PIL import Image, PngImagePlugin
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.types import * from pyrogram.types import *
from dotenv import load_dotenv
# Done! Congratulations on your new bot. You will find it at # Done! Congratulations on your new bot. You will find it at
# t.me/gootmornbot # t.me/gootmornbot
@ -17,12 +18,12 @@ from pyrogram.types import *
# For a description of the Bot API, see this page: https://core.telegram.org/bots/api # For a description of the Bot API, see this page: https://core.telegram.org/bots/api
load_dotenv()
API_ID = os.environ.get("API_ID", None) API_ID = os.environ.get("API_ID", None)
API_HASH = os.environ.get("API_HASH", None) API_HASH = os.environ.get("API_HASH", None)
TOKEN = os.environ.get("TOKEN", None) TOKEN = os.environ.get("TOKEN", None)
SD_URL = os.environ.get("SD_URL", None) SD_URL = os.environ.get("SD_URL", None)
print(SD_URL) print(SD_URL)
app = Client( app = Client(
"stable", "stable",
api_id=API_ID, api_id=API_ID,
@ -45,9 +46,8 @@ def draw(client, message):
r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json() r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json()
# save the image to a file # explaination
def genr():
def genr(): # generate random string
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
chars1 = "1234564890" chars1 = "1234564890"
gen1 = random.choice(chars) gen1 = random.choice(chars)
@ -83,7 +83,7 @@ def draw(client, message):
K.delete() K.delete()
# get the models, choose one, and set it as the model checkpoint
@app.on_message(filters.command(["getmodels"])) @app.on_message(filters.command(["getmodels"]))
async def get_models(client, message): async def get_models(client, message):
response = requests.get(url=f'{SD_URL}/sdapi/v1/sd-models') response = requests.get(url=f'{SD_URL}/sdapi/v1/sd-models')
@ -121,7 +121,7 @@ async def process_callback(client, callback_query):
await callback_query.message.reply_text("Error setting options") await callback_query.message.reply_text("Error setting options")
# start the bot
@app.on_message(filters.command(["start"], prefixes=["/", "!"])) @app.on_message(filters.command(["start"], prefixes=["/", "!"]))
async def start(client, message): async def start(client, message):
# Photo = "https://i.imgur.com/79hHVX6.png" # Photo = "https://i.imgur.com/79hHVX6.png"