-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (43 loc) · 1.29 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Telegraf = require('telegraf');
const assert = require('assert').strict;
const bot = new Telegraf('Your_Token_Here');
const vec = 'vec';
const fs = require('fs');
var lemmaArray = [];
readAllVecCommas("./vec.txt");
function readAllVecCommas(inputpath)
{
try {
// read contents of the file
const data = fs.readFileSync(inputpath, 'UTF-8');
// split the contents by new line.
const lines = data.split(/\r?\n/);
// save all lines
lines.forEach((line) => {
lemmaArray.push(line);
});
}
catch (err) {
console.error(err);
}
}
bot.start((message) => {
console.log('started:', message.from.id);
return message.reply('Ciao vec. Chiedimi una perla scrivendo: vec ');
})
bot.startPolling();
bot.on('text',message =>
{
var messageFromClient = message.message.text;
if (messageFromClient.trim().toUpperCase() === vec.trim().toUpperCase())
{
var randomNumber= Math.random() * (lemmaArray.length - 1);
var randomIndex = Math.floor(randomNumber);
return message.reply(lemmaArray[randomIndex]);
}
else
{
console.log("message: " + messageFromClient.trim() + " from:" + message.from.id);
// return message.reply("Scrivi: vec");
}
});