feat: add Commands enum, delete useless commands, revamp the Settings class and the MarkovChain.message_handler method

This commit is contained in:
cătălin 2024-11-01 04:40:17 +01:00
commit 3a33411dd9
No known key found for this signature in database
18 changed files with 1111 additions and 1190 deletions

View file

@ -43,41 +43,51 @@ class ConfigWindow(BoxLayout):
try:
if config_path.exists():
with open(config_path) as f:
with config_path.open("r") as f:
saved_config = json.load(f)
# Update self.default_config with saved values
self.default_config.update(saved_config)
except json.JSONDecodeError:
logging.error(f"Failed to parse config file at {config_path}")
except Exception as e:
logging.error(f"Error loading config file: {e}")
logging.exception(f"Failed to parse config file at {config_path}")
except Exception:
logging.exception("Error loading config file")
# Create widgets
# Channel input
channel_layout = BoxLayout(
orientation="horizontal", size_hint_y=None, height=dp(40)
orientation="horizontal",
size_hint_y=None,
height=dp(40),
)
channel_label = Label(text="Channel:", size_hint_x=0.3)
self.channel_input = TextInput(
multiline=False, size_hint_x=0.7, text=self.default_config["Channel"]
multiline=False,
size_hint_x=0.7,
text=self.default_config["Channel"],
)
channel_layout.add_widget(channel_label)
channel_layout.add_widget(self.channel_input)
# Nickname input
nickname_layout = BoxLayout(
orientation="horizontal", size_hint_y=None, height=dp(40)
orientation="horizontal",
size_hint_y=None,
height=dp(40),
)
nickname_label = Label(text="Nickname:", size_hint_x=0.3)
self.nickname_input = TextInput(
multiline=False, size_hint_x=0.7, text=self.default_config["Nickname"]
multiline=False,
size_hint_x=0.7,
text=self.default_config["Nickname"],
)
nickname_layout.add_widget(nickname_label)
nickname_layout.add_widget(self.nickname_input)
# Authentication input
auth_layout = BoxLayout(
orientation="horizontal", size_hint_y=None, height=dp(40)
orientation="horizontal",
size_hint_y=None,
height=dp(40),
)
auth_label = Label(text="Auth:", size_hint_x=0.3)
self.auth_input = TextInput(
@ -129,11 +139,11 @@ class ConfigWindow(BoxLayout):
Clock.schedule_once(success_popup.dismiss, 1)
except Exception as e:
except Exception as e: # noqa: BLE001
# Show error message if saving fails
error_popup = Popup(
title="Error",
content=Label(text=f"Failed to save configuration:\n{str(e)}"),
content=Label(text=f"Failed to save configuration:\n{e!s}"),
size_hint=(None, None),
size=(dp(400), dp(150)),
)