|
@@ -23,6 +23,7 @@ import "reflect-metadata";
|
|
|
import { createConnection, getConnectionOptions } from "typeorm";
|
|
|
import { getNumberEnums } from "./util";
|
|
|
import { DB_ENTITIES } from "@shared/db/entities";
|
|
|
+import { logger } from "./logging";
|
|
|
|
|
|
const REACT_PROBABILITY = 0.3;
|
|
|
|
|
@@ -48,7 +49,7 @@ const botEvents: BotEventCollection = getNumberEnums(mCmd.ActionType).reduce((p,
|
|
|
const startActions: Array<() => void | Promise<void>> = [];
|
|
|
|
|
|
client.bot.on("ready", async () => {
|
|
|
- console.log("Starting up NoctBot!");
|
|
|
+ logger.info("Starting up NoctBot");
|
|
|
client.botUser.setActivity(process.env.NODE_ENV == "dev" ? "Maintenance" : "@NoctBot help", {
|
|
|
type: "PLAYING"
|
|
|
});
|
|
@@ -58,7 +59,7 @@ client.bot.on("ready", async () => {
|
|
|
if (val instanceof Promise)
|
|
|
await val;
|
|
|
}
|
|
|
- console.log("NoctBot is ready!");
|
|
|
+ logger.info("NoctBot is ready");
|
|
|
});
|
|
|
|
|
|
client.bot.on("message", async m => {
|
|
@@ -77,8 +78,8 @@ client.bot.on("message", async m => {
|
|
|
return;
|
|
|
|
|
|
if (m.mentions.users.size > 0 && m.mentions.users.has(client.botUser.id)) {
|
|
|
-
|
|
|
- if (m.content.trim().startsWith(client.botUser.id) || m.content.trim().startsWith(client.botUser.discriminator)) {
|
|
|
+ const trimmedContent = m.content.trim();
|
|
|
+ if (trimmedContent.startsWith(client.nameMention) || trimmedContent.startsWith(client.usernameMention)) {
|
|
|
content = content.substring(`@${client.botUser.username}`.length).trim();
|
|
|
|
|
|
const lowerCaseContent = content.toLowerCase();
|
|
@@ -109,7 +110,7 @@ client.bot.on("message", async m => {
|
|
|
|
|
|
client.bot.on("messageReactionAdd", (r, u) => {
|
|
|
if (Math.random() <= REACT_PROBABILITY && !u.bot) {
|
|
|
- console.log(`Reacting to message ${r.message.id} because user ${u.tag} reacted to it`);
|
|
|
+ logger.verbose(`Reacting to message ${r.message.id} because user ${u.tag} reacted to it`);
|
|
|
r.message.react(r.emoji);
|
|
|
}
|
|
|
});
|
|
@@ -162,6 +163,8 @@ async function main() {
|
|
|
entities: DB_ENTITIES
|
|
|
});
|
|
|
|
|
|
+ logger.error("Failed! Oh noes!");
|
|
|
+
|
|
|
const commandsPath = path.resolve(path.dirname(module.filename), "commands");
|
|
|
const files = fs.readdirSync(commandsPath);
|
|
|
|