-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
106 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const BirthdayService = require('../services/birthday') | ||
|
||
const monthTexts = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Setiembre","Octubre","Noviembre","Diciembre"] | ||
|
||
class Birthday { | ||
async addBirthday (target, text, bot, name) { | ||
const day = this._getDay(text) | ||
const month = this._getMonth(text) | ||
const nick = name.toLowerCase() | ||
|
||
const result = await BirthdayService.addBirthday(nick, day, month) | ||
if (result) { | ||
bot.say(target, this._getText(result)) | ||
} | ||
} | ||
|
||
async getBirthday (target, text, bot) { | ||
const nick = text.trim().replace('@', '').toLowerCase() | ||
const result = await BirthdayService.getBirthday(nick) | ||
|
||
if (result) { | ||
bot.say(target, this._getText(result)) | ||
} | ||
} | ||
|
||
_getText(model) { | ||
return `@${model.nick} cumple el dia ${model.day} de ${monthTexts[model.month -1]}` | ||
} | ||
|
||
_getDay (text) { | ||
return parseInt(text.split('-')[0].trim()) | ||
} | ||
|
||
_getMonth (text) { | ||
return parseInt(text.split('-')[1].trim()) | ||
} | ||
} | ||
|
||
module.exports = Birthday |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const mongoose = require('mongoose') | ||
const Schema = mongoose.Schema | ||
|
||
/* Channel Schema */ | ||
const BirthdaySchema = new Schema({ | ||
nick: { | ||
type: String, | ||
required: true | ||
}, | ||
day: { | ||
type: Number, | ||
required: true | ||
}, | ||
month: { | ||
type: Number, | ||
required: true | ||
} | ||
}) | ||
|
||
module.exports = mongoose.model('birthday', BirthdaySchema, 'birthdays') |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const dbManager = require('../helpers/dbmanager') | ||
|
||
async function getBirthday(nick) { | ||
let result = null | ||
result = await dbManager.getBirthday(nick) | ||
return result | ||
} | ||
|
||
async function addBirthday(nick, day, month) { | ||
return await dbManager.updateBirthday(nick, {day: day, month: month}) | ||
} | ||
|
||
|
||
module.exports = { | ||
getBirthday, | ||
addBirthday | ||
} |