mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Add some extra comments
This commit is contained in:
parent
8a3097f63e
commit
4cb890de6b
2 changed files with 17 additions and 2 deletions
|
@ -8,6 +8,7 @@ export let connection: Connection;
|
||||||
export function connect() {
|
export function connect() {
|
||||||
if (!connectionPromise) {
|
if (!connectionPromise) {
|
||||||
connectionPromise = createConnection().then(newConnection => {
|
connectionPromise = createConnection().then(newConnection => {
|
||||||
|
// Verify the DB timezone is set to UTC
|
||||||
return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then(r => {
|
return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then(r => {
|
||||||
if (r[0].tz !== "00:00:00") {
|
if (r[0].tz !== "00:00:00") {
|
||||||
throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`);
|
throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`);
|
||||||
|
|
18
src/index.ts
18
src/index.ts
|
@ -12,6 +12,7 @@ import DiscordHTTPError from "eris/lib/errors/DiscordHTTPError"; // tslint:disab
|
||||||
|
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
|
// Error handling
|
||||||
let recentPluginErrors = 0;
|
let recentPluginErrors = 0;
|
||||||
const RECENT_PLUGIN_ERROR_EXIT_THRESHOLD = 5;
|
const RECENT_PLUGIN_ERROR_EXIT_THRESHOLD = 5;
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ setInterval(() => (recentPluginErrors = Math.max(0, recentPluginErrors - 1)), 25
|
||||||
setInterval(() => (recentDiscordErrors = Math.max(0, recentDiscordErrors - 1)), 2500);
|
setInterval(() => (recentDiscordErrors = Math.max(0, recentDiscordErrors - 1)), 2500);
|
||||||
|
|
||||||
function errorHandler(err) {
|
function errorHandler(err) {
|
||||||
|
// tslint:disable:no-console
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
if (err instanceof PluginError) {
|
if (err instanceof PluginError) {
|
||||||
|
@ -31,7 +33,7 @@ function errorHandler(err) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else if (err instanceof DiscordRESTError || err instanceof DiscordHTTPError) {
|
} else if (err instanceof DiscordRESTError || err instanceof DiscordHTTPError) {
|
||||||
// Discord API errors, usually safe to continue (rate limits etc. are handled elsewhere)
|
// Discord API errors, usually safe to just log instead of crash
|
||||||
// We still bail if we get a ton of them in a short amount of time
|
// We still bail if we get a ton of them in a short amount of time
|
||||||
if (++recentDiscordErrors >= RECENT_DISCORD_ERROR_EXIT_THRESHOLD) {
|
if (++recentDiscordErrors >= RECENT_DISCORD_ERROR_EXIT_THRESHOLD) {
|
||||||
console.error(`Exiting after ${RECENT_DISCORD_ERROR_EXIT_THRESHOLD} API errors`);
|
console.error(`Exiting after ${RECENT_DISCORD_ERROR_EXIT_THRESHOLD} API errors`);
|
||||||
|
@ -41,6 +43,7 @@ function errorHandler(err) {
|
||||||
// On other errors, crash immediately
|
// On other errors, crash immediately
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
// tslint:enable:no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on("unhandledRejection", errorHandler);
|
process.on("unhandledRejection", errorHandler);
|
||||||
|
@ -56,7 +59,8 @@ for (const [i, part] of actualVersionParts.entries()) {
|
||||||
throw new SimpleError(`Unsupported Node.js version! Must be at least ${REQUIRED_NODE_VERSION}`);
|
throw new SimpleError(`Unsupported Node.js version! Must be at least ${REQUIRED_NODE_VERSION}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always use UTC
|
// Always use UTC internally
|
||||||
|
// This is also enforced for the database in data/db.ts
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
moment.tz.setDefault("UTC");
|
moment.tz.setDefault("UTC");
|
||||||
|
|
||||||
|
@ -143,6 +147,12 @@ connect().then(async conn => {
|
||||||
globalPlugins: [BotControlPlugin, LogServerPlugin, UsernameSaver],
|
globalPlugins: [BotControlPlugin, LogServerPlugin, UsernameSaver],
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
|
/**
|
||||||
|
* Plugins are enabled if they...
|
||||||
|
* - are base plugins, i.e. always enabled, or
|
||||||
|
* - are dependencies of other enabled plugins, or
|
||||||
|
* - are explicitly enabled in the guild config
|
||||||
|
*/
|
||||||
getEnabledPlugins(guildId, guildConfig): string[] {
|
getEnabledPlugins(guildId, guildConfig): string[] {
|
||||||
const configuredPlugins = guildConfig.plugins || {};
|
const configuredPlugins = guildConfig.plugins || {};
|
||||||
const pluginNames: string[] = Array.from(this.plugins.keys());
|
const pluginNames: string[] = Array.from(this.plugins.keys());
|
||||||
|
@ -170,6 +180,10 @@ connect().then(async conn => {
|
||||||
return Array.from(finalEnabledPlugins.values());
|
return Array.from(finalEnabledPlugins.values());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the requested config file from the config dir
|
||||||
|
* TODO: Move to the database
|
||||||
|
*/
|
||||||
async getConfig(id) {
|
async getConfig(id) {
|
||||||
const configFile = id ? `${id}.yml` : "global.yml";
|
const configFile = id ? `${id}.yml` : "global.yml";
|
||||||
const configPath = path.join("config", configFile);
|
const configPath = path.join("config", configFile);
|
||||||
|
|
Loading…
Add table
Reference in a new issue