<commit_before># note
# CREATE TABLE inventory(id integer primary key, name text not null, expiration_date text not null);

# functions
validate_expiration_date = (expiration_date) ->  # expiration_date format must be 'YYYYMMDD'
  ey = parseInt(expiration_date.substr(0, 4), 10)
  em = parseInt(expiration_date.substr(4, 2), 10)
  ed = parseInt(expiration_date.substr(6, 2), 10)
  edate = new Date(ey, em-1, ed)
  today = new Date()
  diff = edate.getTime()-today.getTime()
  return edate.getFullYear()==ey && edate.getMonth()==em-1 && edate.getDate()==ed && diff>0

# main
module.exports = (robot) ->

  sqlite3 = require "sqlite3"
  db = new sqlite3.Database "./databases/main.sqlite3"

  robot.hear /^へるぷ$/i, (res) ->
    res.send [
                "Commands:",
                "  へるぷ",
                "  りすと",
                "  とうろく [food_name] [expiration_date](YYYYMMDD)",
                "  さくじょ [id]"
              ].join("\n")

  robot.hear /^りすと$/i, (res) ->
    db.all "SELECT * FROM inventory", (err, rows) ->
      if err
        res.send "Failed to check, sorry:bow:"
        throw err
      else
        if rows.length == 0
          res.send "Nothing is found in our refrigerator..."
        else
          inventory = "[id], [food_name], [expiration_date]"
          rows.forEach (row) ->
            inventory += "#{row.id}, #{row.name}, #{row.expiration_date}\n"
          res.send "#{inventory.substr(0, inventory.length-1)}"

  robot.hear /^とうろく.*/i, (res) ->
    if query = /^とうろく\s+(.*)\s+([0-9]{8})$/i.exec res.match[0]
      name = query[1]
      expiration_date = query[2]<commit_msg>fixed bug<commit_after># note
# CREATE TABLE inventory(id integer primary key, name text not null, expiration_date text not null);

# functions
validate_expiration_date = (expiration_date) ->  # expiration_date format must be 'YYYYMMDD'
  ey = parseInt(expiration_date.substr(0, 4), 10)
  em = parseInt(expiration_date.substr(4, 2), 10)
  ed = parseInt(expiration_date.substr(6, 2), 10)
  edate = new Date(ey, em-1, ed)
  today = new Date()
  diff = edate.getTime()-today.getTime()
  return edate.getFullYear()==ey && edate.getMonth()==em-1 && edate.getDate()==ed && diff>0

# main
module.exports = (robot) ->

  sqlite3 = require "sqlite3"
  db = new sqlite3.Database "./databases/main.sqlite3"

  robot.hear /^へるぷ$/i, (res) ->
    res.send [
                "Commands:",
                "  へるぷ",
                "  りすと",
                "  とうろく [food_name] [expiration_date](YYYYMMDD)",
                "  さくじょ [id]"
              ].join("\n")

  robot.hear /^りすと$/i, (res) ->
    db.all "SELECT * FROM inventory", (err, rows) ->
      if err
        res.send "Failed to check, sorry:bow:"
        throw err
      else
        if rows.length == 0
          res.send "Nothing is found in our refrigerator..."
        else
          inventory = "[id], [food_name], [expiration_date]\n"
          rows.forEach (row) ->
            inventory += "#{row.id}, #{row.name}, #{row.expiration_date}\n"
          res.send "#{inventory.substr(0, inventory.length-1)}"

  robot.hear /^とうろく.*/i, (res) ->
    if query = /^とうろく\s+(.*)\s+([0-9]{8})$/i.exec res.match[0]
      name = query[1]
      expiration_date = query[2]
{'fraction_non_alphanumeric': 0.1654252017380509, 'fraction_numerical': 0.01738050900062073, 'mean_word_length': 2.3962065331928346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5860331', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1156, 'n_words': 256}