Socket
Socket
Sign inDemoInstall

telegram-inline-calendar

Package Overview
Dependencies
1
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.4 to 1.7.0

2

package.json
{
"name": "telegram-inline-calendar",
"version": "1.6.4",
"version": "1.7.0",
"description": "Date and time picker and inline calendar for Node.js telegram bots",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -291,5 +291,7 @@ <h1 align="center">telegram-inline-calendar</h1>

time_step: "30m", //Time step in the format "<Time step><m | h>"
start_date: false, //Minimum date of the calendar in the format "YYYY-MM-DD"
stop_date: false, //Maximum date of the calendar in the format "YYYY-MM-DD"
custom_start_msg: false //Text of the message sent with the calendar/time selector
start_date: false, //Minimum date of the calendar in the format "YYYY-MM-DD" or "YYYY-MM-DD HH:mm" or "now"
stop_date: false, //Maximum date of the calendar in the format "YYYY-MM-DD" or "YYYY-MM-DD HH:mm" or "now"
custom_start_msg: false, //Text of the message sent with the calendar/time selector
lock_date: false, //Enable blocked dates list
lock_datetime: false //Enable list of blocked dates and times
}

@@ -296,0 +298,0 @@ ```

@@ -15,5 +15,31 @@ const lang = require("./language.json");

this.options.time_step = (typeof options.time_step === 'undefined') ? "30m" : options.time_step;
this.options.start_date = (typeof options.start_date === 'undefined') ? false : options.start_date;
this.options.stop_date = (typeof options.stop_date === 'undefined') ? false : options.stop_date;
if (typeof options.start_date === 'undefined') {
this.options.start_date = false;
} else {
if (options.start_date === 'now') {
this.options.start_date = dayjs().format("YYYY-MM-DD HH:mm");
} else {
this.options.start_date = dayjs(options.start_date).format("YYYY-MM-DD HH:mm");
}
}
if (typeof options.stop_date === 'undefined') {
this.options.stop_date = false;
} else {
if (options.stop_date === 'now') {
this.options.stop_date = dayjs().format("YYYY-MM-DD HH:mm");
} else if (dayjs(options.stop_date).format("HH:mm") == '00:00') {
this.options.stop_date = dayjs(options.stop_date).format("YYYY-MM-DD") + " 23:59";
} else {
this.options.stop_date = dayjs(options.stop_date).format("YYYY-MM-DD HH:mm");
}
}
this.options.custom_start_msg = (typeof options.custom_start_msg === 'undefined') ? false : options.custom_start_msg;
this.options.lock_datetime = (typeof options.lock_datetime === 'undefined') ? false : options.lock_datetime;
this.options.lock_date = (typeof options.lock_date === 'undefined') ? false : options.lock_date;
if (this.options.lock_datetime) {
this.lock_datetime_array = new Array();
}
if (this.options.lock_date) {
this.lock_date_array = new Array();
}
this.bot = bot;

@@ -23,2 +49,4 @@ this.chats = new Map();

this.libraryInitialization();
this.dateFuncInitialization();
this.datetimeFuncInitialization();
}

@@ -118,2 +146,24 @@ NodeTelegramBotApi = {

};
DatetimeFunc = {
withoutLockDatetime(stop, datetime, type) {
return (dayjs(stop).diff(datetime, type) < 0) ? true : false;
},
withLockDatetime(stop, datetime, type) {
return (dayjs(stop).diff(datetime, type) < 0 || this.lock_datetime_array.includes(datetime)) ? true : false;
}
};
DateFunc = {
withoutLockDate(date, d) {
if ((!this.options.start_date || (this.options.start_date && dayjs(date).date(d).hour(0).minute(0).diff(dayjs(this.options.start_date).hour(0).minute(0), 'day') >= 0)) && (!this.options.stop_date || (this.options.stop_date && dayjs(this.options.stop_date).hour(0).minute(0).diff(dayjs(date).date(d).hour(0).minute(0), 'day') >= 0))) {
return true;
}
return false;
},
withLockDate(date, d) {
if ((!this.options.start_date || (this.options.start_date && dayjs(date).date(d).hour(0).minute(0).diff(dayjs(this.options.start_date).hour(0).minute(0), 'day') >= 0)) && (!this.options.stop_date || (this.options.stop_date && dayjs(this.options.stop_date).hour(0).minute(0).diff(dayjs(date).date(d).hour(0).minute(0), 'day') >= 0)) && !this.lock_date_array.includes(date.getFullYear() + '-' + this.twoDigits(date.getMonth() + 1) + '-' + this.twoDigits(d))) {
return true;
}
return false;
}
};
addCustomStartMsg() {

@@ -157,2 +207,16 @@ if (this.options.custom_start_msg !== false) {

}
dateFuncInitialization() {
if (this.options.lock_date) {
this.checkDate = this.DateFunc.withLockDate;
} else {
this.checkDate = this.DateFunc.withoutLockDate;
}
}
datetimeFuncInitialization() {
if (this.options.lock_datetime) {
this.checkDatetime = this.DatetimeFunc.withLockDatetime;
} else {
this.checkDatetime = this.DatetimeFunc.withoutLockDatetime;
}
}
weekDaysButtons(day) {

@@ -197,7 +261,31 @@ return (day + this.options.start_week_day > 6) ? (day + this.options.start_week_day - 7) : (day + this.options.start_week_day);

}
if (dayjs(datetime).format("HH") < time_range[0].split(':')[0] || (dayjs(datetime).format("HH") == time_range[0].split(':')[0] && dayjs(datetime).format("mm") <= time_range[0].split(':')[1])) {
datetime.setHours(time_range[0].split(':')[0]);
datetime.setMinutes(time_range[0].split(':')[1]);
datetime.setSeconds(0);
flag_start++;
if (this.options.start_date !== false) {
if (dayjs(datetime).format("YYYY-MM-DD") != dayjs(this.options.start_date).format("YYYY-MM-DD")) {
if (dayjs(datetime).format("HH") < time_range[0].split(':')[0] || (dayjs(datetime).format("HH") == time_range[0].split(':')[0] && dayjs(datetime).format("mm") <= time_range[0].split(':')[1])) {
datetime.setHours(time_range[0].split(':')[0]);
datetime.setMinutes(time_range[0].split(':')[1]);
datetime.setSeconds(0);
flag_start++;
}
} else {
if (dayjs(datetime).format("HH") < time_range[0].split(':')[0] || (dayjs(datetime).format("HH") == time_range[0].split(':')[0] && dayjs(datetime).format("mm") <= time_range[0].split(':')[1])) {
datetime.setHours(time_range[0].split(':')[0]);
datetime.setMinutes(time_range[0].split(':')[1]);
datetime.setSeconds(0);
flag_start = 1;
}
if (dayjs(datetime).format("HH") < dayjs(this.options.start_date).format("HH") || (dayjs(datetime).format("HH") == dayjs(this.options.start_date).format("HH") && dayjs(datetime).format("mm") <= dayjs(this.options.start_date).format("mm"))) {
datetime.setHours(dayjs(this.options.start_date).format("H"));
datetime.setMinutes(dayjs(this.options.start_date).format("m"));
datetime.setSeconds(0);
flag_start = 1;
}
}
} else {
if (dayjs(datetime).format("HH") < time_range[0].split(':')[0] || (dayjs(datetime).format("HH") == time_range[0].split(':')[0] && dayjs(datetime).format("mm") <= time_range[0].split(':')[1])) {
datetime.setHours(time_range[0].split(':')[0]);
datetime.setMinutes(time_range[0].split(':')[1]);
datetime.setSeconds(0);
flag_start++;
}
}

@@ -208,2 +296,9 @@ stop = new Date(datetime);

stop.setSeconds(0);
if (this.options.stop_date !== false && dayjs(stop).format("YYYY-MM-DD") == dayjs(this.options.stop_date).format("YYYY-MM-DD")) {
if (dayjs(stop).format("HH") > dayjs(this.options.stop_date).format("HH") || (dayjs(stop).format("HH") == dayjs(this.options.stop_date).format("HH") && dayjs(stop).format("mm") > dayjs(this.options.stop_date).format("mm"))) {
stop.setHours(dayjs(this.options.stop_date).format("H"));
stop.setMinutes(dayjs(this.options.stop_date).format("m"));
stop.setSeconds(0);
}
}
for (i = d; i < d + 4; i++) {

@@ -215,3 +310,3 @@ cnk.inline_keyboard.push([{},{},{},{}]);

}
cnk.inline_keyboard[i][j] = (dayjs(stop).diff(dayjs(datetime).format("YYYY-MM-DD HH:mm"), type) < 0) ? {text: ' ', callback_data: ' '} : {text: dayjs(datetime).format("HH:mm"), callback_data: 't_' + dayjs(datetime).format("YYYY-MM-DD HH:mm") + '_0'};
cnk.inline_keyboard[i][j] = (this.checkDatetime(stop, dayjs(datetime).format("YYYY-MM-DD HH:mm"), type)) ? {text: ' ', callback_data: ' '} : {text: dayjs(datetime).format("HH:mm"), callback_data: 't_' + dayjs(datetime).format("YYYY-MM-DD HH:mm") + '_0'};
datetime = new Date(dayjs(datetime).add(step, type).format("YYYY-MM-DD HH:mm"));

@@ -270,3 +365,3 @@ }

} else {
if ((!this.options.start_date || (this.options.start_date && dayjs(date).date(d).hour(0).diff(dayjs(this.options.start_date).hour(0), 'day') >= 0)) && (!this.options.stop_date || (this.options.stop_date && dayjs(this.options.stop_date).hour(0).diff(dayjs(date).date(d).hour(0), 'day') >= 0))) {
if (this.checkDate(date, d)) {
cnk.inline_keyboard[i][j] = {text: d, callback_data: 'n_' + date.getFullYear() + '-' + this.twoDigits(date.getMonth() + 1) + '-' + this.twoDigits(d) + '_0'};

@@ -300,3 +395,27 @@ } else {

now.setSeconds(0);
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(now)), msg);
if (this.options.start_date !== false) {
if (new Date(dayjs(this.options.start_date).format("YYYY-MM-01")) > now) {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(new Date(dayjs(this.options.start_date).format("YYYY-MM-01")))), msg);
} else {
if (this.options.stop_date !== false) {
if (new Date(this.options.stop_date) < now) {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(new Date(dayjs(this.options.start_date).format("YYYY-MM-01")))), msg);
} else {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(now)), msg);
}
} else {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(now)), msg);
}
}
} else {
if (this.options.stop_date !== false) {
if (new Date(this.options.stop_date) < now) {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(new Date(dayjs(this.options.stop_date).format("YYYY-MM-01")))), msg);
} else {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(now)), msg);
}
} else {
this.sendMessageCalendar(this.replyMarkupObject(this.createNavigationKeyboard(now)), msg);
}
}
}

@@ -303,0 +422,0 @@ startTimeSelector(msg) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc