Skip to content

Commit becff24

Browse files
authored
Merge pull request #32 from neilenns/neilenns/issue31
Send startup errors to Discord, then just stop
2 parents 2b5daa3 + fa370ec commit becff24

File tree

6 files changed

+88
-232
lines changed

6 files changed

+88
-232
lines changed

src/commands/general/ch340.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/commands/general/wiki.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,39 @@ const {
99
const { replyOrEditReply } = require("../../utilities");
1010
const chokidar = require("chokidar");
1111
const fs = require("fs");
12-
const debug = require("debug")("wikiCommand");
12+
13+
const mainLogger = require("../../logger");
14+
const logger = mainLogger.child({ service: "wiki" });
1315

1416
let selectMenu;
1517
let menuItems;
1618

1719
function loadMenuItems() {
18-
debug(`Loading menu items from ${process.env.WIKI_ITEMS_PATH}`);
19-
menuItems = JSON.parse(fs.readFileSync(process.env.WIKI_ITEMS_PATH, "utf8"));
20-
21-
// Build the menu
22-
selectMenu = new StringSelectMenuBuilder()
23-
.setCustomId("wiki-selector")
24-
.setPlaceholder("Select a wiki topic");
25-
26-
menuItems.forEach((item) => {
27-
selectMenu.addOptions(
28-
new StringSelectMenuOptionBuilder()
29-
.setLabel(item.label)
30-
.setDescription(item.description)
31-
.setValue(item.value)
20+
logger.debug(`Loading menu items from ${process.env.WIKI_ITEMS_PATH}`);
21+
try {
22+
menuItems = JSON.parse(
23+
fs.readFileSync(process.env.WIKI_ITEMS_PATH, "utf8")
3224
);
33-
});
25+
26+
// Build the menu
27+
selectMenu = new StringSelectMenuBuilder()
28+
.setCustomId("wiki-selector")
29+
.setPlaceholder("Select a wiki topic");
30+
31+
menuItems.forEach((item) => {
32+
selectMenu.addOptions(
33+
new StringSelectMenuOptionBuilder()
34+
.setLabel(item.label)
35+
.setDescription(item.description)
36+
.setValue(item.value)
37+
);
38+
});
39+
} catch (err) {
40+
logger.error(
41+
`Failed to load wiki menu items from ${process.env.WIKI_ITEMS_PATH}: ${err.message}`,
42+
err
43+
);
44+
}
3445
}
3546

3647
function watchForMenuChanges() {
@@ -41,9 +52,9 @@ function watchForMenuChanges() {
4152
awaitWriteFinish: true,
4253
})
4354
.on("change", loadMenuItems);
44-
debug(`Watching for changes in ${process.env.WIKI_ITEMS_PATH}`);
55+
logger.debug(`Watching for changes in ${process.env.WIKI_ITEMS_PATH}`);
4556
} catch (e) {
46-
debug(
57+
logger.error(
4758
`Unable to watch for changes to ${process.env.WIKI_ITEMS_PATH}: ${e}`
4859
);
4960
}
@@ -123,7 +134,7 @@ module.exports = {
123134
content: `${preamble} ${link}`,
124135
});
125136
} catch (error) {
126-
debug(`Unable to send wiki link: ${error}`);
137+
logger.error(`Unable to send wiki link: ${error}`);
127138
await replyOrEditReply(interaction, {
128139
content: `Unable to send wiki link: ${error}`,
129140
components: [],

src/commands/general/yt.js

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/index.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,61 @@ client.commands = new Collection();
1616
client.cooldowns = new Collection();
1717

1818
function loadEvents() {
19-
const eventsPath = path.join(__dirname, "events");
20-
const eventFiles = fs
21-
.readdirSync(eventsPath)
22-
.filter((file) => file.endsWith(".js"));
19+
try {
20+
const eventsPath = path.join(__dirname, "events");
21+
const eventFiles = fs
22+
.readdirSync(eventsPath)
23+
.filter((file) => file.endsWith(".js"));
2324

24-
for (const file of eventFiles) {
25-
const filePath = path.join(eventsPath, file);
26-
logger.debug(`Loading event: ${filePath}`, { file: filePath });
27-
const event = require(filePath);
28-
if (event.once) {
29-
client.once(event.name, (...args) => event.execute(...args));
30-
} else {
31-
client.on(event.name, (...args) => event.execute(...args));
25+
for (const file of eventFiles) {
26+
const filePath = path.join(eventsPath, file);
27+
logger.debug(`Loading event: ${filePath}`, { file: filePath });
28+
const event = require(filePath);
29+
if (event.once) {
30+
client.once(event.name, (...args) => event.execute(...args));
31+
} else {
32+
client.on(event.name, (...args) => event.execute(...args));
33+
}
3234
}
35+
} catch (err) {
36+
logger.error(`Failed to load events: ${err.message}`, err);
3337
}
3438
}
3539

3640
function loadCommands() {
37-
const foldersPath = path.join(__dirname, "commands");
38-
const commandFolders = fs.readdirSync(foldersPath);
41+
try {
42+
const foldersPath = path.join(__dirname, "commands");
43+
const commandFolders = fs.readdirSync(foldersPath);
3944

40-
for (const folder of commandFolders) {
41-
const commandsPath = path.join(foldersPath, folder);
42-
const commandFiles = fs
43-
.readdirSync(commandsPath)
44-
.filter((file) => file.endsWith(".js"));
45-
for (const file of commandFiles) {
46-
const filePath = path.join(commandsPath, file);
47-
const command = require(filePath);
48-
logger.debug(`Loading command: ${filePath}`, { file: filePath });
45+
for (const folder of commandFolders) {
46+
const commandsPath = path.join(foldersPath, folder);
47+
const commandFiles = fs
48+
.readdirSync(commandsPath)
49+
.filter((file) => file.endsWith(".js"));
50+
for (const file of commandFiles) {
51+
const filePath = path.join(commandsPath, file);
52+
const command = require(filePath);
53+
logger.debug(`Loading command: ${filePath}`, { file: filePath });
4954

50-
// Initialize the command if it has an initializer
51-
if ("init" in command) {
52-
logger.debug(`Initializing ${filePath}`, { file: filePath });
53-
command.init();
54-
}
55+
// Initialize the command if it has an initializer
56+
if ("init" in command) {
57+
logger.debug(`Initializing ${filePath}`, { file: filePath });
58+
command.init();
59+
}
5560

56-
// Set a new item in the Collection with the key as the command name and the value as the exported module
57-
if ("data" in command && "execute" in command) {
58-
client.commands.set(command.data.name, command);
59-
} else {
60-
logger.warn(
61-
`The command at ${filePath} is missing a required "data" or "execute" property.`,
62-
{ file: filePath }
63-
);
61+
// Set a new item in the Collection with the key as the command name and the value as the exported module
62+
if ("data" in command && "execute" in command) {
63+
client.commands.set(command.data.name, command);
64+
} else {
65+
logger.warn(
66+
`The command at ${filePath} is missing a required "data" or "execute" property.`,
67+
{ file: filePath }
68+
);
69+
}
6470
}
6571
}
72+
} catch (err) {
73+
logger.error(`Failed to load commands: ${err.message}`, err);
6674
}
6775
}
6876

wikiMenuItems.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,19 @@
4040
"value": "7segments",
4141
"href": "https://github.com/MobiFlight/MobiFlight-Connector/wiki/Tutorial-Setting-up-7-segment-LED-modules-with-SimConnect-Events",
4242
"preamble": "Check out this wiki page for information on using 7-segment LED modules with MobiFlight:"
43+
},
44+
{
45+
"label": "CH340",
46+
"description": "Arduino Nano and Mega with CH340 chips connection issues",
47+
"value": "ch340",
48+
"href": "https://www.badcasserole.com/arduino-nano-with-ch340-chips-connection-issues/",
49+
"preamble": "It sounds like your Arduino uses a counterfeit CH340 chip. You can find more information about this problem and how to fix it by visiting this blog post:"
50+
},
51+
{
52+
"label": "Getting started 2023",
53+
"description": "Getting Started 2023 - MobiFlight Tutorial",
54+
"value": "gettingstarted",
55+
"href": "https://www.youtube.com/watch?v=pS8KGfYRNrY",
56+
"preamble": "Check out this YouTube video for a good introduction on getting started with MobiFlight:"
4357
}
4458
]

ytMenuItems.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)