-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
391 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
const NodeTelegramBotApi = require('node-telegram-bot-api'); | ||
|
||
/** | ||
* Class representing a TelegramBot. | ||
* @extends NodeTelegramBotApi | ||
*/ | ||
class TelegramBot extends NodeTelegramBotApi { | ||
|
||
/** | ||
* Creates an instance of NodeTelegramBotApi | ||
* @param {string} token - Token given by @BotFather | ||
* @param {object} options - Options to initialize NodeTelegramBotApi | ||
* @see https://github.com/yagop/node-telegram-bot-api/blob/release/doc/api.md#new-telegrambottoken-options | ||
*/ | ||
constructor(token, options = {}) { | ||
super(token, options); | ||
} | ||
|
||
/** | ||
* Check for a valid telegram message | ||
* @param {object} msg - Message to check | ||
* @return {boolean} | ||
* @see https://core.telegram.org/bots/api#update | ||
*/ | ||
checkMessage(msg) { | ||
return msg.message | ||
|| msg.edited_message | ||
|| msg.channel_post | ||
|| msg.edited_channel_post | ||
|| msg.inline_query | ||
|| msg.chosen_inline_result | ||
|| msg.callback_query; | ||
return msg.message || | ||
msg.edited_message || | ||
msg.channel_post || | ||
msg.edited_channel_post || | ||
msg.inline_query || | ||
msg.chosen_inline_result || | ||
msg.callback_query; | ||
} | ||
|
||
/** | ||
* Give message to processUpdate parent method | ||
* @param {object} msg - Message to process | ||
*/ | ||
proccessMessage(msg) { | ||
this.processUpdate(msg); | ||
} | ||
|
||
} | ||
|
||
module.exports = TelegramBot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
const events = require('events'); | ||
const EventEmitter = require('events').EventEmitter; | ||
const timeUtility = require('./../utils/time'); | ||
|
||
const eventEmitter = new events.EventEmitter(); | ||
|
||
/** | ||
* this function emits an event | ||
* with the current hour/minute & | ||
* it also emits an event when it's | ||
* a new day | ||
* Class representing an EventEmitter | ||
* @extends EventEmitter | ||
*/ | ||
const emitMinuteMark = () => { | ||
const vzlanHour = timeUtility.vzlanHour(); | ||
const vzlanMinute = timeUtility.vzlanMinute(); | ||
class MorningEvent extends EventEmitter { | ||
/** | ||
* Creates an instance of EventEmitter | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
eventEmitter.emit( | ||
'minuteMark', | ||
vzlanHour, | ||
vzlanMinute, | ||
timeUtility.vzlanWeekday() | ||
); | ||
if (vzlanHour === 0 && vzlanMinute === 0) { | ||
eventEmitter.emit('newDay'); | ||
} | ||
}; | ||
/** | ||
* This function emits an event | ||
* with the current hour/minute & | ||
* it also emits an event when it's | ||
* a new day | ||
*/ | ||
const emitMinuteMark = () => { | ||
const vzlanHour = timeUtility.vzlanHour(); | ||
const vzlanMinute = timeUtility.vzlanMinute(); | ||
|
||
setInterval(emitMinuteMark, 60 * 1000); // 60 seconds | ||
this.emit( | ||
'minuteMark', | ||
vzlanHour, | ||
vzlanMinute, | ||
timeUtility.vzlanWeekday() | ||
); | ||
if (vzlanHour === 0 && vzlanMinute === 0) { | ||
this.emit('newDay'); | ||
} | ||
}; | ||
|
||
setInterval(emitMinuteMark, 60 * 1000); // 60 seconds | ||
} | ||
} | ||
|
||
module.exports = eventEmitter; | ||
module.exports = new MorningEvent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.