質問編集履歴

1

コードの可読性を上げるため不必要な箇所を削除

2017/10/03 07:11

投稿

cat_web
cat_web

スコア14

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- javascriptコード
11
+ node該当コード
12
12
 
13
13
 
14
14
 
@@ -200,246 +200,6 @@
200
200
 
201
201
  };
202
202
 
203
-
204
-
205
- /*
206
-
207
- ====================
208
-
209
- ■ Weather(開発中)
210
-
211
- ====================
212
-
213
- */
214
-
215
- function Weather(object) {
216
-
217
- //class
218
-
219
- this.originalDate = object.originalDate;
220
-
221
- this.weather = object.weather;
222
-
223
- this.slack = object.slack;
224
-
225
- }
226
-
227
- Weather.prototype.getWeather = function(robot, id) { //getWeather
228
-
229
- var self = this;
230
-
231
- robot.hear(/(.*)の天気教えて/i, function(msg) {
232
-
233
- var request = msg.http("http://weather.livedoor.com/forecast/webservice/json/v1?city=270000").get();
234
-
235
- request(function(err, res, body) {
236
-
237
- var json = JSON.parse(body);
238
-
239
- switch(msg.match[1]) {
240
-
241
- case "今日":
242
-
243
- robot.messageRoom(self.slack.room, "♪(σ´ω`)σ\tyo!!\n" + json.pinpointLocations.forecasts[0].dateLabel + "の" + json.title + "は" + json.pinpointLocations.forecasts[0].telop + "だ\tyo!!");
244
-
245
- break;
246
-
247
- case "明日":
248
-
249
- robot.messageRoom(self.slack.room, "♪(σ´ω`)σ\tyo!!\n" + json.pinpointLocations.forecasts[1].dateLabel + "の" + json.title + "は" + json.pinpointLocations.forecasts[1].telop + "だ\tyo!!");
250
-
251
- break;
252
-
253
- case "明後日":
254
-
255
- robot.messageRoom(self.slack.room, "♪(σ´ω`)σ\tyo!!\n" + json.pinpointLocations.forecasts[2].dateLabel + "の" + json.title + "は" + json.pinpointLocations.forecasts[2].telop + "だ\tyo!!");
256
-
257
- break;
258
-
259
- default:
260
-
261
- robot.messageRoom(self.slack.room, "♪(σ´ω`)σ\tyo!!\n正しく入力されてない\tyo!!\n「***の天気教えて」って聞く\tyo!!");
262
-
263
- break;
264
-
265
- }
266
-
267
- console.log(json);
268
-
269
- });
270
-
271
- });
272
-
273
- };
274
-
275
-
276
-
277
- /*
278
-
279
- ====================
280
-
281
- ■ Slack
282
-
283
- ====================
284
-
285
- */
286
-
287
- function Slack(object) {
288
-
289
- //class
290
-
291
- this.originalDate = object.originalDate;
292
-
293
- //property
294
-
295
- this.room = "111111";
296
-
297
- }
298
-
299
-
300
-
301
- /*
302
-
303
- ====================
304
-
305
- ■ OriginalDate
306
-
307
- ====================
308
-
309
- */
310
-
311
- function OriginalDate() {
312
-
313
- //property
314
-
315
- this.week = ["日", "月", "火", "水", "木", "金", "土"];
316
-
317
- this.dateObject = new Date();
318
-
319
- this.year = this.dateObject.getFullYear();
320
-
321
- this.month = this.dateObject.getMonth() + 1;
322
-
323
- this.date = this.dateObject.getDate();
324
-
325
- this.day = this.week[this.dateObject.getDay()];
326
-
327
- this.hour = this.dateObject.getHours();
328
-
329
- this.minute = this.dateObject.getMinutes();
330
-
331
- this.second = this.dateObject.getSeconds();
332
-
333
- }
334
-
335
- OriginalDate.prototype.getDate_All = function() { //getDate_All
336
-
337
- this.dateObject = new Date();
338
-
339
- return this.month + "月" + this.date + "日" + this.day + "曜日";
340
-
341
- };
342
-
343
- OriginalDate.prototype.getTime_All = function() { //getTime_All
344
-
345
- this.dateObject = new Date();
346
-
347
- return this.hour + "時" + this.minute + "分" + this.second + "秒";
348
-
349
- };
350
-
351
-
352
-
353
-
354
-
355
- /*
356
-
357
- ====================
358
-
359
- ■ Hubot
360
-
361
- ====================
362
-
363
- */
364
-
365
- function Hubot() {
366
-
367
- //class
368
-
369
- this.originalDate = null;
370
-
371
- this.slack = null;
372
-
373
- this.weather = null;
374
-
375
- this.httpServer = null;
376
-
377
- this.bot = null;
378
-
379
- //method
380
-
381
- this.init();
382
-
383
- }
384
-
385
- Hubot.prototype.init = function() { //init
386
-
387
- //originalDate
388
-
389
- this.originalDate = new OriginalDate();
390
-
391
- //slack
392
-
393
- this.slack = new Slack({
394
-
395
- originalDate: this.originalDate,
396
-
397
- });
398
-
399
- //weather
400
-
401
- this.weather = new Weather({
402
-
403
- originalDate: this.originalDate,
404
-
405
- slack: this.slack
406
-
407
- });
408
-
409
- //httpSrver
410
-
411
- this.httpServer = new HttpServer({
412
-
413
- originalDate: this.originalDate,
414
-
415
- slack: this.slack,
416
-
417
- weather: this.weather
418
-
419
- });
420
-
421
- //bot
422
-
423
- this.bot = new Bot({
424
-
425
- originalDate: this.originalDate,
426
-
427
- slack: this.slack,
428
-
429
- weather: this.weather,
430
-
431
- httpServer: this.httpServer
432
-
433
- });
434
-
435
- };
436
-
437
- //instances
438
-
439
- var hubot = new Hubot();
440
-
441
- })();
442
-
443
203
  ```
444
204
 
445
205