hubot-note
Version:
hubot note taking script
87 lines (69 loc) • 2.73 kB
text/coffeescript
strftime = require('strftime')
NoteManager = require('./note_manager.coffee').NoteManager
class HubotNote
constructor: (robot) ->
= new NoteManager robot
= new RegExp(robot.name)
executeMessage: (room_name, text) ->
message_words = text.split " "
user_name = message_words[0]
if user_name.match
command_name = message_words[1]
command_type = message_words[2]
note_title =
if command_name == "note"
switch command_type
when "start"
if note_title == null
note_title = strftime('%Y-%m-%d', new Date)
return
when "isStart?"
return
when "stop"
return
when "show"
# show (-l show_line_num)
return
# not match command
# write note
.writeTextToNewestNoteInRoom room_name, text
return null
getNoteName: (room_name, note_title) ->
if note_title
return note_title
else
note = .executeGetStartedNote(room_name)
if note != null
return note.title
return null
getOptionValue: (split_str, option_str, default_data) ->
index = split_str.indexOf(option_str)
if 0 < index and index+1 < split_str.length
return split_str[index+1]
else
return default_data
executeNoteStart: (room_name, note_title) ->
if .executeStartNote room_name, note_title
return "#{note_title} start"
else
return "#{note_title} can't start"
executeIsStart: (room_name, note_title) ->
return "There is no started note" if note_title == null
if .executeIsStartNote room_name, note_title
return "#{note_title} is started"
else
return "#{note_title} isn't started"
executeNoteStop: (room_name, note_title) ->
return "There is no started note" if note_title == null
if .executeNoteStop room_name, note_title
return "#{note_title} is stopped"
else
return "#{note_title} isn't start"
executeNoteShow: (room_name, note_title, line_num) ->
return "There is no started note" if note_title == null
note_text = .executeNoteShow room_name, note_title, line_num
if note_text
return note_text
else
return "#{note_title} not exist"
module.exports.HubotNote = HubotNote