Exemplo n.º 1
0
 }).then(function(rating) {
   if (rating) {
     users[data.user].state = 'record3';
     users[data.user].place = place;
     bot.postTo(
       receiver,
       placeName + '에 다녀왔구나! 이대로 입력할까?\n입력하려면 `응` 혹은 `맞아`라고 대답해줘. 취소하려면 `취소`라고 입력해줘.',
       attachments.place({
         name: place.dataValues.name,
         desc: place.dataValues.desc,
         price: place.dataValues.price,
         informer: place.dataValues.User.dataValues.name
       },':kissing_smiling_eyes:')
     );
   } else {
     users[data.user].state = 'record2';
     users[data.user].place = place;
     bot.postTo(
       receiver,
       `${placeName}에 다녀왔구나! 오늘의 평점을 1점에서 10점 사이로 숫자만 입력해줘.`,
       attachments.place({
         name: place.dataValues.name,
         desc: place.dataValues.desc,
         price: place.dataValues.price,
         informer: place.dataValues.User.dataValues.name
       },':kissing_smiling_eyes:')
     );
   }
 });
Exemplo n.º 2
0
 user.createLog().then(function(log) {
   users[data.user].place.addLog(log);
   if (users[data.user].rating) {
     user.createRating({
       rating: users[data.user].rating
     }).then(function(rating) {
       users[data.user].place.addRating(rating);
       bot.postTo(
         receiver,
         '식사기록이 등록됐어!',
         attachments.log({
           placeName: users[data.user].place.dataValues.name,
           createdAt: log.createdAt,
           rating: users[data.user].rating
         }, ':grinning:')
       );
     })
   } else {
     bot.postTo(
       receiver,
       '식사기록이 등록됐어!',
       attachments.log({
         placeName: users[data.user].place.dataValues.name,
         createdAt: log.createdAt,
       }, ':grinning:')
     );
   }
 });
Exemplo n.º 3
0
function count(i, upper, channel) {
  bot.postTo(channel, '' + i, BOT_STATS);

  if (i + 1 <= upper) {

    setTimeout(function () {
      count(i + 1, upper, channel);
    }, 2000);
  }
}
Exemplo n.º 4
0
 }).then(function (place) {
   if (place) {
     users[data.user].state = 'none';
     bot.postTo(
       receiver,
       '이미 등록된 정보가 있어서 취소됐어.',
       attachments.place({
         name: place.dataValues.name,
         desc: place.dataValues.desc,
         price: place.dataValues.price,
         informer: place.dataValues.User.dataValues.name
       })
     );
   } else {
     users[data.user].place = {};
     users[data.user].place.name = placeName
     users[data.user].state = 'registPlace2';
     bot.postTo(receiver, `${placeName}이구나! 이번엔 그 가게 메뉴랑 설명을 부탁할게, 너무 길게 하면 안돼!`, { icon_emoji: ':laughing:' });
   }
 });
Exemplo n.º 5
0
 }).then(function(place) {
   bot.postTo(
     receiver,
     '오늘은 여기 어때?',
     attachments.place({
       name: place.dataValues.name,
       desc: place.dataValues.desc,
       price: place.dataValues.price,
       informer: place.dataValues.User.dataValues.name
     }, ':chorongchorong:')
   );
 });
Exemplo n.º 6
0
 .then(function(place) {
   users[data.user].state = 'none';
   users[data.user].place = {};
   bot.postTo(
     receiver,
     '고마워, 가게가 등록됐어!',
     attachments.place({
       name: place.dataValues.name,
       desc: place.dataValues.desc,
       price: place.dataValues.price,
       informer: users[data.user].name
     }, ':stuck_out_tongue_winking_eye:')
   );
 });
Exemplo n.º 7
0
  /**
   * Post a message in the slack general chat
   *
   * @param {String} message
   * @param {String} fallback
   * @param {successColor|failColor|infoColor} color of the vertical line before the message default infoColor yellow
   * @param {Array} fields is an Array of messages  { 'title': 'Project', 'value': 'Awesome Project','short': true},
   * @param {String} title title message,
   * @param {String} titleLink link message
   * @param {String} nameChannelOrUser where posts a message  channel | group | user by name,
   */
  postSlackMessage(message, fallback, color, fields, title, titleLink, nameChannelOrUser) {
    var params = {
      as_user: true,
      attachments: [
        {
          'fallback': fallback,
          'color': color || this.infoColor,
          'title': title ? title : 'ngostic',
          'title_link': titleLink,
          'text': message,
          'fields': fields,
          'mrkdwn_in': ['text', 'pretext']
        }
      ]
    };

    this.bot.postTo(nameChannelOrUser, '', params);
  }
