Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,59 @@ async def add_server_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -


async def get_alias(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
context.user_data['alias'] = update.message.text
await update.message.reply_text("Great. Now, what is the hostname or IP address?")
await update.message.reply_text(
translate('prompt_hostname', language),
)
return HOSTNAME

async def get_hostname(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
context.user_data['hostname'] = update.message.text
await update.message.reply_text("And the SSH username?")
await update.message.reply_text(
translate('prompt_username', language),
)
return USER

async def get_user(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
context.user_data['user'] = update.message.text
keyboard = [[InlineKeyboardButton("🔑 Key", callback_data='key'), InlineKeyboardButton("🔒 Password", callback_data='password')]]
keyboard = [[
InlineKeyboardButton(
translate('button_auth_key', language),
callback_data='key'
),
InlineKeyboardButton(
translate('button_auth_password', language),
callback_data='password'
)
]]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text("How would you like to authenticate?", reply_markup=reply_markup)
await update.message.reply_text(
translate('prompt_auth_method', language),
reply_markup=reply_markup,
)
return AUTH_METHOD

async def get_auth_method(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
query = update.callback_query
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
await query.answer()

if query.data == 'password':
await query.message.reply_text("Please enter the SSH password.")
await query.message.reply_text(
translate('prompt_enter_password', language),
)
return PASSWORD
else:
await query.message.reply_text("Please enter the full path to your SSH private key on the server running this bot.")
await query.message.reply_text(
translate('prompt_enter_key_path', language),
)
return KEY_PATH

async def get_password(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
Expand All @@ -245,6 +273,8 @@ async def get_key_path(update: Update, context: ContextTypes.DEFAULT_TYPE) -> in

async def save_server(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Saves the server to the database."""
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
try:
owner_id = update.effective_user.id
add_server(
Expand All @@ -257,13 +287,20 @@ async def save_server(update: Update, context: ContextTypes.DEFAULT_TYPE):
)
await update.message.reply_text(f"✅ **Server '{context.user_data['alias']}' added successfully!**", parse_mode='Markdown')
except Exception as e:
await update.message.reply_text(f"❌ **Error:** {e}")
await update.message.reply_text(
translate('server_add_error', language, error=str(e)),
parse_mode='Markdown'
)
finally:
context.user_data.clear()

async def cancel_add_server(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Cancels the add server conversation."""
await update.message.reply_text("Server addition cancelled.")
user_id = _extract_user_id(update)
language = _get_user_language(user_id)
await update.message.reply_text(
translate('server_add_cancelled', language),
)
context.user_data.clear()
return ConversationHandler.END

Expand Down