-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
174 lines (158 loc) · 6.16 KB
/
bot.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
console.log('the bot is starting!');
var Twit = require('twit');
var config = require('./config');
var fs = require('fs');
var T = new Twit(config);
var stream = T.stream('user');
var exec = require('child_process').exec;
//======When I want the Bot to reply=======================
stream.on('tweet', tweetEvent);
function tweetEvent(eventMsg) {
var replyto = eventMsg.in_reply_to_screen_name;
var text = eventMsg.text;
var from = eventMsg.user.screen_name;
if (replyto === 'JS_Is_Life') {
var newT = '@' + from + '! Thanks for Tweeting at me! #JS_Is_Life';
tweetReply(newT);
}
function tweetReply(txt) {
var tweet = {
status: txt
};
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log('Something went wrong');
} else {
console.log('It worked!');
}
}
}
}
//======When I want the Bot to reply ends==================
//======When someone follows my account====================
stream.on('follow', followed);
function followed(eventMsg) {
var name = eventMsg.source.name;
var screenName = eventMsg.source.screen_name;
tweetFollow('.@' + screenName + ' kudos! #JSIsLife');
}
function tweetFollow(txt) {
var tweet = {
status: txt
};
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log('Something went wrong');
} else {
console.log('It worked!');
}
}
}
//======When someone follows my account ends===============
//======When I want to post an image using Processing======
function tweetImage() {
var cmd = 'processing-java --sketch=`pwd`/images --run';
exec(cmd, processing);
function processing() {
var filename = 'images/output.png';
var params = {
encoding: 'base64'
};
var b64content = fs.readFileSync(filename, params);
T.post('media/upload', { media_data: b64content }, uploaded);
function uploaded(err, data, response) {
var id = data.media_id_string;
var tweet = {
status: '#JSIsLife',
media_ids: [id]
};
T.post('statuses/update', tweet, tweeted);
}
function tweeted(err, data, response) {
if (err) {
console.log('Something went wrong');
} else {
console.log('It worked! Image Tweeted!');
}
}
}
}
tweetImage();
//======When I want to post an image using Processing ends======
//======When I want to tweet on javascript stuff================
function tweetIt() {
var jsArray = [
'npm i use Alias for npm install',
'npm install use Install everything in package.json',
'npm install use lodash Install a package',
'npm install --save-dev lodash use Install as devDependency',
'npm install --save-exact lodash use Install with exact',
'npm i sax use NPM package',
'npm i sax@latest use Specify tag latest',
'npm i sax@3.0.0 use Specify version 3.0.0',
'npm i sax@">=1 <2.0" use Specify version range',
'npm i @org/sax use Scoped NPM package',
'npm i user/repo use GitHub',
'npm i user/repo#master use GitHub',
'npm i github:user/repo use GitHub',
'npm i gitlab:user/repo use GitLab',
'npm i /path/to/repo use Absolute path',
'npm i ./archive.tgz use Tarball',
'npm i https: use //site.com/archive.tgz Tarball via HTTP',
'npm update use Update production packages',
'npm update --dev use Update dev packages',
'npm update -g use Update global packages',
'npm update lodash use Update a package',
'a1.concat(a2) use Return new array by joining arrays a1 and a2 together',
'a1.join(separator) use Join all elements of array a1 into a string separated by separator arg',
'a1.slice(start, end) use Extract a section from start to end of array a1 and return a new array',
'a1.indexOf(obj) use Return first index of obj within array a1',
'a1.lastIndexOf(obj) use Return last index of obj within array a1',
'a1.forEach(fn) use Calls function fn for each element in the array a1',
'a1.every(fn) use Return true if every element in array a1 satisfies provided testing function fn',
'a1.some(fn) use Return true if at least one element in array a1 satisfies provided testing function fn',
'a1.filter(fn) use a new array with all elements of array a1 which pass the filtering function fn',
'a1.map(fn) use Create a new array with results of calling function fn on every element in array a1',
'a1.reduce(fn) use Apply a function fn against an accumulator and each value (from left to right) of the array as to reduce it to a single value',
'a1.reduceRight(fn) use Apply a function fn against an accumulator and each value (from right to left) of the array as to reduce it to a single value',
'a1.pop() use Remove and return last element from array a1',
'a1.push(obj) use Add obj to end of array a1 and return new length',
'a1.reverse() use Reverse order of elements of array a1 in place',
'a1.sort() use Sort the elements of array a1 in place',
'a1.splice(start, deleteCount, items) use Change content of array a1 by removing existing elements and/or adding new elements',
'a1.unshift(obj) use Add obj to start of array a1 and return new length',
'Array.isArray(var) use Return true if var is an array',
'a1.length use Return length of array a1',
'a1[0] use Access first element of array a1',
'Variables declared with const keyword cannot be reassigned, while let and var can.'
];
var randomizer = Math.floor(Math.random() * 30);
var tweet = {
status: '#JSIsLife ' + jsArray[randomizer]
};
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log('Something went wrong');
} else {
console.log('It worked!');
}
}
}
//setInterval(tweetIt, 1000 * 30);
//======When I want to tweet on javascript stuff ends===========
// var params = {
// q: 'javascript',
// count: 2
// };
//
// T.get('search/tweets', params, getData);
//
// function getData(err, data, response) {
// var tweets = data.statuses;
// for (var i = 0; i < tweets.length; i++) {
// console.log(tweets[i].text);
// }
// }