Exemplo n.º 8
0
 }).then(function (place) {
   if (place) {
     db.Rating.findOne({
       where: {
         UserSlackId: data.user,
         PlaceId: place.dataValues.id
       }
     }).then(function(rating) {
       if (rating) {
         users[data.user].state = 'record3';
         users[data.user].place = place;
         bot.postTo(
           receiver,
           placeName + '에 다녀왔구나! 이대로 입력할까?\n입력하려면 `응` 혹은 `맞아`라고 대답해줘. 취소하려면 `취소`라고 입력해줘.',
           attachments.place({
             name: place.dataValues.name,
             desc: place.dataValues.desc,
             price: place.dataValues.price,
             informer: place.dataValues.User.dataValues.name
           },':kissing_smiling_eyes:')
         );
       } else {
         users[data.user].state = 'record2';
         users[data.user].place = place;
         bot.postTo(
           receiver,
           `${placeName}에 다녀왔구나! 오늘의 평점을 1점에서 10점 사이로 숫자만 입력해줘.`,
           attachments.place({
             name: place.dataValues.name,
             desc: place.dataValues.desc,
             price: place.dataValues.price,
             informer: place.dataValues.User.dataValues.name
           },':kissing_smiling_eyes:')
         );
       }
     });
   } else {
     bot.postTo(receiver, '앗! 등록되지 않은 가게야. 다시 입력해봐!', { icon_emoji: ':confused:' });
   }
 });
