-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathviews.py
124 lines (101 loc) · 3.85 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from __future__ import annotations
import typing as t
from discord import ui
import discord
if t.TYPE_CHECKING:
from core import Discloud
from utils import App
class SelectApp(ui.Select):
def __init__(self, apps: t.Iterable[App], bot: Discloud) -> None:
self.client = bot.discloud_client
self.manager = bot.app_manager
self.bot = bot
options = [discord.SelectOption(label=app.fullname, value=app.id) for app in apps]
super().__init__(
placeholder="Aperte Aqui!",
options=options
)
async def callback(self, interaction: discord.Interaction) -> None:
selected = self.values[0]
app = await self.manager.get_app(selected)
await interaction.response.send_message(embed=app.to_embed(), view=app.dashboard(), ephemeral=True)
class Restart(ui.Button):
def __init__(self, app: App):
self.app = app
super().__init__(
label="Restart",
emoji="\U0001f501",
style=discord.ButtonStyle.red,
)
async def callback(self, interaction: discord.Interaction) -> None:
await interaction.response.send_message("O Aplicativo será reiniciado em breve", ephemeral=True)
await self.app.restart()
class Start(ui.Button):
def __init__(self, app: App) -> None:
self.app = app
super().__init__(
label="Start",
emoji="\U000025b6",
style=discord.ButtonStyle.green,
)
async def callback(self, interaction: discord.Interaction) -> None:
action = await self.app.start()
await interaction.response.send_message(action.message, ephemeral=True)
class Stop(ui.Button):
def __init__(self, app: App) -> None:
self.app = app
super().__init__(
label="Stop",
emoji="\U000023f9",
style=discord.ButtonStyle.red,
)
async def callback(self, interaction: discord.Interaction) -> None:
await interaction.response.send_message("O Aplicativo será desligado em breve", ephemeral=True)
await self.app.stop()
class Backup(ui.Button):
def __init__(self, app: App) -> None:
self.app = app
super().__init__(
label="Backup",
emoji="\U0001f4be",
style=discord.ButtonStyle.blurple
)
async def callback(self, interaction: discord.Interaction) -> None:
from utils import DISCLOUD_COLOR
bckp = await self.app.backup()
embed = discord.Embed(
description=f"Aperte [aqui]({bckp.url}) para baixar os arquivos de {self.app.fullname}",
color=DISCLOUD_COLOR
)
embed.set_author(name=self.app.fullname, icon_url=self.app.avatar)
await interaction.response.send_message(embed=embed, ephemeral=True)
class Terminal(ui.Button):
def __init__(self, app: App) -> None:
self.app = app
super().__init__(
label="Terminal",
emoji="\U0001f5a8",
style=discord.ButtonStyle.blurple
)
async def callback(self, interaction: discord.Interaction) -> None:
from utils import DISCLOUD_COLOR
await interaction.response.defer(ephemeral=True)
terminal = await self.app.terminal()
e = discord.Embed(
description=f"```{terminal.small}```",
color=DISCLOUD_COLOR
)
await interaction.followup.send(embed=e, ephemeral=True)
class Dashboard(ui.View):
def __init__(self, app: App):
super().__init__(timeout=180)
self.app = app
if self.app.is_online:
self.add_item(Stop(app))
self.add_item(Restart(app))
self.add_item(Backup(app))
self.add_item(Terminal(app))
else:
self.add_item(Start(app))
self.add_item(Backup(app))
self.add_item(Terminal(app))