Skip to content

Commit 19aaab3

Browse files
committed
feat: initialize database and bot in main entry point
- Set up `DatabaseService` to initialize the database connection and seed tables. - Added logging for database initialization. - Instantiate and initialize the `CopBot` in the main entry point (`app.ts`). - Added logging for bot initialization.
1 parent 4d57eca commit 19aaab3

1 file changed

Lines changed: 11 additions & 31 deletions

File tree

src/app.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
import { Bot } from "grammy";
2-
import { GenerateCommand } from "./service/command/generator";
3-
import { MessageCheck } from "./service/MessageCheck";
4-
import { Spam } from "./service/bot/spam";
5-
import { logger } from "./config/logger";
6-
import { db } from "./service/db";
7-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
8-
new GenerateCommand(bot).generate();
9-
bot.on("message", async (ctx) => {
10-
if (!ctx.chat) {
11-
return;
12-
}
13-
await MessageCheck.Message(ctx);
14-
await MessageCheck.isCode(ctx);
15-
await MessageCheck.CheckBlackList(ctx);
16-
await Spam.WarnSpam(ctx);
17-
await MessageCheck.isNewUser(ctx);
18-
await MessageCheck.leftGroup(ctx);
19-
});
20-
bot.on("my_chat_member", MessageCheck.initialGroup);
21-
(async () => {
22-
try {
23-
await db.initialize();
24-
bot.start();
25-
logger.info("BOT STARTED", "APP");
26-
} catch (error: any) {
27-
logger.error("ERROR FROM START APP", error.message, "APP");
28-
await db.close();
29-
process.exit(1);
30-
}
31-
})();
1+
import { CopBot } from './bot';
2+
import { DatabaseService } from './database';
3+
import logger from './utils/logger';
4+
async function main() {
5+
const cop = new CopBot();
6+
await new DatabaseService().initialize();
7+
logger.info('initialize Database');
8+
await cop.initial();
9+
logger.info('initial bot');
10+
}
11+
main();

0 commit comments

Comments
 (0)