-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
73 lines (64 loc) · 1.74 KB
/
bot.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
const Telegraf = require('telegraf')
const config = require('./config/config')
const comic = require('./lib/comic')
const random = require('./lib/random')
const bot = new Telegraf(config.telegramToken)
const errMsg = 'Unable to fullfil this request, try again later.'
bot.command('cyanide', (ctx) => {
comic.cyanide(config.explosmUrl)
.then(cyanideLink => {
ctx.replyWithChatAction('upload_photo')
ctx.replyWithPhoto(cyanideLink, {caption: 'Random C&H comic'})
})
.catch(err => {
ctx.reply(errMsg)
console.error(err)
})
})
bot.command('xkcd', (ctx) => {
comic.xkcd(config.xkcdUrl)
.then(xkcdLink => {
ctx.replyWithChatAction('upload_photo')
ctx.replyWithPhoto(xkcdLink, {caption: 'Random XKCD comic'})
})
.catch(err => {
ctx.reply(errMsg)
console.error(err)
})
})
bot.command('dinocomics', (ctx) => {
comic.dinocomics(config.dinocomicsUrl)
.then(dinocomicsLink => {
ctx.replyWithChatAction('upload_photo')
ctx.replyWithPhoto(dinocomicsLink, {caption: 'Random Dinocomics comic'})
})
.catch(err => {
ctx.reply(errMsg)
console.error(err)
})
})
bot.command('randomcat', (ctx) => {
random.cat(config.catApi)
.then(catsLink => {
ctx.replyWithChatAction('upload_photo')
ctx.replyWithPhoto(catsLink, {caption: 'Random Cat'})
})
.catch(err => {
ctx.reply(errMsg)
console.log(err)
})
})
bot.command('randomjoke', (ctx) => {
random.joke(config.jokeUrl)
.then(jokeTxt => {
ctx.replyWithChatAction('typing')
ctx.reply(jokeTxt[0])
setTimeout(() => ctx.reply(jokeTxt[1]), 1000)
})
.catch(err => {
ctx.reply(errMsg)
console.log(err)
})
})
bot.startPolling()