Guest User

sql new

a guest
Feb 5th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. var builder = require('botbuilder');
  2.  
  3. var connector = new builder.ConsoleConnector().listen();
  4. var bot = new builder.UniversalBot(connector);
  5. var intents = new builder.IntentDialog();
  6.  
  7. var mysql=require('mysql');
  8. var connection= mysql.createConnection({
  9. host :"localhost",//52.172.180.93",//localhost",
  10. user :"root",
  11. password :"Dragneel03"
  12. });
  13.  
  14. connection.connect();
  15. connection.query("use TO_DO_LIST");
  16. var strQuery="select*from USER_ID";
  17.  
  18. connection.query(strQuery, function(err, rows){
  19. console.log("Here");
  20. if(err){
  21. console.log(err);
  22. throw err;
  23. }else{
  24. console.log(rows);
  25. }
  26. });
  27.  
  28. var strQuery1="select*from USER_TASKS";
  29. connection.query(strQuery1, function(err, rows){
  30. console.log("Connected");
  31. if(err){
  32. console.log(err);
  33. throw err;
  34. }else{
  35. console.log(rows);
  36. }
  37. });
  38. connection.end(function(err){
  39. console.log("connected");
  40. });
  41.  
  42. console.log("Here");
  43.  
  44. function details(session) {
  45. this.head = "";
  46. this.t = 0;
  47. this.stop;
  48. this.it = 0;
  49. this.start = function() {
  50. var to = this.t*1000*60*60*24;
  51. var h1 = this.head;
  52. var it1 = this.it;
  53. this.stop = setTimeout(function() {1000*60*60*24
  54. session.send(h1);
  55. i--;
  56. time.splice(it1, 1);
  57. }, to);
  58. }
  59. };
  60. var task;
  61. var time = [];
  62. var i = -1;
  63.  
  64. bot.dialog('/', intents
  65. .matches(/^add task/i, '/add')
  66. .matches(/^show task/i, '/show')
  67. .matches(/^remove task/i, '/remove')
  68. );
  69.  
  70.  
  71. bot.dialog('/show', [
  72. function(session){
  73. builder.Prompts.text(session,'Which days task you want to see?');
  74. },
  75. function(session,results) {
  76. if(results.response=='all'){
  77. if (i > 0) {
  78. session.send('Task yet to be completed are -->')
  79. for (var j = i; j >= 0; j--) {
  80. session.send('%s', time[j].head);
  81. }
  82. } else {
  83. session.send('No task remaining');
  84. }}
  85. else{
  86. var da=results.response;
  87. var today= new Date();
  88. var yr =da.substr(0,4);
  89. var month= da.substr(5,2);
  90. var day=da.substr(8,2);
  91. var y2k = new Date(yr, month-1, day);
  92. var diff=Date.daysBetween(today,y2k);
  93. session.send('Task yet to be completed on %s are -->',da);
  94. for (var j = i; j >= 0; j--) {
  95. if(diff==time[j].t){
  96. session.send('%s', time[j].head);}
  97. }
  98. }
  99. session.send('What do you want to do now? %s!', session.userData.name);
  100. session.endDialog();
  101.  
  102. }
  103. ]);
  104.  
  105.  
  106. bot.dialog('/remove', [
  107. function(session) {
  108. builder.Prompts.text(session, 'Which task have you completed?');
  109. },
  110. function(session, results) {
  111. var rem = results.response;
  112. var index = -1;
  113. for (var j = 0; j <= i; j++) {
  114. if (time[i].head === rem) {
  115. index = i;
  116. break;
  117. }
  118. }
  119. if (index == -1) {
  120. session.send("Task does not exist");
  121. } else {
  122. clearTimeout(time[index].stop);
  123. time.splice(index, 1);
  124. i--;
  125. session.send('Ok... Changed your task has been removed');
  126.  
  127. }
  128. session.endDialog();
  129. session.beginDialog('/remove more');
  130.  
  131. }
  132. ]);
  133.  
  134.  
  135. intents.onDefault([
  136. function(session, args, next) {
  137. if (!session.userData.name) {
  138. session.beginDialog('/profile');
  139. } else {
  140. next();
  141. }
  142. },
  143. function(session, results) {
  144. session.send('What do you want to do now? %s!', session.userData.name);
  145. intents.onDefault(builder.DialogAction.send("I'm sorry. I didn't understand."));
  146. }
  147. ]);
  148.  
  149. bot.dialog('/add', [
  150. function(session) {
  151. builder.Prompts.text(session, 'What do you want to add?');
  152. },
  153. function(session, results) {
  154. i++;
  155.  
  156. task = results.response;
  157. session.send('Ok... Your task has been added %s', task);
  158. builder.Prompts.text(session, 'Tell the due date?');
  159. },
  160. function(session, results) {
  161. time.push(new details(session));
  162. time[i].head = task;
  163. var da=results.response;
  164. var today= new Date();
  165. var yr =da.substr(0,4);
  166. var month= da.substr(5,2);
  167. var day=da.substr(8,2);
  168. var y2k = new Date(yr, month-1, day);
  169. time[i].t =Date.daysBetween(today,y2k);
  170. time[i].it = i;
  171. time[i].start();
  172. session.endDialog();
  173. session.beginDialog('/add more');
  174.  
  175. }
  176. ]);
  177. Date.daysBetween = function( date1, date2 ) {
  178. //Get 1 day in milliseconds
  179. var one_day=1000*60*60*24;
  180.  
  181. // Convert both dates to milliseconds
  182. var date1_ms = date1.getTime();
  183. var date2_ms = date2.getTime();
  184. // Calculate the difference in milliseconds
  185. var difference_ms = date2_ms - date1_ms;
  186.  
  187. // Convert back to days and return
  188. return Math.round(difference_ms/one_day);
  189. }
  190.  
  191.  
  192. bot.dialog('/add more', [
  193. function(session) {
  194. builder.Prompts.text(session, 'Do you want to add anything more ?(yes/no)');
  195. },
  196. function(session, results) {
  197. var res = results.response;
  198. if (res == 'yes') {
  199. session.beginDialog('/add');
  200. } else if (res == 'no') {
  201. session.endDialog();
  202. session.send('What do you want to do now? %s!', session.userData.name);
  203. } else {
  204. session.send("I'm sorry. I didn't understand.");
  205. session.beginDialog('/add more');
  206. }
  207. }
  208. ]);
  209.  
  210.  
  211. bot.dialog('/remove more', [
  212. function(session) {
  213. builder.Prompts.text(session, 'Do you want to remove anything more ?(yes/no)');
  214. },
  215. function(session, results) {
  216. var res = results.response;
  217. if (res == 'yes') {
  218. session.beginDialog('/remove');
  219. } else if (res == 'no') {
  220. session.endDialog();
  221. session.send('What do you want to do now? %s!', session.userData.name);
  222. } else {
  223. session.send("I'm sorry. I didn't understand.");
  224. session.beginDialog('/remove more');
  225. }
  226. }
  227. ]);
  228.  
  229.  
  230. bot.dialog('/profile', [
  231. function(session) {
  232. builder.Prompts.text(session, 'Hi! What is your name?');
  233. },
  234. function(session, results) {
  235. session.userData.name = results.response;
  236. session.endDialog();
  237. }
  238. ]);
Add Comment
Please, Sign In to add comment