-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const clashApi = require('clash-of-clans-api');
const { Telegraf } = require('telegraf');
const clan = require('./src/callbacks/clan');
const player = require('./src/callbacks/player');
const telegramReplies = require('./src/replies/telegram');
// Telegram init
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.catch((err, ctx) => console.log(`Ooops, encountered an error for ${ctx.updateType}.`, err));
// Clash of Clans API init
const clashOfClansClient = clashApi();
// Telegram commands
bot.start((ctx) => ctx.replyWithHTML(telegramReplies.getStarted));
bot.help((ctx) => ctx.replyWithHTML(telegramReplies.getStarted));
bot.launch();
// Clan commands
bot.command('clan', async (ctx) => await clan.getClan(ctx, clashOfClansClient));
bot.command('claneros', async (ctx) => await clan.getClanMembers(ctx, clashOfClansClient));
// Player commands
bot.command('jugador', async (ctx) => await player.getPlayer(ctx, clashOfClansClient));
// Help commands
bot.command('ayuda', (ctx) => ctx.replyWithHTML(telegramReplies.getStarted));
// On message sended.
bot.on('message', async (ctx) => {
const { text } = ctx.message;
let message = '';
if (text.charAt(0) == '#') {
const tag = text.substring(0, 10);
ctx.reply(await player.playerMessage(tag, clashOfClansClient));
}
});