-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
executable file
·70 lines (55 loc) · 1.48 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
const telegraf = require('telegraf');
const uuid1 = require('uuid/v1');
const setupServer = require('./server');
bot = new telegraf(process.env.TOKEN);
bot.start(ctx => {
const message = `Hello, ${ctx.message.from.username}. Use /help for help.`;
ctx.reply(message);
});
bot.help(ctx => {
const message = `
Write me something and I'll send it back to you but in sArCaSm font, so you can copy and paste it.
Or
Just type "@sarcybot I want this in sarcasm font" in another chat and I'll do all the things for you.
`;
ctx.reply(message);
});
bot.on('message', ctx => {
const msg = ctx.message.text;
if (msg === '/start' || msg === '/help') {
return;
}
const sarcasm = makeSarcasm(msg);
ctx.reply(sarcasm);
});
bot.on('inline_query', ({ inlineQuery, answerInlineQuery }) => {
const sarcasmString = makeSarcasm(inlineQuery.query);
if (!sarcasmString) {
return;
}
const option = {
type: 'article',
id: uuid1(),
title: sarcasmString,
input_message_content: {
message_text: sarcasmString
}
};
return answerInlineQuery([option]);
});
bot.on('choosen_inline_result', ({ chosenInlineResult }) => {
console.log(chosenInlineResult);
});
function makeSarcasm(string) {
const sarcasm = [];
for (let i = 0; i < string.length; i++) {
if (i % 2 === 0) {
sarcasm.push(string[i].toUpperCase());
} else {
sarcasm.push(string[i].toLowerCase());
}
}
return sarcasm.join('');
}
bot.launch();
setupServer();