-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature : heroku add configvars @ /settings -> heroku config vars
- Loading branch information
himitsu
committed
Sep 24, 2020
1 parent
695e733
commit 4eacf58
Showing
5 changed files
with
153 additions
and
126 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import heroku3 | ||
from pyrogram import errors, InlineKeyboardButton, InlineKeyboardMarkup, Filters | ||
|
||
from nana import setbot, HEROKU_API | ||
from nana.assistant.input_handler import temp_vars | ||
from nana.assistant.repo_changer import dynamic_data_filter | ||
from nana.assistant.settings import get_text_settings, get_button_settings | ||
|
||
|
||
@setbot.on_callback_query(dynamic_data_filter("restart_heroku")) | ||
async def reboot_heroku(client, query): | ||
text = await get_text_settings() | ||
button = await get_button_settings() | ||
if HEROKU_API is not None: | ||
text += "\nPlease wait..." | ||
try: | ||
await query.message.edit_text(text, reply_markup=button) | ||
except errors.exceptions.bad_request_400.MessageNotModified: | ||
pass | ||
await client.answer_callback_query(query.id, "Please wait for Heroku App restarting...") | ||
heroku = heroku3.from_key(HEROKU_API) | ||
heroku_applications = heroku.apps() | ||
if len(heroku_applications) >= 1: | ||
heroku_app = heroku_applications[0] | ||
heroku_app.restart() | ||
else: | ||
text += "No heroku application found, but a key given? 😕" | ||
try: | ||
await query.message.edit_text(text, reply_markup=button) | ||
except errors.exceptions.bad_request_400.MessageNotModified: | ||
pass | ||
await client.answer_callback_query(query.id, "No heroku application found, but a key given?") | ||
|
||
|
||
@setbot.on_callback_query(dynamic_data_filter("heroku_vars")) | ||
async def vars_heroku(_client, query): | ||
text = "**⚙️ Welcome to Heroku Vars Settings!**\n" \ | ||
"`Setting your heroku config vars here!`\n" | ||
list_button = [[InlineKeyboardButton("⬅ back️", callback_data="back"), | ||
InlineKeyboardButton("➕ add️", callback_data="add_vars")]] | ||
if HEROKU_API: | ||
heroku = heroku3.from_key(HEROKU_API) | ||
heroku_applications = heroku.apps() | ||
if len(heroku_applications) >= 1: | ||
app = heroku_applications[0] | ||
config = app.config() | ||
# if config["api_id"]: | ||
# list_button.insert(0, [InlineKeyboardButton("api_id✅", callback_data="api_id")]) | ||
# else: | ||
# list_button.insert(0, [InlineKeyboardButton("api_id🚫", callback_data="api_id")]) | ||
configdict = config.to_dict() | ||
for x, _ in configdict.items(): | ||
list_button.insert(0, [InlineKeyboardButton("{}✅".format(x), callback_data="tes")]) | ||
button = InlineKeyboardMarkup(list_button) | ||
await query.message.edit_text(text, reply_markup=button) | ||
|
||
|
||
@setbot.on_callback_query(Filters.regex("^add_vars")) | ||
async def addvars(client, query): | ||
temp_vars.append(True) | ||
await query.message.edit_text("Send Name Variable :") | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import heroku3 | ||
from pyrogram import Filters, InlineKeyboardButton, InlineKeyboardMarkup | ||
|
||
from nana import AdminSettings, setbot, Owner, HEROKU_API | ||
from nana.assistant.database.custom_theme_db import add_custom_theme | ||
|
||
temp_input = False | ||
theme_format = [] | ||
temp_query = {} | ||
temp_vars = [] | ||
|
||
|
||
@setbot.on_message(Filters.user(AdminSettings)) | ||
async def theme_input_handlers(client, message): | ||
global temp_input, theme_format, temp_query, temp_vars | ||
if temp_input: | ||
text = "**⚙️Add Theme **\n" | ||
if len(theme_format) >= 1: | ||
try: | ||
cap = "Image has been set!" | ||
await setbot.send_photo(Owner, message.text, caption=cap) | ||
theme_format.append(message.text) | ||
except: | ||
text += "**Wrong URL image !** \n" | ||
else: | ||
theme_format.append(message.text) | ||
|
||
if len(theme_format) == 1: | ||
text += f"Set URL image for welcome image \n" | ||
elif len(theme_format) == 2: | ||
text += f"Set URL image for start image \n" | ||
elif len(theme_format) == 3: | ||
text += f"Set URL image for settings image \n" | ||
elif len(theme_format) == 4: | ||
text += f"Set URL image for stats image \n" | ||
elif len(theme_format) == 5: | ||
text += f"Custom Theme has successfully added \n" | ||
temp_input = False | ||
await add_custom_theme(theme_format[0], theme_format[1], theme_format[2], theme_format[3], theme_format[4]) | ||
theme_format = [] | ||
list_button = [[InlineKeyboardButton("❌ Cancel", callback_data="cancel")]] | ||
button = InlineKeyboardMarkup(list_button) | ||
await client.send_message(Owner, text, reply_markup=button) | ||
elif len(temp_vars) >= 1: | ||
temp_vars.append(message.text) | ||
text = "**⚙️Add heroku config vars **\n" | ||
if len(temp_vars) == 2: | ||
text += "`Send Value `" | ||
list_button = [[InlineKeyboardButton("❌ Cancel", callback_data="cancel")]] | ||
button = InlineKeyboardMarkup(list_button) | ||
await client.send_message(Owner, text, reply_markup=button) | ||
if len(temp_vars) == 3: | ||
await config_vars(temp_vars[1], temp_vars[2]) | ||
text += "`Successfully added config vars! `" | ||
await client.send_message(Owner, text) | ||
temp_vars = [] | ||
|
||
|
||
@setbot.on_callback_query(Filters.regex("^cancel")) | ||
async def cancel_input(client, query): | ||
global temp_input, theme_format, temp_vars | ||
temp_input = False | ||
theme_format = [] | ||
temp_vars = [] | ||
await client.answer_callback_query(query.id, "Operation Canceled!") | ||
await query.message.delete() | ||
|
||
|
||
async def config_vars(name, value): | ||
if HEROKU_API: | ||
heroku = heroku3.from_key(HEROKU_API) | ||
heroku_applications = heroku.apps() | ||
if len(heroku_applications) >= 1: | ||
app = heroku_applications[0] | ||
config = app.config() | ||
config[name] = value |
This file contains 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
This file contains 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