old_contents: var http=require("http");var key="59936cbc7642729f6f519c130c530bdd";var baseUrl="api.uwaterloo.ca";function process(b,c){var a=b.split(" ");switch(a[1]){case"weather":getWeather(function(d){c(d)});break;case"exam":if(a.length==4){getExamSchedule(a[2],a[3],function(d){c(d)})}else{c(returnHelpString())}break;case"help":c("Address bot with <b>@uwbot</b> or <b>@bot</b> (command) (options) <br>         <b>UWBot commands:</b> <br>           <b>weather</b>: get the current weather in waterloo <br>           <b>exam</b> (subject) (course_num): Gets exam info for given subject <br>           <b>disclaimer</b>: Prints a boring disclaimer <br>           <b>help</b>: print this help command <br>");break;case"disclaimer":c("All information from api.uwaterloo.ca, the author provides no guarentees to its correctness.");break;default:c(returnHelpString());break}}function returnHelpString(){return"Unrecognized command, please refer to '@bot help' for accepted command."}function getCurrentTerm(c){var a="/v2/terms/list.json?key="+key;var b;sendReq(a,function(d){b=JSON.parse(d);c(b.data.current_term)})}function getExamSchedule(a,d,f){var c="/v2/courses/"+a+"/"+d+"/examschedule.json?key="+key;var b;var e;sendReq(c,function(g){e=JSON.parse(g);if(typeof e.data.course!=="undefined"){b="Exam Info for "+e.data.course+": <br>";for(section in e.data.sections){b+="Section: "+e.data.section.section+"<br>         Date: "+e.data.section.date+"<br>         Start Time: "+e.data.section.start_time+"<br>         End Time: "+e.data.section.end_time+"<br>         Location: "+e.data.section.location+"<br>         "}}else{b="Cannot get exam information for '"+a+d+"'!"}f(b)})}function getWeather(d){var b="/v2/weather/current.json";var a;var c;sendReq(b,function(e){c=JSON.parse(e);a="The current temperature in Waterloo is: "+c.data.temperature_current_c+" Celsius";d(a)})}function sendReq(b,d){var a={host:baseUrl,port:80,path:b,method:"GET",headers:{"Content-Type":"application/json"}};var c=http.get(a,function(e){var f=[];e.on("data",function(g){f.push(g)}).on("end",function(){var g=Buffer.concat(f);d(g)})});c.on("error",function(f){console.log("ERROR: "+f.message)})}module.exports.process=process;
new_contents: var http=require("http");var key="59936cbc7642729f6f519c130c530bdd";var baseUrl="api.uwaterloo.ca";function process(b,c){var a=b.split(" ");switch(a[1]){case"weather":if(a.length==2){getWeather(function(d){c(d)})}else{c(returnHelpString())}break;case"holiday":if(a.length==2){getNextHoliday(function(d){c(d)})}else{c(returnHelpString())}break;case"exam":if(a.length==4){getExamSchedule(a[2],a[3],function(d){c(d)})}else{c(returnHelpString())}break;case"help":c("Address bot with <b>@uwbot</b> or <b>@bot</b> (command) (options) <br>         <b>UWBot commands:</b> <br>           <b>weather</b>: get the current weather in waterloo <br>           <b>exam</b> (subject) (course_num): Gets exam info for given subject <br>           <b>holiday</b>: Get the date of the next holiday! <br>           <b>disclaimer</b>: Prints a boring disclaimer <br>           <b>help</b>: print this help command <br>");break;case"disclaimer":c("All information from api.uwaterloo.ca, the author provides no guarentees to its correctness.");break;default:c(returnHelpString());break}}function returnHelpString(){return"Unrecognized command, please refer to '@bot help' for accepted command."}function getNextHoliday(b){var a="/v2/events/holidays.json";sendReq(a,function(c){var e;var d=new Date();for(index in c.data){if(new Date(c.data[index].date)>d){e=c.data[index];break}}if(typeof e!=="undefined"){b("The next holiday is "+e.name+" on "+e.date+". Yay!")}else{b("Cannot find the next holiday, maybe there is none... :(")}})}function getCurrentTerm(b){var a="/v2/terms/list.json?key="+key;sendReq(a,function(c){b(c.data.current_term)})}function getExamSchedule(a,d,e){var c="/v2/courses/"+a+"/"+d+"/examschedule.json?key="+key;var b;sendReq(c,function(f){if(typeof f.data.course!=="undefined"){b="Exam Info for "+f.data.course+": <br>";for(section in f.data.sections){b+="Section: "+f.data.section.section+"<br>         Date: "+f.data.section.date+"<br>         Start Time: "+f.data.section.start_time+"<br>         End Time: "+f.data.section.end_time+"<br>         Location: "+f.data.section.location+"<br>         "}}else{b="Cannot get exam information for '"+a+d+"'!"}e(b)})}function getWeather(c){var b="/v2/weather/current.json";var a;sendReq(b,function(d){a="The current temperature in Waterloo is: "+d.data.temperature_current_c+" Celsius";c(a)})}function sendReq(b,d){var a={host:baseUrl,port:80,path:b,method:"GET",headers:{"Content-Type":"application/json"}};var c=http.get(a,function(e){var f=[];e.on("data",function(g){f.push(g)}).on("end",function(){var g=Buffer.concat(f);d(JSON.parse(g))})});c.on("error",function(f){console.log("ERROR: "+f.message)})}module.exports.process=process;
subject: Update bot script