-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
111 lines (77 loc) · 3.14 KB
/
server.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
process.env.NTBA_FIX_319='production'
const TelegramBot = require('node-telegram-bot-api');
const token = "594136880:AAEKyek5W-ZEHwdP52n1iEPQzBJwFLtISTo";
const bot = new TelegramBot(token, {polling: true});
var fs = require('fs');
const Btn1_RASM = 'پیام تبریک رسمی';
const Btn1_DUST = 'پیام تبریک دوستانه';
const BTN1GP = {'keyboard':[[Btn1_RASM,Btn1_DUST]],'resize_keyboard':true};
const _SESSION = [];
bot.onText(/\/start/, (msg) => {
var initData = {
"RASM":[],
"DUST": []
};
fs.writeFile(`./data/USERS/${msg.from.username}.json`, JSON.stringify(initData),()=>{
bot.sendMessage(
msg.from.id,
"لطفا انتخاب کنید",{
'reply_markup':BTN1GP,
})
bot.on('message', (msg) => {
fs.readFile(`./data/USERS/${msg.from.username}.json` , function (err, data) {
if (data)
var userData = JSON.parse(data);
if (msg.text == Btn1_RASM ) {
if( userData.RASM.length >=23){
userData.RASM=[];
}
var rasmArray = userData.RASM;
do{
var randomNumber = Math.ceil(Math.random() * 23);
}while(rasmArray.find((rasmNumber)=>randomNumber===rasmNumber));
userData.RASM.push(randomNumber)
fs.writeFile(`./data/USERS/${msg.from.username}.json` , JSON.stringify(userData), (err) => {
if (err) throw err;
});
fs.readFile(`./data/RASM/${randomNumber}.txt`, 'utf8', function (err, data) {
if (err) {
return;
}
bot.sendMessage(
msg.chat.id,
data + "\n\n" + "از طرف "+ msg.from.first_name ,
{parse_mode : "HTML"}
);
});
return true;
}
if (msg.text == Btn1_DUST ) {
if( userData.DUST.length >=23){
userData.DUST=[];
}
var dustArray = userData.DUST;
do{
var randomNumber = Math.ceil(Math.random() * 23);
}while(dustArray.find((dustNumber)=>randomNumber===dustNumber));
userData.DUST.push(randomNumber)
fs.writeFile(`./data/USERS/${msg.from.username}.json` , JSON.stringify(userData), (err) => {
if (err) throw err;
});
fs.readFile(`./data/DUST/${randomNumber}.txt`, 'utf8', function (err, data) {
if (err) {
return;
}
bot.sendMessage(
msg.chat.id,
data + "\n\n" + "از طرف "+ msg.from.first_name ,
{parse_mode : "HTML"}
);
});
return true
}
})
});
});
return true
});