-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (62 loc) · 2.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//SMS-Bot
//written by Caleb Smith
//Requires
const bot = require('fancy-groupme-bot');
const async = require('async');
const request = require('request');
const _ = require('underscore');
const events = require('events');
const util = require('util');
const http = require('http');
const formidable = require('formidable');
const Forecast = require('forecast');
const URL = require('url');
var cities = require('cities');
//fancy-groupme-bot config vars
const TOKEN = "pHRZcCOaax7eJNCNYWrT4OIvtFkzGl41pVOq3cHv"; // your groupme api token
const GROUP = "7264366"; // the room you want to join
const NAME = "node"; // the name of your bot
const URL2 = "http://frozen-waters-9985.herokuapp.com"; // the domain you're serving from, should be accessible by Groupme.
const CONFIG = {
token: TOKEN,
group: GROUP,
name: NAME,
url: URL2
};
//some other useful stuff
var port = Number(process.env.PORT || 5000);
var mybot = bot(CONFIG);
var forecast = new Forecast({
service: 'forecast.io',
key: 'b07f3f4bd55e300af0bec21f71de5fb0',
units: 'fahrenheit', // Only the first letter is parsed
cache: true, // Cache API requests?
ttl: { // How long to cache requests. Uses syntax from moment.js: http://momentjs.com/docs/#/durations/creating/
minutes: 5,
seconds: 45
}
});
//When the groupme bot registers, this is passed to the chat.
mybot.on('botRegistered', function (b) {
console.log("I am registered");
b.message("<bot registers>");
});
//the meaty part
mybot.on('botMessage', function (b, message) {
console.log("I got a message, fyi: " + message.name + " said " + message.text);
if (message.name != b.name && (message.text.search(/^!echo/) != -1)) { //.search provides a -1 if the regex returns nothing
var minusecho = message.text.substring(5); //removing the !echo bit
b.message(message.name + " said " + minusecho);
} else if (message.name != b.name && (message.text.search(/^syn/) != -1)) {
b.message("ACK!"); //sounds like a nasty cough you got there
} else if (message.name != b.name && (message.text.search(/^!w/) != -1)) { //This is going to be a a simple weather info command. thing.
var city = cities.zip_lookup(Number(message.text.substring(3)));
forecast.get([city.latitude, city.longitude], function (err, weather) { //y u no define, variables?
if (weather) {return b.message(weather);}
else {"no weather"}
});
}
});
//startup
console.log("i am serving");
mybot.serve(port);