AnixartBot/index.js
2022-08-10 13:06:23 +02:00

41 lines
1.4 KiB
JavaScript

const TelegramBot = require('node-telegram-bot-api');
require("dotenv").config();
const env = process.env;
const mongoose = require('mongoose');
const handlers = require("./handlers");
const commands = require("./commands");
const config = require('./config');
const modelUser = require('./models/user');
const api = require('./network/api');
const bot = new TelegramBot(env.TOKEN, {polling: true});
mongoose
.connect(env.MONGODB_URI, config.mongodb)
.then(() => {
// Commands
bot.onText(/\/start$/i, commands.start(bot));
bot.onText(/\/account/i, commands.account(bot));
bot.onText(/\/profile/i, commands.profile(bot));
bot.onText(/\/anime/i, commands.anime(bot));
bot.onText(/\/about$/i, commands.about(bot));
// Handlers
bot.on("callback_query", handlers.callbackQuery(bot));
bot.on("polling_error", handlers.botError);
bot.on("error", handlers.botError);
//Successful connection
console.log("[Anixart Info] >> Bot was started.")
})
.catch(error => console.error(error));
// bot.onText('test', async (msg) => {
// const chatId = msg.chat.id;
// let animeList = await api.getProfileByName("ice cream")
// console.log(animeList)
// // send a message to the chat acknowledging receipt of their message
// bot.sendMessage(chatId, `a`);
// });