lists working
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-21 22:05:27 +02:00
parent b5551eb596
commit e9d2582606
7 changed files with 216 additions and 36 deletions

74
bot/commands/status.py Normal file
View File

@@ -0,0 +1,74 @@
import datetime
import requests
import socket
from telegram.ext import ConversationHandler, CommandHandler, CallbackQueryHandler, ParseMode
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
FIRST = 1
from .basehandler import BaseHandler
class StatusHandler(BaseHandler):
"""Shows a short status of the program."""
def __init__(self, entry_string, models):
self.start_time = datetime.datetime.now()
self.entry_string = entry_string
self.models = models
self.handler = ConversationHandler(
entry_points=[CommandHandler(self.entry_string, self.entry_point)],
states={
FIRST: [
CallbackQueryHandler(self.send_log, pattern="^full$"),
]
},
fallbacks=[CommandHandler('status', self.entry_point)],
)
async def entry_point(self, update, context) -> None:
super().entry_point(update, context)
keyboard = [
[
InlineKeyboardButton("And the log?", callback_data="full"),
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
delta = str(datetime.datetime.now() - self.start_time)
message = "BeebBop, this is Norbit)\n"
try:
ip = requests.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()
local_ips = addr
except:
ip = "not fetchable"
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"
if update.message:
await update.message.reply_text(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
else:
await update._effective_chat.send_message(message, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
return FIRST
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)
return ConversationHandler.END