Skip to content

Commit

Permalink
Remove messy implied state in ControlPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
yiays committed Sep 2, 2024
1 parent 1baf0f6 commit 68dd130
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def save(self):
os.remove(oldfile)

self.last_backup = time.time()
#TODO: autodelete all but one of each config history
with open(self.file, 'w', encoding='utf-8') as f:
ConfigParser.write(self, f)

Expand Down
25 changes: 9 additions & 16 deletions extensions/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ def __init__(self, parent:ControlPanel.ControlPanelView, setting:Stringable):
self.parent = parent

super().__init__(
title=setting.label(parent.msg),
title=setting.label(parent.origin),
custom_id=setting.id,
components=[disnake.ui.TextInput(
label=setting.label(parent.msg),
label=setting.label(parent.origin),
custom_id='value',
placeholder=self.parent.parent.bot.utilities.truncate(setting.get(''), 100),
value=setting.get(''),
Expand All @@ -218,14 +218,13 @@ async def callback(self, inter:disnake.ModalInteraction):
# Views

class ControlPanelView(disnake.ui.View):
msg:disnake.Message | None = None

def __init__(
self, inter:disnake.CommandInteraction, parent:ControlPanel, settings:list[Setting]
):
super().__init__(timeout=300)

self.parent = parent
self.origin = inter
self.settings:dict[str, Setting] = {}
sections:list[str] = []
rowcap:dict[int, int] = {}
Expand Down Expand Up @@ -328,16 +327,10 @@ async def callback_all(self, inter:disnake.MessageInteraction | disnake.ModalInt
await inter.response.edit_message(view=self)

async def on_timeout(self):
if self.msg:
try:
await self.msg.delete()
except disnake.HTTPException:
pass
else:
for component in self.children:
if isinstance(component, (disnake.ui.Button, disnake.ui.Select)):
component.disabled = True
await self.msg.edit(view=self)
try:
await self.origin.delete_original_response()
except disnake.HTTPException:
pass # Message was probably dismissed, don't worry about it

# Commands

Expand All @@ -353,8 +346,8 @@ async def controlpanel(self, inter:disnake.CommandInteraction):
view=panel,
ephemeral=True
)
panel.msg = await inter.original_response()
self.panels[panel.msg.id] = panel
msg = await inter.original_response()
self.panels[msg.id] = panel


def setup(bot:MerelyBot):
Expand Down

0 comments on commit 68dd130

Please sign in to comment.