Skip to content

Commit 69cd550

Browse files
authored
improve[servers]: add refresh button (#24)
1 parent 14e4083 commit 69cd550

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

src/handlers/servers/info.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,40 @@ async def servers_info(callback_query: CallbackQuery, callback_data: BotCB, hetz
3939
price_hourly = f"{hourly:.4f}€"
4040
price_monthly = f"{monthly:.2f}€"
4141

42-
update = await callback_query.message.edit(
43-
text=Dialogs.SERVERS_INFO.format(
44-
name=server.name,
45-
status=server.status,
46-
ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖",
47-
ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖",
48-
ram=server.server_type.memory,
49-
cpu=server.server_type.cores,
50-
created=server.created.strftime("%Y-%m-%d"),
51-
country=server.datacenter.location.country,
52-
city=server.datacenter.location.city,
53-
image=server.image.name or server.image.description,
54-
created_day=(datetime.now(tz=timezone.utc) - server.created).days,
55-
disk=server.server_type.disk,
56-
snapshot=len(
57-
[
58-
snapshot
59-
for snapshot in hetzner.images.get_all(type="snapshot")
60-
if snapshot.created_from and snapshot.created_from.id == server.id
61-
]
62-
),
63-
traffic_in=ingoing_gb,
64-
traffic_out=outgoing_gb,
65-
traffic_total=total_gb,
66-
traffic_included=included_gb,
67-
traffic_used_percent=(used_percent if used_percent is not None else "➖"),
68-
traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0,
69-
price_hourly=price_hourly,
70-
price_monthly=price_monthly,
42+
text = Dialogs.SERVERS_INFO.format(
43+
name=server.name,
44+
status=server.status,
45+
ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖",
46+
ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖",
47+
ram=server.server_type.memory,
48+
cpu=server.server_type.cores,
49+
created=server.created.strftime("%Y-%m-%d"),
50+
country=server.datacenter.location.country,
51+
city=server.datacenter.location.city,
52+
image=server.image.name or server.image.description,
53+
created_day=(datetime.now(tz=timezone.utc) - server.created).days,
54+
disk=server.server_type.disk,
55+
snapshot=len(
56+
[
57+
snapshot
58+
for snapshot in hetzner.images.get_all(type="snapshot")
59+
if snapshot.created_from and snapshot.created_from.id == server.id
60+
]
7161
),
72-
reply_markup=BotKB.servers_update(server=server),
62+
traffic_in=ingoing_gb,
63+
traffic_out=outgoing_gb,
64+
traffic_total=total_gb,
65+
traffic_included=included_gb,
66+
traffic_used_percent=(used_percent if used_percent is not None else "➖"),
67+
traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0,
68+
price_hourly=price_hourly,
69+
price_monthly=price_monthly,
7370
)
71+
reply_markup = BotKB.servers_update(server=server)
72+
73+
try:
74+
update = await callback_query.message.edit(text=text, reply_markup=reply_markup)
75+
except Exception:
76+
await callback_query.answer()
77+
return
7478
return await UserMessage.clear(update, keep_current=True)

src/keys/manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ def servers_update(cls, server: Server) -> InlineKeyboardMarkup:
191191
).pack(),
192192
)
193193
kb.adjust(1, 1, 2, 1, 2, 1, 2, 1, 2, 2)
194+
kb.row(
195+
InlineKeyboardButton(
196+
text=Buttons.SERVERS_REFRESH,
197+
callback_data=BotCB(area=AreaType.SERVER, task=TaskType.INFO, target=server.id).pack(),
198+
),
199+
size=1,
200+
)
194201
cls._back(kb=kb, area=AreaType.SERVER)
195202
return kb.as_markup()
196203

src/lang/_button.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Buttons(StrEnum):
3333
SERVERS_UNASSIGN_IPV4 = "❌ Unassign IPv4"
3434
SERVERS_UNASSIGN_IPV6 = "❌ Unassign IPv6"
3535
SERVERS_UPGRADE = "⬆️ Upgrade"
36+
SERVERS_REFRESH = "🔄 Refresh"
3637

3738
### Snapshots
3839
SNAPSHOTS = "📸 Snapshots"

0 commit comments

Comments
 (0)