Skip to content

[✨] Replace literal usage of components #20

Description

@Maghish

As you can see in the code snippet below, it uses a lot of literal mentions of components and there could be possible risks of the component not even present and we need to error handle that. Hence we need to make it dynamic. By dynamic, some might not need dynamic mentions, as the code only uses the certain components, but to avoid risks of the absence of components, we can add if statements to check if the component exists, if not we can throw an error saying that some components are missing.

setControllers() {
this.app.post("/botlog", (req, res) => {
if (this.components.bot_log.content === "") {
this.components.bot_log.setContent(req.body.content);
} else {
this.components.bot_log.setContent(
this.components.bot_log.content + "\n" + req.body.content
);
}
this.screen.render();
res.status(200);
});
this.app.post("/boterror", (req, res) => {
if (this.components.bot_error.content === "") {
this.components.bot_error.setContent(req.body.content);
} else {
this.components.bot_error.setContent(
this.components.bot_error.content + "\n" + req.body.content
);
}
this.screen.render();
res.status(200);
});
this.app.post("/setcogs", (req, res) => {
if (this.components.bot_cogs.content === "Loading...") {
this.components.bot_cogs.setContent(req.body.content);
} else {
this.components.bot_cogs.setContent(
this.components.bot_cogs.content + "\n" + req.body.content
);
}
this.screen.render();
res.status(200);
});
this.app.post("/generallog", (req, res) => {
if (this.components.general_log.content === "") {
this.components.general_log.setContent(req.body.content);
} else {
this.components.general_log.setContent(
this.components.general_log.content + "\n" + req.body.content
);
}
this.screen.render();
res.status(200);
});
}
async _start() {
this.app.listen(this.port, () => {
console.log(`TUI listening on port ${this.port}`);
});
this.screen.render();
}
async appendGeneralLog(content: string) {
if (this.components.general_log.content === "") {
this.components.general_log.setContent(content);
} else {
this.components.general_log.setContent(
this.components.general_log.content + "\n" + content
);
}
this.screen.render();
}
async appendModule(module: string) {
if (this.components.modules.content === "Loading...") {
this.components.modules.setContent(`- ${module} ✅`);
} else {
this.components.modules.setContent(
this.components.modules.content + "\n" + `- ${module} ✅`
);
}
this.screen.render();
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions