Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
fix: Login to Discord (#38)
Browse files Browse the repository at this point in the history
* 👷 chore(cd): Add continuous deployment workflow

* ♻️ refactor: Remove deployment script

* 👷 fix: Add image tag to production image

* ♻️ feat: Pertain logger script on production

* 🚑 fix: Login to Discord
  • Loading branch information
Namchee committed Jul 31, 2021
1 parent ddbba30 commit b355e5d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
3 changes: 3 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ services:
- mongo
networks:
- backend
volumes:
- logs:/usr/bot/logs

volumes:
mongo-volume:
driver: local
logs:

networks:
backend:
2 changes: 1 addition & 1 deletion src/config/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Db, MongoClient } from 'mongodb';
import { MongoClient } from 'mongodb';
import config from './env';

const { env } = config;
Expand Down
81 changes: 44 additions & 37 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,48 @@ import { bootstrapBot } from './bot';
const { env } = config;

(async (): Promise<void> => {
await NSFWClassifier.initializeCache();

const connection = await getDBConnection();
const db = connection.db(env.MONGO_DBNAME);
const repository = new MongoRepository(db);

const discordClient = bootstrapBot(repository);
Logger.bootstrap();

schedule('0 0 1 * *', async () => {
await cleanDb(repository);
});

const closeConnections = async (): Promise<void> => {
await connection.close();
discordClient.destroy();
};

process.on('uncaughtException', async (err) => {
Logger.getInstance().logBot(`Uncaught Exception: ${err}`, LogLevel.ERROR);
await closeConnections();
process.exit(1);
});

process.on('unhandledRejection', async (reason) => {
Logger.getInstance().logBot(
`Unhandled promise rejection: ${reason}`,
LogLevel.ERROR,
);
await closeConnections();
process.exit(1);
});

process.on('SIGTERM', async () => {
await closeConnections();
process.exit(0);
});
try {
await NSFWClassifier.initializeCache();

const connection = await getDBConnection();
const db = connection.db(env.MONGO_DBNAME);
const repository = new MongoRepository(db);

const discordClient = bootstrapBot(repository);

Logger.bootstrap();

schedule('0 0 1 * *', async () => {
await cleanDb(repository);
});

discordClient.login(env.DISCORD_TOKEN);

const closeConnections = async (): Promise<void> => {
await connection.close();
discordClient.destroy();
};

process.on('uncaughtException', async (err) => {
Logger.getInstance().logBot(`Uncaught Exception: ${err}`, LogLevel.ERROR);
await closeConnections();
process.exit(1);
});

process.on('unhandledRejection', async (reason) => {
Logger.getInstance().logBot(
`Unhandled promise rejection: ${reason}`,
LogLevel.ERROR,
);
await closeConnections();
process.exit(1);
});

process.on('SIGTERM', async () => {
await closeConnections();
process.exit(0);
});
} catch (err) {
console.error(err);
}
})();

0 comments on commit b355e5d

Please sign in to comment.