Compare commits
1 Commits
393bc4f8ca
...
8d4a7f9455
Author | SHA1 | Date | |
---|---|---|---|
|
8d4a7f9455 |
@ -13,9 +13,10 @@ import {
|
|||||||
TextChannel,
|
TextChannel,
|
||||||
User
|
User
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { logError, logInfo } from '../logging';
|
|
||||||
import {
|
import {
|
||||||
db,
|
db,
|
||||||
|
logInfo,
|
||||||
|
logError,
|
||||||
openDb,
|
openDb,
|
||||||
reactionEmojis,
|
reactionEmojis,
|
||||||
recordReaction,
|
recordReaction,
|
||||||
@ -85,7 +86,7 @@ async function scheduleRandomMessage(firstTime = false)
|
|||||||
const timeoutMins = Math.random() * 360 + 120;
|
const timeoutMins = Math.random() * 360 + 120;
|
||||||
const scheduledTime = new Date();
|
const scheduledTime = new Date();
|
||||||
scheduledTime.setMinutes(scheduledTime.getMinutes() + timeoutMins);
|
scheduledTime.setMinutes(scheduledTime.getMinutes() + timeoutMins);
|
||||||
logInfo(`[bot] Next MOTD: ${scheduledTime.toLocaleTimeString()}`);
|
logInfo(`[bot] Next MOTD: ${scheduledTime}`);
|
||||||
setTimeout(scheduleRandomMessage, timeoutMins * 60 * 1000);
|
setTimeout(scheduleRandomMessage, timeoutMins * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Client, Events, GatewayIntentBits, IntentsBitField, Partials } from 'discord.js';
|
import { Client, Events, GatewayIntentBits, IntentsBitField, Partials } from 'discord.js';
|
||||||
import { logInfo } from '../logging';
|
import { db, logInfo, openDb, reactionEmojis, sync } from './util';
|
||||||
import { db, openDb, reactionEmojis, sync } from './util';
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages],
|
intents: [GatewayIntentBits.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages],
|
||||||
|
@ -9,7 +9,6 @@ import { get as httpGet } from 'https';
|
|||||||
import { Database, open } from 'sqlite';
|
import { Database, open } from 'sqlite';
|
||||||
import { Database as Database3 } from 'sqlite3';
|
import { Database as Database3 } from 'sqlite3';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { logError, logInfo, logWarn } from '../logging';
|
|
||||||
import { ScoreboardMessageRow } from '../models';
|
import { ScoreboardMessageRow } from '../models';
|
||||||
|
|
||||||
|
|
||||||
@ -17,6 +16,22 @@ const reactionEmojis: string[] = process.env.REACTIONS.split(',');
|
|||||||
let db: Database = null;
|
let db: Database = null;
|
||||||
|
|
||||||
|
|
||||||
|
function curDateStr() {
|
||||||
|
return new Date().toJSON().replace('T', ' ').replace('Z', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function logInfo(...data) {
|
||||||
|
console.log(`[${curDateStr()}] ${data.join(' ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logWarn(...data) {
|
||||||
|
console.warn(`[${curDateStr()}] ${data.join(' ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logError(...data) {
|
||||||
|
console.error(`[${curDateStr()}] ${data.join(' ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
async function openDb() {
|
async function openDb() {
|
||||||
db = await open({
|
db = await open({
|
||||||
filename: 'db.sqlite',
|
filename: 'db.sqlite',
|
||||||
@ -163,4 +178,4 @@ async function sync(guilds: GuildManager) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { db, clearDb, openDb, reactionEmojis, recordReaction, sync };
|
export { db, clearDb, logError, logInfo, logWarn, openDb, reactionEmojis, recordReaction, sync };
|
||||||
|
22
logging.ts
22
logging.ts
@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* logging.ts
|
|
||||||
* Standardized logging helper functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
function curDateStr() {
|
|
||||||
return new Date().toJSON().replace('T', ' ').replace('Z', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function logInfo(...data) {
|
|
||||||
console.log(`[${curDateStr()}] ${data.join(' ')}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function logWarn(...data) {
|
|
||||||
console.warn(`[${curDateStr()}] ${data.join(' ')}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function logError(...data) {
|
|
||||||
console.error(`[${curDateStr()}] ${data.join(' ')}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { logInfo, logWarn, logError };
|
|
@ -7,8 +7,8 @@ import { Database as Database3 } from 'sqlite3';
|
|||||||
import { Database, open } from 'sqlite';
|
import { Database, open } from 'sqlite';
|
||||||
import express = require('express');
|
import express = require('express');
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { logInfo } from './logging';
|
|
||||||
import { ScoreboardMessageRow, ScoreboardUserRow } from './models';
|
import { ScoreboardMessageRow, ScoreboardUserRow } from './models';
|
||||||
|
import { logInfo } from './discord/util';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user