server registration and subscription
This commit is contained in:
60
index.js
60
index.js
@@ -1,9 +1,57 @@
|
||||
// index.js
|
||||
require('dotenv').config();
|
||||
const winston = require('winston');
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const Bot = require('./src/Bot');
|
||||
require('dotenv').config();
|
||||
|
||||
const bot = new Bot();
|
||||
bot.start(process.env.BOT_TOKEN).catch(error => {
|
||||
console.error('Failed to start bot:', error);
|
||||
process.exit(1);
|
||||
// Initialize logger
|
||||
const logger = winston.createLogger({
|
||||
level: 'debug',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple()
|
||||
)
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
// Initialize Supabase client
|
||||
const supabase = createClient(
|
||||
process.env.SUPABASE_URL,
|
||||
process.env.SUPABASE_KEY
|
||||
);
|
||||
|
||||
// Initialize and start bot
|
||||
const bot = new Bot(process.env.DISCORD_TOKEN, supabase, logger);
|
||||
bot.start().catch(error => {
|
||||
console.error('Failed to start bot:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Handle process termination
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Received SIGINT. Shutting down...');
|
||||
try {
|
||||
await bot.stop();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('Error during shutdown:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('Received SIGTERM. Shutting down...');
|
||||
try {
|
||||
await bot.stop();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('Error during shutdown:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user