use db contexts for better stability
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-24 18:37:58 +02:00
parent e9d2582606
commit 0dfb5f3134
9 changed files with 54 additions and 140 deletions

View File

@@ -1,8 +1,9 @@
import datetime
import requests
import httpx
import socket
from telegram.ext import ConversationHandler, CommandHandler, CallbackQueryHandler, ParseMode
from telegram.ext import ConversationHandler, CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode
@@ -27,7 +28,7 @@ class StatusHandler(BaseHandler):
async def entry_point(self, update, context) -> None:
super().entry_point(update, context)
await super().entry_point(update, context)
keyboard = [
[
InlineKeyboardButton("And the log?", callback_data="full"),
@@ -36,10 +37,10 @@ class StatusHandler(BaseHandler):
reply_markup = InlineKeyboardMarkup(keyboard)
delta = str(datetime.datetime.now() - self.start_time)
message = "BeebBop, this is Norbit)\n"
message = "BeebBop, this is Norbit\n"
try:
ip = requests.get('https://api.ipify.org').text
ip = httpx.get('https://api.ipify.org').text
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(('8.8.8.8', 80))
(addr, port) = s.getsockname()
@@ -49,15 +50,14 @@ class StatusHandler(BaseHandler):
local_ips = "not fetchable"
message += "Status: Running 🟢\n"
message += "Uptime: `" + delta[:delta.rfind(".")] + "`\n"
message += "IP (public): `" + ip + "`\n"
message += "IP (private): `" + str(local_ips) + "`\n"
message += f"Uptime: `{delta[:delta.rfind('.')]}`\n"
message += f"IP \(public\): `{ip}`\n"
message += f"IP \(private\): `{local_ips}`\n"
if update.message:
await update.message.reply_text(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
await update.message.reply_text(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN_V2)
else:
await update._effective_chat.send_message(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
await update._effective_chat.send_message(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN_V2)
return FIRST
@@ -65,10 +65,7 @@ class StatusHandler(BaseHandler):
async def send_log(self, update, context) -> None:
query = update.callback_query
wanted = query.data.replace("status-","")
query.answer()
# with open("persistence/server.log") as l:
# query.message.reply_document(l)
await update.message.reply_text("Not implemented yet.")
super().log_activity(read = False, execute = False, send = True)
await query.answer()
await query.edit_message_text("Here you go: https://portainer.kluster.moll.re/#!/1/kubernetes/applications/journal/journal-botte")
return ConversationHandler.END