Skip to content

Commit

Permalink
WIP1-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho committed Sep 6, 2023
1 parent c2f1450 commit d7d07e1
Show file tree
Hide file tree
Showing 24 changed files with 358 additions and 146 deletions.
18 changes: 10 additions & 8 deletions app.js → app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require('dotenv').config();
const { SocksProxyAgent } = require('socks-proxy-agent');
const { start } = require('./bot');
const mongoConnect = require('./db_connect');
import * as dotenv from "dotenv";
dotenv.config()
import { SocksProxyAgent } from "socks-proxy-agent";
import { start } from "./bot/start";
import mongoConnect from './db_connect'
const { resubscribeInvoices } = require('./ln');
const logger = require('./logger');
import logger from "./logger";
const { delay } = require('./util');

(async () => {
Expand All @@ -30,12 +31,13 @@ const { delay } = require('./util');
telegram: {
agent,
},
};
} as any;
}
const bot = start(process.env.BOT_TOKEN, options);
const bot = start(String(process.env.BOT_TOKEN), options);
// Wait 1 seconds before try to resubscribe hold invoices
await delay(1000);
await resubscribeInvoices(bot);
})
.on('error', error => logger.error(`Error connecting to Mongo: ${error}`));
.on('error', (error: Error) => logger.error(`Error connecting to Mongo: ${error}`));
})();

6 changes: 3 additions & 3 deletions bot/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TelegramError } = require('telegraf');
const QR = require('qrcode');
import { TelegramError } from 'telegraf'
import QR from 'qrcode';
const {
getCurrency,
numberFormat,
Expand All @@ -12,7 +12,7 @@ const {
decimalRound,
getUserAge,
} = require('../util');
const logger = require('../logger');
import logger from "../logger";
import { MainContext } from './start';
import { UserDocument } from '../models/user'
import { IOrder } from '../models/order'
Expand Down
17 changes: 8 additions & 9 deletions bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { I18n, I18nContext } from '@grammyjs/i18n';
import { Message } from 'typegram'
import { UserDocument } from '../models/user'
import { FilterQuery } from 'mongoose';

const { limit } = require('@grammyjs/ratelimiter');
const schedule = require('node-schedule');
import { limit } from "@grammyjs/ratelimiter"
import schedule from 'node-schedule';
const {
Order,
User,
Expand Down Expand Up @@ -66,7 +65,7 @@ const {
deleteCommunity,
nodeInfo,
} = require('../jobs');
const logger = require('../logger');
import logger from "../logger";

export interface MainContext extends Context {
match: Array<string> | null;
Expand All @@ -75,7 +74,7 @@ export interface MainContext extends Context {
admin: UserDocument;
}

interface OrderQuery {
export interface OrderQuery {
status?: string;
buyer_id?: string;
seller_id?: string;
Expand Down Expand Up @@ -137,7 +136,7 @@ has the same condition.
The problem mentioned above is similar to this issue:
https://github.com/telegraf/telegraf/issues/1319#issuecomment-766360594
*/
const ctxUpdateAssertMsg = "ctx.update.message.text is not available.";
export const ctxUpdateAssertMsg = "ctx.update.message.text is not available.";

const initialize = (botToken: string, options: Partial<Telegraf.Options<MainContext>>): Telegraf<MainContext> => {
const i18n = new I18n({
Expand Down Expand Up @@ -256,7 +255,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
throw new Error(ctxUpdateAssertMsg);
}
const params = ctx.update.message.text.split(' ');
const [command, orderId] = params.filter((el) => el);
const [command, orderId] = params.filter((el: string) => el);

if (!orderId) {
const orders = await askForConfirmation(ctx.user, command);
Expand Down Expand Up @@ -347,7 +346,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
throw new Error(ctxUpdateAssertMsg);
}
const params = ctx.update.message.text.split(' ');
const [command, orderId] = params.filter((el) => el);
const [command, orderId] = params.filter((el: string) => el);

if (!orderId) {
const orders = await askForConfirmation(ctx.user, command);
Expand Down Expand Up @@ -515,7 +514,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
throw new Error(ctxUpdateAssertMsg);
}
const params = ctx.update.message.text.split(' ');
const [command, orderId] = params.filter((el) => el);
const [command, orderId] = params.filter((el: string) => el);

if (!orderId) {
const orders = await askForConfirmation(ctx.user, command);
Expand Down
Loading

0 comments on commit d7d07e1

Please sign in to comment.