diff --git a/src/handlers/servers/info.py b/src/handlers/servers/info.py index 7809fb9..061202e 100644 --- a/src/handlers/servers/info.py +++ b/src/handlers/servers/info.py @@ -39,36 +39,40 @@ async def servers_info(callback_query: CallbackQuery, callback_data: BotCB, hetz price_hourly = f"{hourly:.4f}€" price_monthly = f"{monthly:.2f}€" - update = await callback_query.message.edit( - text=Dialogs.SERVERS_INFO.format( - name=server.name, - status=server.status, - ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖", - ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖", - ram=server.server_type.memory, - cpu=server.server_type.cores, - created=server.created.strftime("%Y-%m-%d"), - country=server.datacenter.location.country, - city=server.datacenter.location.city, - image=server.image.name or server.image.description, - created_day=(datetime.now(tz=timezone.utc) - server.created).days, - disk=server.server_type.disk, - snapshot=len( - [ - snapshot - for snapshot in hetzner.images.get_all(type="snapshot") - if snapshot.created_from and snapshot.created_from.id == server.id - ] - ), - traffic_in=ingoing_gb, - traffic_out=outgoing_gb, - traffic_total=total_gb, - traffic_included=included_gb, - traffic_used_percent=(used_percent if used_percent is not None else "➖"), - traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0, - price_hourly=price_hourly, - price_monthly=price_monthly, + text = Dialogs.SERVERS_INFO.format( + name=server.name, + status=server.status, + ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖", + ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖", + ram=server.server_type.memory, + cpu=server.server_type.cores, + created=server.created.strftime("%Y-%m-%d"), + country=server.datacenter.location.country, + city=server.datacenter.location.city, + image=server.image.name or server.image.description, + created_day=(datetime.now(tz=timezone.utc) - server.created).days, + disk=server.server_type.disk, + snapshot=len( + [ + snapshot + for snapshot in hetzner.images.get_all(type="snapshot") + if snapshot.created_from and snapshot.created_from.id == server.id + ] ), - reply_markup=BotKB.servers_update(server=server), + traffic_in=ingoing_gb, + traffic_out=outgoing_gb, + traffic_total=total_gb, + traffic_included=included_gb, + traffic_used_percent=(used_percent if used_percent is not None else "➖"), + traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0, + price_hourly=price_hourly, + price_monthly=price_monthly, ) + reply_markup = BotKB.servers_update(server=server) + + try: + update = await callback_query.message.edit(text=text, reply_markup=reply_markup) + except Exception: + await callback_query.answer() + return return await UserMessage.clear(update, keep_current=True) diff --git a/src/keys/manager.py b/src/keys/manager.py index c1605f9..8f8e8e9 100644 --- a/src/keys/manager.py +++ b/src/keys/manager.py @@ -191,6 +191,13 @@ def servers_update(cls, server: Server) -> InlineKeyboardMarkup: ).pack(), ) kb.adjust(1, 1, 2, 1, 2, 1, 2, 1, 2, 2) + kb.row( + InlineKeyboardButton( + text=Buttons.SERVERS_REFRESH, + callback_data=BotCB(area=AreaType.SERVER, task=TaskType.INFO, target=server.id).pack(), + ), + size=1, + ) cls._back(kb=kb, area=AreaType.SERVER) return kb.as_markup() diff --git a/src/lang/_button.py b/src/lang/_button.py index d273479..82ae93f 100644 --- a/src/lang/_button.py +++ b/src/lang/_button.py @@ -33,6 +33,7 @@ class Buttons(StrEnum): SERVERS_UNASSIGN_IPV4 = "❌ Unassign IPv4" SERVERS_UNASSIGN_IPV6 = "❌ Unassign IPv6" SERVERS_UPGRADE = "⬆️ Upgrade" + SERVERS_REFRESH = "🔄 Refresh" ### Snapshots SNAPSHOTS = "📸 Snapshots"