forked from soaska/sd_telegram
combined into an array VK and OK
prompt output for inf without use_prompt added fast params delete disable-nan-check (add lifehack to readme)
This commit is contained in:
parent
46859f798c
commit
c9739d7263
@ -31,6 +31,7 @@ ___**reset_param**
|
|||||||
reset to default
|
reset to default
|
||||||
___**fast_param**
|
___**fast_param**
|
||||||
reset to my default params
|
reset to my default params
|
||||||
|
comp, mobile, no hr, big, inc, w↔h
|
||||||
__**scrpts**
|
__**scrpts**
|
||||||
___**get_lora**
|
___**get_lora**
|
||||||
get list LORA`s from stable-diffusion-webui/models/Lora
|
get list LORA`s from stable-diffusion-webui/models/Lora
|
||||||
@ -90,7 +91,7 @@ Before that, you need to set up a token and enter the ID of the album where the
|
|||||||
3. Get all files/pictures from the computer for today (preview and seeds)
|
3. Get all files/pictures from the computer for today (preview and seeds)
|
||||||
4. Ability to send everything with one command with settings
|
4. Ability to send everything with one command with settings
|
||||||
5. Preloading photos when waiting for a long time so that you can skip
|
5. Preloading photos when waiting for a long time so that you can skip
|
||||||
6. Progress in script
|
6. Progress in script (done with no HR)
|
||||||
7. Translator capable of translating up to 4000 characters and detecting the language
|
7. Translator capable of translating up to 4000 characters and detecting the language
|
||||||
|
|
||||||
**TNX**
|
**TNX**
|
||||||
@ -101,4 +102,7 @@ And respect for Santa 🎅
|
|||||||
|
|
||||||
Donations are **not needed**. Who wants to subscribe to [my generations](https://t.me/mishgenai)
|
Donations are **not needed**. Who wants to subscribe to [my generations](https://t.me/mishgenai)
|
||||||
|
|
||||||
|
Lifehack`s:
|
||||||
|
If Lora dont work, see [this](https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/7984?ref=blog.hinablue.me#issuecomment-1514312942)
|
||||||
|
|
||||||
© _Mishgen_
|
© _Mishgen_
|
203
bot.py
203
bot.py
@ -45,8 +45,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# from https://t.me/BotFather
|
# from https://t.me/BotFather
|
||||||
API_BOT_TOKEN = "TOKEN_HERE"
|
API_BOT_TOKEN = "TOKEN_HERE"
|
||||||
#заходим в https://oauth.vk.com/authorize?client_id=123&scope=photos&redirect_uri=http%3A%2F%2Foauth.vk.com%2Fblank.html&display=page&response_type=token,
|
#заходим в https://oauth.vk.com/authorize?client_id=51626357&scope=photos&redirect_uri=http%3A%2F%2Foauth.vk.com%2Fblank.html&display=page&response_type=token
|
||||||
# где 123 - номер вашего включенного приложения, созданного в https://vk.com/apps?act=manage,
|
# где 51626357 - номер вашего включенного приложения, созданного в https://vk.com/apps?act=manage,
|
||||||
# photos - зона доступа.
|
# photos - зона доступа.
|
||||||
# После перехода и подтверждения выцепляем access_token из адресной строки
|
# После перехода и подтверждения выцепляем access_token из адресной строки
|
||||||
# TODO auto requests
|
# TODO auto requests
|
||||||
@ -58,8 +58,8 @@ API_BOT_TOKEN = "TOKEN_HERE"
|
|||||||
# Ссылка на страницу = https://apiok.ru/oauth_callback
|
# Ссылка на страницу = https://apiok.ru/oauth_callback
|
||||||
# Список разрешённых redirect_uri = https://apiok.ru/oauth_callback
|
# Список разрешённых redirect_uri = https://apiok.ru/oauth_callback
|
||||||
# сохранить, перезайти
|
# сохранить, перезайти
|
||||||
# Ищем ID приложения справа от "Основные настройки приложения" - ID 123
|
# Ищем ID приложения справа от "Основные настройки приложения" - ID 512002358821
|
||||||
# Открываем в браузере https://connect.ok.ru/oauth/authorize?client_id=123&scope=PHOTO_CONTENT;VALUABLE_ACCESS&response_type=token&redirect_uri=https://apiok.ru/oauth_callback
|
# Открываем в браузере https://connect.ok.ru/oauth/authorize?client_id=512002358821&scope=PHOTO_CONTENT;VALUABLE_ACCESS&response_type=token&redirect_uri=https://apiok.ru/oauth_callback
|
||||||
# С адресной строки копируем token в access_token ниже
|
# С адресной строки копируем token в access_token ниже
|
||||||
# application_key = Публичный ключ справа от "Основные настройки приложения"
|
# application_key = Публичный ключ справа от "Основные настройки приложения"
|
||||||
# Вечный access_token - Получить новый
|
# Вечный access_token - Получить новый
|
||||||
@ -71,6 +71,7 @@ OK_ACCESS_TOKEN = 'OK_ACCESS_TOKEN_HERE'
|
|||||||
OK_APPLICATION_KEY = 'OK_APPLICATION_KEY_HERE'
|
OK_APPLICATION_KEY = 'OK_APPLICATION_KEY_HERE'
|
||||||
OK_APPLICATION_SECRET_KEY = 'OK_APPLICATION_SECRET_KEY_HERE'
|
OK_APPLICATION_SECRET_KEY = 'OK_APPLICATION_SECRET_KEY_HERE'
|
||||||
OK_GROUP_ID = 'OK_GROUP_ID_HERE'
|
OK_GROUP_ID = 'OK_GROUP_ID_HERE'
|
||||||
|
ARRAY_INLINE = []
|
||||||
|
|
||||||
bot = Bot(token=API_BOT_TOKEN)
|
bot = Bot(token=API_BOT_TOKEN)
|
||||||
storage = MemoryStorage()
|
storage = MemoryStorage()
|
||||||
@ -132,7 +133,7 @@ def start_sd():
|
|||||||
global process, sd
|
global process, sd
|
||||||
if not process:
|
if not process:
|
||||||
logging.info('start_process start_sd')
|
logging.info('start_process start_sd')
|
||||||
process = subprocess.Popen(["python", "../../launch.py", "--nowebui", "--xformers", "--disable-nan-check"])
|
process = subprocess.Popen(["python", "../../launch.py", "--nowebui", "--xformers"]) #, "--disable-nan-check"
|
||||||
sd = "✅"
|
sd = "✅"
|
||||||
|
|
||||||
async def stop_sd():
|
async def stop_sd():
|
||||||
@ -399,6 +400,18 @@ def getSet(returnAll = 1) -> InlineKeyboardMarkup:
|
|||||||
]
|
]
|
||||||
return (getKeyboard(keysArr, returnAll))
|
return (getKeyboard(keysArr, returnAll))
|
||||||
|
|
||||||
|
# Меню быстрых параметров
|
||||||
|
def getFastParams(returnAll = 1) -> InlineKeyboardMarkup:
|
||||||
|
keysArr = [
|
||||||
|
InlineKeyboardButton("comp", callback_data="fp_comp"),
|
||||||
|
InlineKeyboardButton("mobile", callback_data="fp_mobile"),
|
||||||
|
InlineKeyboardButton("no hr", callback_data="fp_no_hr"),
|
||||||
|
InlineKeyboardButton("big", callback_data="fp_big"),
|
||||||
|
InlineKeyboardButton("inc", callback_data="fp_inc"),
|
||||||
|
InlineKeyboardButton("w↔h", callback_data="fp_wh"),
|
||||||
|
]
|
||||||
|
return (getKeyboard(keysArr, returnAll))
|
||||||
|
|
||||||
# Меню галочек Да/Нет
|
# Меню галочек Да/Нет
|
||||||
def getYesNo(returnAll = 1, nam = '') -> InlineKeyboardMarkup:
|
def getYesNo(returnAll = 1, nam = '') -> InlineKeyboardMarkup:
|
||||||
keysArr = [
|
keysArr = [
|
||||||
@ -536,14 +549,26 @@ async def show_thumbs(chat_id, res):
|
|||||||
chat_id=chat_id, media=pilToImages(res, "tg")
|
chat_id=chat_id, media=pilToImages(res, "tg")
|
||||||
)
|
)
|
||||||
if dataParams["img_real"] == "true" or dataParams["img_real"] == "True":
|
if dataParams["img_real"] == "true" or dataParams["img_real"] == "True":
|
||||||
mes_file = await bot.send_media_group(
|
messages = await bot.send_media_group(
|
||||||
chat_id=chat_id, media=pilToImages(res, "real")
|
chat_id=chat_id,
|
||||||
|
media=pilToImages(res, "real")
|
||||||
)
|
)
|
||||||
|
# send button load in VK
|
||||||
|
arr = []
|
||||||
|
i = 0
|
||||||
|
for mes_file in messages:
|
||||||
|
i = i + 1
|
||||||
|
print(mes_file)
|
||||||
|
ARRAY_INLINE.append({'message_id': str(mes_file.message_id),
|
||||||
|
'num_but': str(i),
|
||||||
|
'file_id': str(mes_file.document.file_id),
|
||||||
|
'prompt': get_prompt_settings(0)})
|
||||||
|
arr.append(InlineKeyboardButton(i, callback_data='send_vk|' + str(mes_file.message_id)))
|
||||||
await bot.send_message(
|
await bot.send_message(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
text="⬇ send to VK and OK ⬇",
|
text="⬇ send to VK and OK ⬇",
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
inline_keyboard=[[InlineKeyboardButton(mes_file[0].document.file_id, callback_data='send_vk')]])
|
inline_keyboard=[arr])
|
||||||
)
|
)
|
||||||
|
|
||||||
# -------- COMMANDS ----------
|
# -------- COMMANDS ----------
|
||||||
@ -696,8 +721,33 @@ async def inl_reset_param(message: Union[types.Message, types.CallbackQuery]) ->
|
|||||||
@dp.callback_query_handler(text="fast_param")
|
@dp.callback_query_handler(text="fast_param")
|
||||||
async def inl_fast_param(message: Union[types.Message, types.CallbackQuery]) -> None:
|
async def inl_fast_param(message: Union[types.Message, types.CallbackQuery]) -> None:
|
||||||
logging.info("inl_fast_param")
|
logging.info("inl_fast_param")
|
||||||
|
keyboard = InlineKeyboardMarkup(inline_keyboard=[getFastParams(0), getSet(0), getOpt(0), getStart(0)])
|
||||||
|
await getKeyboardUnion('Выбери быстрые настройки', message, keyboard, '')
|
||||||
|
|
||||||
|
# Список быстрых настроек
|
||||||
|
@dp.message_handler(commands=["fp_comp"])
|
||||||
|
@dp.message_handler(commands=["fp_mobile"])
|
||||||
|
@dp.message_handler(commands=["fp_no_hr"])
|
||||||
|
@dp.message_handler(commands=["fp_big"])
|
||||||
|
@dp.message_handler(commands=["fp_inc"])
|
||||||
|
@dp.message_handler(commands=["fp_wh"])
|
||||||
|
@dp.callback_query_handler(text="fp_comp")
|
||||||
|
@dp.callback_query_handler(text="fp_mobile")
|
||||||
|
@dp.callback_query_handler(text="fp_no_hr")
|
||||||
|
@dp.callback_query_handler(text="fp_big")
|
||||||
|
@dp.callback_query_handler(text="fp_inc")
|
||||||
|
@dp.callback_query_handler(text="fp_wh")
|
||||||
|
async def inl_fp(message: Union[types.Message, types.CallbackQuery]) -> None:
|
||||||
|
logging.info("inl_fp")
|
||||||
|
m = message.data
|
||||||
|
keyboard = InlineKeyboardMarkup(inline_keyboard=[getFastParams(0), getSet(0), getOpt(0), getStart(0)])
|
||||||
global data
|
global data
|
||||||
global dataParams
|
global dataParams
|
||||||
|
if m == 'fp_wh':
|
||||||
|
w = data['width']
|
||||||
|
data['width'] = data['height']
|
||||||
|
data['height'] = w
|
||||||
|
if m == 'fp_comp':
|
||||||
data['steps'] = 35
|
data['steps'] = 35
|
||||||
data['sampler_name'] = 'Euler a'
|
data['sampler_name'] = 'Euler a'
|
||||||
data['enable_hr'] = 'True'
|
data['enable_hr'] = 'True'
|
||||||
@ -716,8 +766,69 @@ async def inl_fast_param(message: Union[types.Message, types.CallbackQuery]) ->
|
|||||||
"img_real": "true",
|
"img_real": "true",
|
||||||
"stop_sd": "true",
|
"stop_sd": "true",
|
||||||
"use_prompt": "true"}
|
"use_prompt": "true"}
|
||||||
keyboard = InlineKeyboardMarkup(inline_keyboard=[getSet(0), getOpt(0), getStart(0)])
|
if m == 'fp_mobile':
|
||||||
txt = f"JSON сброшен\n{getJson()}\n{getJson(1)}"
|
data['steps'] = 15
|
||||||
|
data['enable_hr'] = 'false'
|
||||||
|
data['cfg_scale'] = '6'
|
||||||
|
data['width'] = '512'
|
||||||
|
data['height'] = '768'
|
||||||
|
data['do_not_save_grid'] = 'true'
|
||||||
|
data['negative_prompt'] = 'easynegative, bad-hands-5, bad-picture-chill-75v, bad-artist, bad_prompt_version2, rmadanegative4_sd15-neg, bad-image-v2-39000, illustration, painting, cartoons, sketch, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)), collapsed eyeshadow, multiple eyeblows, vaginas in breasts, (cropped), oversaturated, extra limb, missing limbs, deformed hands, long neck, long body, imperfect, (bad hands), signature, watermark, username, artist name, conjoined fingers, deformed fingers, ugly eyes, imperfect eyes, skewed eyes, unnatural face, unnatural body, error, asian, obese, tatoo, stacked torsos, totem pole, watermark, black and white, close up, cartoon, 3d, denim, (disfigured), (deformed), (poorly drawn), (extra limbs), blurry, boring, sketch, lackluster, signature, letters'
|
||||||
|
data['save_images'] = 'true'
|
||||||
|
dataParams = {"img_thumb": "true",
|
||||||
|
"img_tg": "false",
|
||||||
|
"img_real": "true",
|
||||||
|
"stop_sd": "true",
|
||||||
|
"use_prompt": "true"}
|
||||||
|
if m == 'fp_no_hr':
|
||||||
|
data['steps'] = 20
|
||||||
|
data['enable_hr'] = 'false'
|
||||||
|
data['cfg_scale'] = '7'
|
||||||
|
data['width'] = '512'
|
||||||
|
data['height'] = '768'
|
||||||
|
data['do_not_save_grid'] = 'true'
|
||||||
|
data['negative_prompt'] = 'easynegative, bad-hands-5, bad-picture-chill-75v, bad-artist, bad_prompt_version2, rmadanegative4_sd15-neg, bad-image-v2-39000, illustration, painting, cartoons, sketch, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)), collapsed eyeshadow, multiple eyeblows, vaginas in breasts, (cropped), oversaturated, extra limb, missing limbs, deformed hands, long neck, long body, imperfect, (bad hands), signature, watermark, username, artist name, conjoined fingers, deformed fingers, ugly eyes, imperfect eyes, skewed eyes, unnatural face, unnatural body, error, asian, obese, tatoo, stacked torsos, totem pole, watermark, black and white, close up, cartoon, 3d, denim, (disfigured), (deformed), (poorly drawn), (extra limbs), blurry, boring, sketch, lackluster, signature, letters'
|
||||||
|
data['save_images'] = 'true'
|
||||||
|
dataParams = {"img_thumb": "true",
|
||||||
|
"img_tg": "false",
|
||||||
|
"img_real": "true",
|
||||||
|
"stop_sd": "true",
|
||||||
|
"use_prompt": "true"}
|
||||||
|
if m == 'fp_big':
|
||||||
|
data['steps'] = 50
|
||||||
|
data['sampler_name'] = 'Euler a'
|
||||||
|
data['enable_hr'] = 'True'
|
||||||
|
data['denoising_strength'] = '0.7'
|
||||||
|
data['hr_upscaler'] = 'ESRGAN_4x'
|
||||||
|
data['hr_second_pass_steps'] = '20'
|
||||||
|
data['cfg_scale'] = '7'
|
||||||
|
data['width'] = '768'
|
||||||
|
data['height'] = '1024'
|
||||||
|
data['restore_faces'] = 'true'
|
||||||
|
data['do_not_save_grid'] = 'true'
|
||||||
|
data['negative_prompt'] = 'easynegative, bad-hands-5, bad-picture-chill-75v, bad-artist, bad_prompt_version2, rmadanegative4_sd15-neg, bad-image-v2-39000, illustration, painting, cartoons, sketch, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)), collapsed eyeshadow, multiple eyeblows, vaginas in breasts, (cropped), oversaturated, extra limb, missing limbs, deformed hands, long neck, long body, imperfect, (bad hands), signature, watermark, username, artist name, conjoined fingers, deformed fingers, ugly eyes, imperfect eyes, skewed eyes, unnatural face, unnatural body, error, asian, obese, tatoo, stacked torsos, totem pole, watermark, black and white, close up, cartoon, 3d, denim, (disfigured), (deformed), (poorly drawn), (extra limbs), blurry, boring, sketch, lackluster, signature, letters'
|
||||||
|
data['save_images'] = 'true'
|
||||||
|
dataParams = {"img_thumb": "false",
|
||||||
|
"img_tg": "true",
|
||||||
|
"img_real": "true",
|
||||||
|
"stop_sd": "true",
|
||||||
|
"use_prompt": "true"}
|
||||||
|
if m == 'fp_inc':
|
||||||
|
data['steps'] = 20
|
||||||
|
data['sampler_name'] = 'Euler a'
|
||||||
|
data['enable_hr'] = 'false'
|
||||||
|
data['cfg_scale'] = '7'
|
||||||
|
data['width'] = '512'
|
||||||
|
data['height'] = '768'
|
||||||
|
data['do_not_save_grid'] = 'true'
|
||||||
|
data['negative_prompt'] = 'easynegative, bad-hands-5, bad-picture-chill-75v, bad-artist, bad_prompt_version2, rmadanegative4_sd15-neg, bad-image-v2-39000, illustration, painting, cartoons, sketch, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)), collapsed eyeshadow, multiple eyeblows, vaginas in breasts, (cropped), oversaturated, extra limb, missing limbs, deformed hands, long neck, long body, imperfect, (bad hands), signature, watermark, username, artist name, conjoined fingers, deformed fingers, ugly eyes, imperfect eyes, skewed eyes, unnatural face, unnatural body, error, asian, obese, tatoo, stacked torsos, totem pole, watermark, black and white, close up, cartoon, 3d, denim, (disfigured), (deformed), (poorly drawn), (extra limbs), blurry, boring, sketch, lackluster, signature, letters'
|
||||||
|
data['save_images'] = 'false'
|
||||||
|
dataParams = {"img_thumb": "true",
|
||||||
|
"img_tg": "false",
|
||||||
|
"img_real": "false",
|
||||||
|
"stop_sd": "true",
|
||||||
|
"use_prompt": "true"}
|
||||||
|
txt = f"JSON отредактирован\n{getJson()}\n{getJson(1)}"
|
||||||
await getKeyboardUnion(txt, message, keyboard, '')
|
await getKeyboardUnion(txt, message, keyboard, '')
|
||||||
|
|
||||||
# Обработчик команды /skip
|
# Обработчик команды /skip
|
||||||
@ -749,7 +860,7 @@ async def inl_gen(message: Union[types.Message, types.CallbackQuery]) -> None:
|
|||||||
else:
|
else:
|
||||||
chatId = message.message.chat.id
|
chatId = message.message.chat.id
|
||||||
keyboard = InlineKeyboardMarkup(inline_keyboard=[getSet(0), getOpt(0), getStart(0)])
|
keyboard = InlineKeyboardMarkup(inline_keyboard=[getSet(0), getOpt(0), getStart(0)])
|
||||||
global sd
|
global sd, ARRAY_INLINE
|
||||||
dataPromptOld = data['prompt']
|
dataPromptOld = data['prompt']
|
||||||
if sd == '✅':
|
if sd == '✅':
|
||||||
for itemTxt in data['prompt'].split(';'):
|
for itemTxt in data['prompt'].split(';'):
|
||||||
@ -774,17 +885,26 @@ async def inl_gen(message: Union[types.Message, types.CallbackQuery]) -> None:
|
|||||||
chat_id=chatId, media=pilToImages(res, "tg")
|
chat_id=chatId, media=pilToImages(res, "tg")
|
||||||
)
|
)
|
||||||
if dataParams["img_real"] == "true" or dataParams["img_real"] == "True":
|
if dataParams["img_real"] == "true" or dataParams["img_real"] == "True":
|
||||||
mes_file = await bot.send_media_group(
|
messages = await bot.send_media_group(
|
||||||
chat_id=chatId,
|
chat_id=chatId,
|
||||||
media=pilToImages(res, "real")
|
media=pilToImages(res, "real")
|
||||||
)
|
)
|
||||||
# send button load in VK
|
# send button load in VK
|
||||||
# TODO long message
|
arr = []
|
||||||
|
i = 0
|
||||||
|
for mes_file in messages:
|
||||||
|
i = i + 1
|
||||||
|
print(mes_file)
|
||||||
|
ARRAY_INLINE.append({'message_id':str(mes_file.message_id),
|
||||||
|
'num_but':str(i),
|
||||||
|
'file_id':str(mes_file.document.file_id),
|
||||||
|
'prompt':get_prompt_settings(0)})
|
||||||
|
arr.append(InlineKeyboardButton(i, callback_data='send_vk|'+str(mes_file.message_id)))
|
||||||
await bot.send_message(
|
await bot.send_message(
|
||||||
chat_id=chatId,
|
chat_id=chatId,
|
||||||
text="⬇ send to VK and OK ⬇",
|
text="⬇ send to VK and OK ⬇",
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
inline_keyboard=[[InlineKeyboardButton(mes_file[0].document.file_id, callback_data='send_vk')]])
|
inline_keyboard=[arr])
|
||||||
)
|
)
|
||||||
await bot.send_message(
|
await bot.send_message(
|
||||||
chat_id=chatId,
|
chat_id=chatId,
|
||||||
@ -812,47 +932,63 @@ async def inl_gen(message: Union[types.Message, types.CallbackQuery]) -> None:
|
|||||||
|
|
||||||
# upload in VK
|
# upload in VK
|
||||||
# TODO actual prompt
|
# TODO actual prompt
|
||||||
@dp.callback_query_handler(text="send_vk")
|
@dp.callback_query_handler(text_startswith="send_vk")
|
||||||
async def send_vk(callback: types.CallbackQuery) -> None:
|
async def send_vk(callback: types.CallbackQuery) -> None:
|
||||||
try:
|
try:
|
||||||
# Export VK
|
global VK_TOKEN, VK_ALBUM_ID, OK_ACCESS_TOKEN, OK_APPLICATION_KEY, OK_APPLICATION_SECRET_KEY, OK_GROUP_ID, ARRAY_INLINE
|
||||||
global VK_TOKEN, VK_ALBUM_ID, OK_ACCESS_TOKEN, OK_APPLICATION_KEY, OK_APPLICATION_SECRET_KEY, OK_GROUP_ID
|
message_id = callback.data.split("|")[1]
|
||||||
file_id = callback.message.reply_markup.inline_keyboard[0][0].text #TODO
|
arrInlineItem = next(item for item in ARRAY_INLINE if item['message_id'] == message_id)
|
||||||
|
file_id = arrInlineItem['file_id']
|
||||||
|
num_but = arrInlineItem['num_but']
|
||||||
|
unique_prompt = arrInlineItem['prompt']
|
||||||
file_obj = await bot.get_file(file_id)
|
file_obj = await bot.get_file(file_id)
|
||||||
|
|
||||||
|
# Export VK
|
||||||
vk_session = vk_api.VkApi(token=VK_TOKEN)
|
vk_session = vk_api.VkApi(token=VK_TOKEN)
|
||||||
vk_upload = VkUpload(vk_session)
|
vk_upload = VkUpload(vk_session)
|
||||||
file_url = f'https://api.telegram.org/file/bot{API_BOT_TOKEN}/{file_obj.file_path}'
|
file_url = f'https://api.telegram.org/file/bot{API_BOT_TOKEN}/{file_obj.file_path}'
|
||||||
|
|
||||||
#TODO optimize
|
#TODO optimize
|
||||||
with open('temp.png', 'wb') as file:
|
with open('temp.png', 'wb') as file:
|
||||||
file.write(requests.get(file_url).content)
|
file.write(requests.get(file_url).content)
|
||||||
|
try:
|
||||||
vk_upload.photo(
|
vk_upload.photo(
|
||||||
photos='temp.png',
|
photos='temp.png',
|
||||||
album_id=VK_ALBUM_ID,
|
album_id=VK_ALBUM_ID,
|
||||||
caption=data['prompt'] #TODO actual from ID message
|
caption=unique_prompt
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
await bot.send_message(
|
||||||
|
chat_id=callback.message.chat.id,
|
||||||
|
text='VK ERROR = '+str(e),
|
||||||
|
parse_mode=types.ParseMode.HTML
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
# Export OK
|
# Export OK
|
||||||
ok = OkApi(
|
ok = OkApi(
|
||||||
access_token=OK_ACCESS_TOKEN,
|
access_token=OK_ACCESS_TOKEN,
|
||||||
application_key=OK_APPLICATION_KEY,
|
application_key=OK_APPLICATION_KEY,
|
||||||
application_secret_key=OK_APPLICATION_SECRET_KEY)
|
application_secret_key=OK_APPLICATION_SECRET_KEY)
|
||||||
group_id = OK_GROUP_ID
|
|
||||||
upload = Upload(ok)
|
upload = Upload(ok)
|
||||||
upload_response = upload.photo(photos=['temp.png'], album=group_id)
|
upload_response = upload.photo(photos=['temp.png'], album=OK_GROUP_ID)
|
||||||
for photo_id in upload_response['photos']:
|
for photo_id in upload_response['photos']:
|
||||||
token = upload_response['photos'][photo_id]['token']
|
token = upload_response['photos'][photo_id]['token']
|
||||||
response = ok.photosV2.commit(photo_id=photo_id, token=token, comment=data['prompt'])
|
ok.photosV2.commit(photo_id=photo_id, token=token, comment=unique_prompt)
|
||||||
print(response.text)
|
|
||||||
|
|
||||||
# clear garbage
|
|
||||||
os.remove('temp.png')
|
|
||||||
await callback.message.edit_text(
|
|
||||||
'Фотка в VK и OK загружена'
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await bot.send_message(
|
await bot.send_message(
|
||||||
chat_id=callback.message.chat.id,
|
chat_id=callback.message.chat.id,
|
||||||
text=e,
|
text='OK ERROR = '+str(e),
|
||||||
|
parse_mode=types.ParseMode.HTML
|
||||||
|
)
|
||||||
|
# clear garbage
|
||||||
|
os.remove('temp.png')
|
||||||
|
# alert
|
||||||
|
await bot.answer_callback_query(callback.id, text='Фотка '+num_but+' в VK и OK загружена', show_alert=True)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
await bot.send_message(
|
||||||
|
chat_id=callback.message.chat.id,
|
||||||
|
text='send_vk '+str(e),
|
||||||
parse_mode=types.ParseMode.HTML
|
parse_mode=types.ParseMode.HTML
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1023,6 +1159,11 @@ async def inl_rnd_inf(message: Union[types.Message, types.CallbackQuery]) -> Non
|
|||||||
chat_id=chatId,
|
chat_id=chatId,
|
||||||
text='use_prompt включен, будет использоваться промпт ' + data['prompt']
|
text='use_prompt включен, будет использоваться промпт ' + data['prompt']
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
await bot.send_message(
|
||||||
|
chat_id=chatId,
|
||||||
|
text=data['prompt']
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
# PROMPT
|
# PROMPT
|
||||||
if str(dataParams['use_prompt']).lower() == 'false':
|
if str(dataParams['use_prompt']).lower() == 'false':
|
||||||
|
Loading…
Reference in New Issue
Block a user