-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefundnotes.js
More file actions
141 lines (108 loc) · 4.71 KB
/
refundnotes.js
File metadata and controls
141 lines (108 loc) · 4.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ********* TODO *********
// * Nothing :)
var twit = require('twit'),
fs = require('fs'),
global_config = require('./config'),
logger = require('./logger'),
utils = require('./utils'),
agg_twitter = require('./aggregators/aggregator-twitter'),
url = require("url");
var email = require("emailjs/email");
var Tumblr = require('tumblrwks');
var aggregators = [agg_twitter];
var tumblr = null;
function processInstagramPost(request, response) {
/*if (response.statusCode == 200) {
var keywordList = request.post.map(function (message, index, array) {
return message.object_id;
});
agg_instagram_new.pushNewKeywords(keywordList);
}
response.writeHead(200, "OK", { 'Content-Type': 'text/plain' });
response.end();*/
}
RegExp.escape = function (str) {
var specials = /[.*+?|()\[\]{}\\$^]/g; // .*+?|()[]{}\$^
return str.replace(specials, "\\$&");
}
var pushMessage = function(message) {
var keywords = require('./keywords');
var cleanedMessageText = message.Text
keywords.list.forEach(function (element, index) {
var regex = new RegExp("(" + RegExp.escape(element) + ")", "gi"); // replace case insensitive
cleanedMessageText = cleanedMessageText.replace(regex, '');
});
// extract steam id
var sid = cleanedMessageText.match(/sid(\d*)/g);
if (sid && sid.length > 0 && sid[0].length > 3) {
cleanedMessageText = cleanedMessageText.replace(/sid(\d*)/g, "");
sid = sid[0].substring(3, sid[0].length);
}
var tweetText = cleanedMessageText;
var maxCharsToTweet = 111; // tweet functionality of tumblr only allows 111 characters....
var refundNotesUrl = "http://refundnotes.com";
var refundNotesTweetSuffix = " " + refundNotesUrl;
var caractersToRemove = (tweetText.length + refundNotesTweetSuffix.length) - maxCharsToTweet;
if (caractersToRemove > 0) {
tweetText = tweetText.substring(0, tweetText.length - caractersToRemove - 3) + "...";
}
tweetText += refundNotesTweetSuffix;
// remove media after tweet text creation because to keep the media in the autotweet
var mediaTag = "";
if (message.Media && message.Media.length > 0) {
// if media is available remove the automatically added tweet link
cleanedMessageText = cleanedMessageText.replace(/http.?:\/\/t\.co\/[A-Za-z0-9]*/g, "");
mediaTag = "<img src='" + message.Media + "'>";
}
cleanedMessageText = cleanedMessageText.trim();
var body = "";
if (cleanedMessageText.length > 0) {
body += cleanedMessageText;
}
body += mediaTag;
var source = "<a href='http://twitter.com/" + message.UserName + "' ><img style='vertical-align:middle;margin:0px' src='" + message.UserImageURL + "'> <span style=''>" + message.UserName + "</span></a>";
var addSteamWidget = sid && sid.length > 0;
if (addSteamWidget) {
source += "<iframe src='http://store.steampowered.com/widget/" + sid + "/' style='margin-top:5px;' frameborder=0 width=646 height=190 ></iframe>";
}
tumblr.post('/post', { type: 'quote', quote: body, source: source, tweet: tweetText, state: 'draft' }, function (err, json) {
console.log(json);
/*tumblr.post('/post/delete', { id: json.id }, function (err, json) {
console.log(json);
});*/
});
if (!global_config.debug || true) {
var server = email.server.connect({
user: "refundnotes@hemofektik.de",
password: "{0a8404F9-55B6}",
host: "smtp.hemofektik.de",
tls: true
});
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: message.Text,
from: "#RefundNotes Bot <refundnotes@hemofektik.de>",
to: "drafts@refundnotes.com",
subject: "New RefundNote Draft"
}, function (err, message) { console.log(err || message); });
}
}
var init = function () {
logger.logInfo('[SERVER] Configuration:');
var tmblrOptions = {
consumerKey: global_config.tmblr_consumer_key,
consumerSecret: global_config.tmblr_consumer_secret,
accessToken: global_config.tmblr_access_token,
accessSecret: global_config.tmblr_access_secret,
hostname: global_config.tmblr_hostname
};
tumblr = new Tumblr( tmblrOptions, tmblrOptions.hostname );
// Initialize aggregators
logger.logInfo('[SERVER] Initializing aggregators');
aggregators.forEach(function (agg, index, array) {
logger.logInfo(agg.logName + 'initializing');
agg.init(pushMessage);
});
}
exports.init = init;
exports.processInstagramPost = processInstagramPost;