-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
130 lines (120 loc) · 3.37 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const TelegramBot = require("node-telegram-bot-api");
const schedule = require("node-schedule");
require("dotenv").config();
const http = require("http");
const bot = new TelegramBot(process.env.TOKEN, { polling: true });
let peopleNotHaveFood = [];
let userInput = false;
bot.on("message", (msg) => {
var Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
bot.sendChatAction(msg.chat.id, "typing");
bot.sendMessage(msg.chat.id, "Hello");
}
});
bot.onText(/\/no/, (msg) => {
if (userInput) {
if (!peopleNotHaveFood.includes(msg.from.id)) {
peopleNotHaveFood.push(msg.from.id);
console.log(msg.chat.id);
bot.sendMessage("552375707", msg.from.first_name + ", Not Having Food");
bot.sendMessage(msg.chat.id, "Your input has been recorded");
} else {
bot.sendMessage(msg.chat.id, "Input already recorded");
}
} else {
bot.sendMessage(msg.chat.id, "List already prepared.");
}
});
bot.onText(/\/start/, (msg) => {
schedule.scheduleJob(
{ hour: 23, minute: 57, dayOfWeek: [0, 6] },
bot.sendMessage(msg.from.id, "Hello " + msg.from.first_name)
);
});
bot.onText(/\/menu/, (msg) => {
bot.sendMessage(msg.chat.id, "<strong>Monday</strong>:<i>daliya</i>", {
parse_mode: "HTML",
});
});
function timeTable() {
const breakFast = schedule.scheduleJob(
{ hour: 8, minute: 0, dayOfWeek: [1, 6] },
function () {
userInput = true;
peopleNotHaveFood = [];
bot.sendMessage(
"-1001353914062",
"<b>Are you having lunch</b>\n<strong>If no please Respond with /no </strong>\n\n\n<i>thank you.</i>",
{
parse_mode: "HTML",
}
);
}
);
const lunch = schedule.scheduleJob(
{ hour: 12, minute: 0, dayOfWeek: [0, 6] },
function () {
peopleNotHaveFood = [];
bot.sendMessage(
"-1001353914062",
"<b>Are you having lunch</b>\n<strong>If no please Respond with /no </strong>\n\n\n<i>thank you.</i>",
{
parse_mode: "HTML",
}
);
userInput = true;
}
);
const dinner = schedule.scheduleJob(
{ hour: 19, minute: 47, dayOfWeek: [0, 6] },
function () {
peopleNotHaveFood = [];
bot.sendMessage(
"-1001353914062",
"<b>Are you having dinner</b>\n<strong>If no please Respond with /no </strong>\n\n\n<i>thank you.</i>",
{
parse_mode: "HTML",
}
);
userInput = true;
}
);
}
function listOfPeople() {
const breakFast = schedule.scheduleJob(
{ hour: 8, minute: 30, dayOfWeek: [0, 6] },
function () {
bot.sendMessage(
"552375707",
"Number of people not having food " + peopleNotHaveFood.length
);
userInput = false;
}
);
const lunch = schedule.scheduleJob(
{ hour: 12, minute: 30, dayOfWeek: [0, 6] },
function () {
bot.sendMessage(
"552375707",
"Number of people not having food. " + peopleNotHaveFood.length
);
userInput = false;
}
);
const dinner = schedule.scheduleJob(
{ hour: 19, minute: 48, dayOfWeek: [0, 6] },
function () {
bot.sendMessage(
"552375707",
"Number of people not having food." + peopleNotHaveFood.length
);
userInput = false;
}
);
}
listOfPeople();
timeTable();
let server = http
.createServer()
.listen(process.env.PORT || 3000, () => console.log("conneted"));