-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
105d40f
commit 1b52488
Showing
21 changed files
with
141 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { I18n } = require("@grammyjs/i18n"); | ||
const { Bot } = require("grammy"); | ||
|
||
const i18n = new I18n({ | ||
defaultLocale: "en", | ||
directory: "app/bot/locales" | ||
}); | ||
|
||
class TelegramBot { | ||
#log; | ||
bot; | ||
|
||
constructor(options) { | ||
this.#log = options.logger.debug(this.constructor.name); | ||
this.bot = new Bot(options.config.telegramBotToken); | ||
|
||
this.#log('Initializing...'); | ||
this.bot.catch(this.errorHandler); | ||
this.bot.use(options.logger.middleware(this.constructor.name)); | ||
this.bot.use(i18n); | ||
this.bot.command('start', async ctx => { | ||
await ctx.reply('Test'); | ||
}); | ||
} | ||
|
||
errorHandler({ ctx, error }) { | ||
this.#log('Error while handling update %s:', ctx.update.update_id); | ||
|
||
if (error instanceof GrammyError) { | ||
this.#log('Error in request: %s', error.description); | ||
} else if (error instanceof HttpError) { | ||
this.#log('Could not contact Telegram:', error); | ||
} else { | ||
this.#log("Unknown error:", error); | ||
} | ||
} | ||
|
||
start() { | ||
this.#log('Started.'); | ||
this.bot.start(); | ||
} | ||
} | ||
|
||
module.exports = TelegramBot; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
const { createContainer, asClass, asValue, asFunction } = require('awilix'); | ||
|
||
const config = require('./config'); | ||
const logger = require('./logger'); | ||
const { connectToDatabase, mongoose } = require('./db/database'); | ||
const App = require('./app'); | ||
const MarketsService = require('./market/MarketsService'); | ||
const TelegramBot = require('./bot/TelegramBot'); | ||
|
||
const container = createContainer({ | ||
strict: true | ||
}); | ||
|
||
container.register({ | ||
config: asValue(config), | ||
logger: asValue(logger), | ||
mongoose: asValue(mongoose), | ||
db: asFunction(connectToDatabase).singleton(), | ||
app: asClass(App) | ||
app: asClass(App), | ||
marketsService: asClass(MarketsService).singleton(), | ||
bot: asClass(TelegramBot).singleton() | ||
}); | ||
|
||
module.exports = container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var debug = require('debug'); | ||
|
||
module.exports = source => debug(source); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const debug = require('./debug'); | ||
const middleware = require('./middleware'); | ||
|
||
module.exports = { | ||
debug, middleware | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var debug = require('debug'); | ||
|
||
const middleware = source => async (ctx, next) => { | ||
debug(source)('Update Received:'); | ||
debug(source)(ctx.message ?? ctx.update); | ||
|
||
await next(); | ||
}; | ||
|
||
module.exports = middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const round = num => { | ||
return Math.ceil(num * 1000000) / 1000000; | ||
} | ||
|
||
module.exports = round; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters