Commit 28ffbbba authored by Guillaume Vagner's avatar Guillaume Vagner
Browse files

funcionnal

parent 08d3442c
const bot = require('./telegram');
const app = require('./website');
const mongoose = require('./mongoose');
const { sendRequest, getBirthdays } = require('./requests');
const Channel = require('./models/Channel');
require('./telegram');
require('./website');
......@@ -2,11 +2,13 @@ const mongoose = require('../mongoose');
const channelSchema = new mongoose.Schema({
token: String,
refresh: String,
expiration: Date,
username: String,
chatId: Number,
state: String,
groups: [Number]
groups: [Number],
scheduleTime: { type: String, validate: /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/ }
})
module.exports = mongoose.model('Channel', channelSchema);
\ No newline at end of file
language: node_js
node_js:
- "4"
- "5"
- "6"
- "8"
- "10"
The MIT License (MIT)
Copyright (c) 2014-2016 Harri Siirak
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
cron-parser
================
[![Build Status](https://travis-ci.org/harrisiirak/cron-parser.svg?branch=master)](https://travis-ci.org/harrisiirak/cron-parser)
[![NPM version](https://badge.fury.io/js/cron-parser.png)](http://badge.fury.io/js/cron-parser)
Node.js library for parsing crontab instructions. It includes support for timezones and DST transitions.
Setup
========
```bash
npm install cron-parser
```
Supported format
========
```
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
```
Supports mixed use of ranges and range increments (L, W and # characters are not supported currently). See tests for examples.
Usage
========
Simple expression.
```javascript
var parser = require('cron-parser');
try {
var interval = parser.parseExpression('*/2 * * * *');
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET)
console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:40:00 GMT+0200 (EET)
} catch (err) {
console.log('Error: ' + err.message);
}
```
Iteration with limited timespan. Also returns ES6 compatible iterator (when iterator flag is set to true).
```javascript
var parser = require('cron-parser');
var options = {
currentDate: new Date('Wed, 26 Dec 2012 12:38:53 UTC'),
endDate: new Date('Wed, 26 Dec 2012 14:40:00 UTC'),
iterator: true
};
try {
var interval = parser.parseExpression('*/22 * * * *', options);
while (true) {
try {
var obj = interval.next();
console.log('value:', obj.value.toString(), 'done:', obj.done);
} catch (e) {
break;
}
}
// value: Wed Dec 26 2012 14:44:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:00:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:22:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:44:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 16:00:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 16:22:00 GMT+0200 (EET) done: true
} catch (err) {
console.log('Error: ' + err.message);
}
```
Timezone support
```javascript
var parser = require('cron-parser');
var options = {
currentDate: '2016-03-27 00:00:01',
tz: 'Europe/Athens'
};
try {
var interval = parser.parseExpression('0 * * * *', options);
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 01:00:00 GMT+0200
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 02:00:00 GMT+0200
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 04:00:00 GMT+0300 (Notice DST transition)
} catch (err) {
console.log('Error: ' + err.message);
}
```
Options
========
* *currentDate* - Start date of the iteration
* *endDate* - End date of the iteration
`currentDate` and `endDate` accept `string`, `integer` and `Date` as input.
In case of using `string` as input, not every string format accepted
by the `Date` constructor will work correctly. The supported formats are: [`ISO8601`](http://momentjs.com/docs/#/parsing/string/) and the older
[`ASP.NET JSON Date`](http://momentjs.com/docs/#/parsing/asp-net-json-date/) format. The reason being that those are the formats accepted by the
[`moment`](http://momentjs.com) library which is being used to handle dates.
Using `Date` as an input can be problematic specially when using the `tz` option. The issue being that, when creating a new `Date` object without
any timezone information, it will be created in the timezone of the system that is running the code. This (most of times) won't be what the user
will be expecting. Using one of the supported `string` formats will solve the issue(see timezone example).
* *iterator* - Return ES6 compatible iterator object
* *utc* - Enable UTC
* *tz* - Timezone string. It won't be used in case `utc` is enabled
{
"name": "cron-parser",
"repo": "harrisiirak/cron-parser",
"description": "Node.js library for parsing crontab instructions",
"version": "2.7.3",
"keywords": ["cron", "crontab", "parser"],
"dependencies": {},
"development": {},
"main": "lib/parser.js",
"scripts": [ "lib/parser.js", "lib/expression.js", "lib/date.js" ]
}
'use strict';
var moment = require('moment-timezone');
CronDate.prototype.addYear = function() {
this._date.add(1, 'year');
};
CronDate.prototype.addMonth = function() {
this._date.add(1, 'month').startOf('month');
};
CronDate.prototype.addDay = function() {
this._date.add(1, 'day').startOf('day');
};
CronDate.prototype.addHour = function() {
var prev = this.getTime();
this._date.add(1, 'hour').startOf('hour');
if (this.getTime() <= prev) {
this._date.add(1, 'hour');
}
};
CronDate.prototype.addMinute = function() {
var prev = this.getTime();
this._date.add(1, 'minute').startOf('minute');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
}
};
CronDate.prototype.addSecond = function() {
var prev = this.getTime();
this._date.add(1, 'second').startOf('second');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
}
};
CronDate.prototype.subtractYear = function() {
this._date.subtract(1, 'year');
};
CronDate.prototype.subtractMonth = function() {
this._date.subtract(1, 'month').endOf('month');
};
CronDate.prototype.subtractDay = function() {
this._date.subtract(1, 'day').endOf('day');
};
CronDate.prototype.subtractHour = function() {
var prev = this.getTime();
this._date.subtract(1, 'hour').endOf('hour');
if (this.getTime() >= prev) {
this._date.subtract(1, 'hour');
}
};
CronDate.prototype.subtractMinute = function() {
var prev = this.getTime();
this._date.subtract(1, 'minute').endOf('minute');
if (this.getTime() > prev) {
this._date.subtract(1, 'hour');
}
};
CronDate.prototype.subtractSecond = function() {
var prev = this.getTime();
this._date.subtract(1, 'second').startOf('second');
if (this.getTime() > prev) {
this._date.subtract(1, 'hour');
}
};
CronDate.prototype.getDate = function() {
return this._date.date();
};
CronDate.prototype.getFullYear = function() {
return this._date.year();
};
CronDate.prototype.getDay = function() {
return this._date.day();
};
CronDate.prototype.getMonth = function() {
return this._date.month();
};
CronDate.prototype.getHours = function() {
return this._date.hours();
};
CronDate.prototype.getMinutes = function() {
return this._date.minute();
};
CronDate.prototype.getSeconds = function() {
return this._date.second();
};
CronDate.prototype.getMilliseconds = function() {
return this._date.millisecond();
};
CronDate.prototype.getTime = function() {
return this._date.valueOf();
};
CronDate.prototype.getUTCDate = function() {
return this._getUTC().date();
};
CronDate.prototype.getUTCFullYear = function() {
return this._getUTC().year();
};
CronDate.prototype.getUTCDay = function() {
return this._getUTC().day();
};
CronDate.prototype.getUTCMonth = function() {
return this._getUTC().month();
};
CronDate.prototype.getUTCHours = function() {
return this._getUTC().hours();
};
CronDate.prototype.getUTCMinutes = function() {
return this._getUTC().minute();
};
CronDate.prototype.getUTCSeconds = function() {
return this._getUTC().second();
};
CronDate.prototype.toISOString = function() {
return this._date.toISOString();
};
CronDate.prototype.toJSON = function() {
return this._date.toJSON();
};
CronDate.prototype.setDate = function(d) {
return this._date.date(d);
};
CronDate.prototype.setFullYear = function(y) {
return this._date.year(y);
};
CronDate.prototype.setDay = function(d) {
return this._date.day(d);
};
CronDate.prototype.setMonth = function(m) {
return this._date.month(m);
};
CronDate.prototype.setHours = function(h) {
return this._date.hour(h);
};
CronDate.prototype.setMinutes = function(m) {
return this._date.minute(m);
};
CronDate.prototype.setSeconds = function(s) {
return this._date.second(s);
};
CronDate.prototype.setMilliseconds = function(s) {
return this._date.millisecond(s);
};
CronDate.prototype.getTime = function() {
return this._date.valueOf();
};
CronDate.prototype._getUTC = function() {
return moment.utc(this._date);
};
CronDate.prototype.toString = function() {
return this._date.toString();
};
CronDate.prototype.toDate = function() {
return this._date.toDate();
};
function CronDate (timestamp, tz) {
if (timestamp instanceof CronDate) {
timestamp = timestamp._date;
}
if (!tz) {
this._date = moment(timestamp);
} else {
this._date = moment.tz(timestamp, tz);
}
}
module.exports = CronDate;
'use strict';
// Load Date class extensions
var CronDate = require('./date');
// Get Number.isNaN or the polyfill
var safeIsNaN = require('is-nan');
/**
* Construct a new expression parser
*
* Options:
* currentDate: iterator start date
* endDate: iterator end date
*
* @constructor
* @private
* @param {Object} fields Expression fields parsed values
* @param {Object} options Parser options
*/
function CronExpression (fields, options) {
this._options = options;
this._utc = options.utc || false;
this._tz = this._utc ? 'UTC' : options.tz;
this._currentDate = new CronDate(options.currentDate, this._tz);
this._startDate = options.startDate ? new CronDate(options.startDate, this._tz) : null;
this._endDate = options.endDate ? new CronDate(options.endDate, this._tz) : null;
this._fields = {};
this._isIterator = options.iterator || false;
this._hasIterated = false;
// Map fields
for (var i = 0, c = CronExpression.map.length; i < c; i++) {
var key = CronExpression.map[i];
this._fields[key] = fields[i];
}
}
/**
* Field mappings
* @type {Array}
*/
CronExpression.map = [ 'second', 'minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek' ];
/**
* Prefined intervals
* @type {Object}
*/
CronExpression.predefined = {
'@yearly': '0 0 1 1 *',
'@monthly': '0 0 1 * *',
'@weekly': '0 0 * * 0',
'@daily': '0 0 * * *',
'@hourly': '0 * * * *'
};
/**
* Fields constraints
* @type {Array}
*/
CronExpression.constraints = [
[ 0, 59 ], // Second
[ 0, 59 ], // Minute
[ 0, 23 ], // Hour
[ 1, 31 ], // Day of month
[ 1, 12 ], // Month
[ 0, 7 ] // Day of week
];
/**
* Days in month
* @type {number[]}
*/
CronExpression.daysInMonth = [
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
];
/**
* Field aliases
* @type {Object}
*/
CronExpression.aliases = {
month: {
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
jul: 7,
aug: 8,
sep: 9,
oct: 10,
nov: 11,
dec: 12
},
dayOfWeek: {
sun: 0,
mon: 1,
tue: 2,
wed: 3,
thu: 4,
fri: 5,
sat: 6
}
};
/**
* Field defaults
* @type {Array}
*/
CronExpression.parseDefaults = [ '0', '*', '*', '*', '*', '*' ];
CronExpression.standardValidCharacters = /^[\d|/|*|\-|,]+$/;
CronExpression.dayValidCharacters = /^[\d|/|*|\-|,|\?]+$/;
CronExpression.validCharacters = {
second: CronExpression.standardValidCharacters,
minute: CronExpression.standardValidCharacters,
hour: CronExpression.standardValidCharacters,
dayOfMonth: CronExpression.dayValidCharacters,
month: CronExpression.standardValidCharacters,
dayOfWeek: CronExpression.dayValidCharacters,
}
/**
* Parse input interval
*
* @param {String} field Field symbolic name
* @param {String} value Field value
* @param {Array} constraints Range upper and lower constraints
* @return {Array} Sequence of sorted values
* @private
*/
CronExpression._parseField = function _parseField (field, value, constraints) {
// Replace aliases
switch (field) {
case 'month':
case 'dayOfWeek':
var aliases = CronExpression.aliases[field];
value = value.replace(/[a-z]{1,3}/gi, function(match) {
match = match.toLowerCase();
if (typeof aliases[match] !== undefined) {
return aliases[match];
} else {
throw new Error('Cannot resolve alias "' + match + '"')
}
});
break;
}
// Check for valid characters.
if (!(CronExpression.validCharacters[field].test(value))) {
throw new Error('Invalid characters, got value: ' + value)
}
// Replace '*' and '?'
if (value.indexOf('*') !== -1) {
value = value.replace(/\*/g, constraints.join('-'));
} else if (value.indexOf('?') !== -1) {
value = value.replace(/\?/g, constraints.join('-'));
}
//
// Inline parsing functions
//
// Parser path:
// - parseSequence
// - parseRepeat
// - parseRange
/**
* Parse sequence
*
* @param {String} val
* @return {Array}
* @private
*/
function parseSequence (val) {
var stack = [];