Exemplo n.º 9
0
bot.on('message', function(data) {
  let receiver = '';

  if (data.channel && channels[data.channel]) receiver = channels[data.channel].name;
  else if (data.user && users[data.user]) receiver = users[data.user].name;
  else return;

  if (u.isBobMentioned(bot, data) || u.isBobChannel(bot, data) && data.text) {
    let args = u.parseUserMessage(bot, data.text);

    if (args[0] === '안녕') {
      bot.postTo(receiver, '안녕! 나는 로앤컴퍼니의 점심 메뉴 선택을 책임지기 위해서 태어난 밥이야!\n뭘 할 수 있는지 궁금하면 `@밥 명령`을 입력해봐!', { icon_emoji: ':grin:' });
    } else if (args[0] === '명령') {
      bot.postTo(receiver, '내가 뭘 도와줄까?', attachments.commands);
    } else if (args[0] === '등록') {
      if (u.isBobChannel(bot, data)) {
        bot.postTo(receiver, '우와! 가게를 등록할거야? 가게 이름을 말해줘.\n하다가 잘못 입력하면 `취소`라고 해줘!', { icon_emoji: ':blushblush:' });
        users[data.user].state = 'registPlace1';
        return;
      } else {
        bot.postTo(receiver, '`등록`은 DM으로 부탁해!', { icon_emoji: ':sweat_smile:' });
      }
      return;
    } else if (args[0] === '추천') {
      db.Place.findOne({
        order: [ db.Sequelize.fn('RAND') ],
        include: { model: db.User }
      }).then(function(place) {
        bot.postTo(
          receiver,
          '오늘은 여기 어때?',
          attachments.place({
            name: place.dataValues.name,
            desc: place.dataValues.desc,
            price: place.dataValues.price,
            informer: place.dataValues.User.dataValues.name
          }, ':chorongchorong:')
        );
      });
    } else if (args[0] === '가게') {
      db.Place.findAll({
        include: { model: db.User }
      }).then(function(places) {
        bot.postTo(receiver, '가게 목록이야.', attachments.places(places));
      });
    } else if (args[0] === '기록') {
      if (u.isBobChannel(bot, data)) {
        bot.postTo(receiver, '식사 기록을 남기면 추천이 정확해 질거야! 가게 이름이 뭐야?\n잘못 입력했으면 `취소`라고 해줘!', { icon_emoji: ':kissing:' });
        users[data.user].state = 'record1';
        return;
      } else {
        bot.postTo(receiver, '`기록`은 DM으로 부탁해!', { icon_emoji: ':sweat_smile:' });
      }
    } else if (args[0] === '로그') {
      db.Log.findAll({
        where: { UserSlackId: data.user },
        include: { model: db.Place }
      }).then(function(logs) {
        bot.postTo(receiver, '지금까지 갔던 곳들이야.', attachments.logs(logs));
      });
    } else if (args[0] === '뭐야') {
      bot.postTo(
        receiver,
        `>>> *밥* v0.1.1
https://github.com/HyunSeob/bob
Copyright (c) 2016, HyunSeob. Licensed under the MIT license.
_맛있는 점심 드세요!_
        `, { icon_emoji: ':grin:' }
      );
    } else if (args[0] === '투표') {
      args[1] = parseInt(args[1]);
      if (args[1] && (args[1] > 5 || args[1] < 2) ) {
        bot.postTo(receiver, '이상한 숫자 입력하지마..', { icon_emoji: ':confounded:' });
        return;
      }
      db.Place.findAll({
        limit: args[1] || 3,
        order: [ db.Sequelize.fn('RAND') ],
        include: { model: db.User }
      }).then(function(places) {
        bot.postTo(receiver, '가고 싶은 곳 번호로 Add Reaction!', attachments.poll(places));
      });
    } else if (args[0] === '취소') {
      cancelAllState(bot, users[data.user], receiver);
    }
  }

  // Only for specific state
  if (data.text) {
    if (users[data.user].state === 'registPlace1') {
      let placeName = data.text;
      db.Place.findOne({
        where: { name: placeName },
        include: { model: db.User }
      }).then(function (place) {
        if (place) {
          users[data.user].state = 'none';
          bot.postTo(
            receiver,
            '이미 등록된 정보가 있어서 취소됐어.',
            attachments.place({
              name: place.dataValues.name,
              desc: place.dataValues.desc,
              price: place.dataValues.price,
              informer: place.dataValues.User.dataValues.name
            })
          );
        } else {
          users[data.user].place = {};
          users[data.user].place.name = placeName
          users[data.user].state = 'registPlace2';
          bot.postTo(receiver, `${placeName}이구나! 이번엔 그 가게 메뉴랑 설명을 부탁할게, 너무 길게 하면 안돼!`, { icon_emoji: ':laughing:' });
        }
      });
    } else if (users[data.user].state === 'registPlace2') {
      users[data.user].place.desc = data.text;
      users[data.user].state = 'registPlace3';
      bot.postTo(receiver, '마지막으로 가격대가 얼마정도야? 숫자만 입력해줘. 에러가 날지도 몰라.', { icon_emoji: ':sunglasses:' });
    } else if (users[data.user].state === 'registPlace3') {
      let args = u.parseUserMessage(bot, data.text);
      users[data.user].place.price = args[0];
      users[data.user].state = 'registPlace4';
      bot.postTo(
        receiver,
        '아래의 정보가 맞아? 맞으면 `응` 혹은 `맞아`라고 대답해줘! 정보가 틀리면 `취소`라고 대답해줘!',
        attachments.place({
          name: users[data.user].place.name,
          desc: users[data.user].place.desc,
          price: users[data.user].place.price,
          informer: users[data.user].name
        })
      );
    } else if (users[data.user].state === 'registPlace4') {
      let args = u.parseUserMessage(bot, data.text);
      if (args[0] === '응' || args[0] === '맞아') {
        db.User.findOne({
          where: { slack_id: data.user }
        }).then(function(user) {
          user
          .createPlace(users[data.user].place)
          .then(function(place) {
            users[data.user].state = 'none';
            users[data.user].place = {};
            bot.postTo(
              receiver,
              '고마워, 가게가 등록됐어!',
              attachments.place({
                name: place.dataValues.name,
                desc: place.dataValues.desc,
                price: place.dataValues.price,
                informer: users[data.user].name
              }, ':stuck_out_tongue_winking_eye:')
            );
          });
        });
      } else if (args[0] === '취소') {
        cancelAllState(bot, users[data.user], receiver);
      }
    } else if (users[data.user].state === 'record1') {
      let placeName = data.text;
      db.Place.findOne({
        where: { name: placeName },
        include: { model: db.User }
      }).then(function (place) {
        if (place) {
          db.Rating.findOne({
            where: {
              UserSlackId: data.user,
              PlaceId: place.dataValues.id
            }
          }).then(function(rating) {
            if (rating) {
              users[data.user].state = 'record3';
              users[data.user].place = place;
              bot.postTo(
                receiver,
                placeName + '에 다녀왔구나! 이대로 입력할까?\n입력하려면 `응` 혹은 `맞아`라고 대답해줘. 취소하려면 `취소`라고 입력해줘.',
                attachments.place({
                  name: place.dataValues.name,
                  desc: place.dataValues.desc,
                  price: place.dataValues.price,
                  informer: place.dataValues.User.dataValues.name
                },':kissing_smiling_eyes:')
              );
            } else {
              users[data.user].state = 'record2';
              users[data.user].place = place;
              bot.postTo(
                receiver,
                `${placeName}에 다녀왔구나! 오늘의 평점을 1점에서 10점 사이로 숫자만 입력해줘.`,
                attachments.place({
                  name: place.dataValues.name,
                  desc: place.dataValues.desc,
                  price: place.dataValues.price,
                  informer: place.dataValues.User.dataValues.name
                },':kissing_smiling_eyes:')
              );
            }
          });
        } else {
          bot.postTo(receiver, '앗! 등록되지 않은 가게야. 다시 입력해봐!', { icon_emoji: ':confused:' });
        }
      });
    } else if (users[data.user].state === 'record2') {
      let args = u.parseUserMessage(bot, data.text);
      let rating = parseInt(args[0]);
      if (rating > 10 || rating < 1) bot.postTo(receiver, '점수를 잘 못 입력했어. 다시 입력해볼래?', { icon_emoji: ':anguished:' });
      else {
        users[data.user].rating = rating;
        users[data.user].state = 'record3';
        bot.postTo(
          receiver,
          '아래의 정보가 맞아? 맞으면 `응` 혹은 `맞아`라고 대답해줘!\n정보가 틀리면 `취소`라고 대답해줘!',
          attachments.log({
            placeName: users[data.user].place.dataValues.name,
            rating: rating
          })
        );
      }
    } else if (users[data.user].state === 'record3') {
      let args = u.parseUserMessage(bot, data.text);
      if (args[0] === '응' || args[0] === '맞아') {
        db.User.findOne({
          where: { slack_id: data.user }
        }).then(function(user) {
          user.createLog().then(function(log) {
            users[data.user].place.addLog(log);
            if (users[data.user].rating) {
              user.createRating({
                rating: users[data.user].rating
              }).then(function(rating) {
                users[data.user].place.addRating(rating);
                bot.postTo(
                  receiver,
                  '식사기록이 등록됐어!',
                  attachments.log({
                    placeName: users[data.user].place.dataValues.name,
                    createdAt: log.createdAt,
                    rating: users[data.user].rating
                  }, ':grinning:')
                );
              })
            } else {
              bot.postTo(
                receiver,
                '식사기록이 등록됐어!',
                attachments.log({
                  placeName: users[data.user].place.dataValues.name,
                  createdAt: log.createdAt,
                }, ':grinning:')
              );
            }
          });
        });
      } else if (args[0] === '취소') {
        cancelAllState(bot, users[data.user], receiver);
      }
    }
  }
});
Exemplo n.º 10
0
 }).then(function(places) {
   bot.postTo(receiver, '가고 싶은 곳 번호로 Add Reaction!', attachments.poll(places));
 });
Exemplo n.º 11
0
 }).then(function(logs) {
   bot.postTo(receiver, '지금까지 갔던 곳들이야.', attachments.logs(logs));
 });
Exemplo n.º 12
0
 }).then(function(places) {
   bot.postTo(receiver, '가게 목록이야.', attachments.places(places));
 });
Exemplo n.º 13
0
function say(phrase) {
  return bot.postTo(CHANNEL, phrase, BOT_STATS);
}
Exemplo n.º 14
0
function sayBye() {
  return bot.postTo(CHANNEL, choose(BYE_PHRASES), BOT_STATS);
}
Exemplo n.º 15
0
function sayGreetings() {
  return bot.postTo(CHANNEL, choose(GREETINGS_PHRASES), BOT_STATS);
}