diff --git a/src/start.ts b/src/start.ts index 2fbda069f..bbe0cfaaf 100644 --- a/src/start.ts +++ b/src/start.ts @@ -17,7 +17,8 @@ import discordConnect from './discord/discord'; import api from './discord/api/api'; // eslint-disable-line // import startMatrix from './matrix/matrix'; // import ircConnect from './irc/irc'; -// import telegramConnect from './telegram/telegram'; +import telegramConnect from './telegram/telegram'; + sourceMap.install(); global.bootTime = new Date(); @@ -37,7 +38,7 @@ async function start() { if (env.DISCORD_CLIENT_TOKEN && validateEnv('DISCORD')) await discordConnect(); // if (env.MATRIX_ACCESS_TOKEN && validateEnv('MATRIX') && env.NODE_ENV !== 'production') await startMatrix(); // if (env.IRC_PASSWORD && validateEnv('IRC') && env.NODE_ENV !== 'production') ircConnect(); - // if (env.TELEGRAM_TOKEN && validateEnv('TELEGRAM') && env.NODE_ENV !== 'production') await telegramConnect(); + if (env.TELEGRAM_TOKEN && validateEnv('TELEGRAM') && env.NODE_ENV !== 'production') await telegramConnect(); } start(); diff --git a/src/telegram/commands/t.index.ts b/src/telegram/commands/t.index.ts index a4927f4cf..ce75e3f4d 100644 --- a/src/telegram/commands/t.index.ts +++ b/src/telegram/commands/t.index.ts @@ -1,20 +1,34 @@ /* eslint-disable global-require */ -import { Composer } from 'telegraf'; +import start from './t.start'; +import drug from './t.drug'; +import topic from './t.topic'; +import combo from './t.combo'; +import breathe from './t.breathe'; +import combochart from './t.combochart'; +import irc from './t.irc'; +import ban from './t.ban'; +import moderateChat from './t.moderateChat'; +import gban from './t.gban'; +import about from './t.about'; +import recovery from './t.recovery'; +import calcMushrooms from './t.calc-mushrooms'; +import calcLsd from './t.calc-lsd'; -export default Composer.compose([ - require('./t.start'), - require('./t.drug'), - require('./t.topic'), - require('./t.combo'), - require('./t.breathe'), - require('./t.combochart'), - require('./t.irc'), - require('./t.ban'), - require('./t.moderateChat'), - require('./t.gban'), - // require('./t.eightball'), - require('./t.about'), - require('./t.recovery'), - require('./t.calc-mushrooms'), - require('./t.calc-lsd'), -]); + +export default [ + start, + drug, + topic, + combo, + breathe, + combochart, + irc, + ban, + moderateChat, + gban, + // eightball, + about, + recovery, + calcMushrooms, + calcLsd, +] \ No newline at end of file diff --git a/src/telegram/telegram.ts b/src/telegram/telegram.ts index 7830bbe71..ec0dd79aa 100644 --- a/src/telegram/telegram.ts +++ b/src/telegram/telegram.ts @@ -1,19 +1,22 @@ -import { Telegraf as TelegramClient } from 'telegraf'; - -const commands = require('./commands/t.index'); +import { Telegraf } from 'telegraf'; +import commands from './commands/t.index'; const F = f(__filename); export default async function telegramConnect() { log.debug(F, 'Connecting to Telegram...'); - const bot = new TelegramClient(env.TELEGRAM_TOKEN); + const bot = new Telegraf(env.TELEGRAM_TOKEN); // load bot commands - bot.use(commands); + bot.use(...commands); bot.launch(); + bot.catch((err: any) => { + log.error(F, `Error in Telegram bot: ${err}`); + }); + global.telegramClient = bot; process.once('SIGINT', () => bot.stop('SIGINT')); @@ -21,5 +24,5 @@ export default async function telegramConnect() { } declare global { - var telegramClient: TelegramClient; // eslint-disable-line + var telegramClient: Telegraf; } diff --git a/tsconfig.json b/tsconfig.json index c3bfb50af..5e7354887 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "*/matrix/*", "*/node_modules", "node_modules", - "*/telegram/*", + // "*/telegram/*", "**/__tests__editreply_/*", "**/__tests__integration__/*", "**/__tests__modals__/*",