-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
169 lines (126 loc) · 4.26 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
// running check //
console.log("hello this is bot.");
var fs = require('fs');
var Colorflex = require('colorflex');
var Scheduler = require('./js/node/_SCHEDULER');
var scheduler = new Scheduler();
var Action = require('./js/node/_ACTIONS');
var action = new Action();
global.color = new Colorflex();
global.sampleRate = 44100;
// ARP Observatory by Luke Twyman | t: @whitevinyluk
// @arpobservatory
// soundcloud.com/arpobservatory
// All actions - tweet/audio/chart generation etc are in 'action' (_ACTIONS.js)
// Actions are initiated via the 'scheduler' (_SCHEDULER.js), which every 48 hours plans out
// what actions the bot will make during that 48 hr window.
//-------------------------------------------------------------------------------------------
// OPERATION MODE
//-------------------------------------------------------------------------------------------
// MODES FOR TESTING //
// (only partially implemented) //
global.modes = {
'running': 0,
'audio': 1,
'audioTweet': 2,
'phase': 3,
'phaseTweet': 4,
'waveform': 5,
'waveformTweet': 6,
'periodic': 7,
'periodicTweet': 8,
'spectrum': 9,
'spectrumTweet': 10,
'starTrail': 11,
'starTrailTweet': 12,
'tweet': 13,
'tweetTweet': 14
};
// SET THE CURRENT OPERATION MODE //
global.opMode = modes.running;
var testTweet = 'tweetWork';
//-------------------------------------------------------------------------------------------
// SETUP CONFIG
//-------------------------------------------------------------------------------------------
function setupConfig() {
var config = {};
var configExists = fs.existsSync('./config.js');
if (configExists) {
console.log('file config');
config = require('./config');
}
else {
console.log('environment config');
config = {
twitter: {
consumer_key: process.env.TW_KEY,
consumer_secret: process.env.TW_SECRET,
access_token: process.env.TW_TOKEN,
access_token_secret: process.env.TW_TOKEN_SECRET,
timeout_ms: 60*1000 // optional HTTP request timeout.
},
soundcloud: {
client_id : process.env.SC_ID,
client_secret : process.env.SC_SECRET,
username : process.env.SC_USER,
password : process.env.SC_PASS
}
}
}
return config;
}
//-------------------------------------------------------------------------------------------
// INIT
//-------------------------------------------------------------------------------------------
// START THE BOT RUNNING //
function init() {
var config = setupConfig();
action.init(config,soundCloudReady);
// IF WE'RE IN A TESTING MODE //
switch(opMode) {
case modes.audio:
action.audio();
break;
case modes.phase:
case modes.phaseTweet:
action.chartPhase();
break;
case modes.waveform:
case modes.waveformTweet:
action.chartWaveform();
break;
case modes.periodic:
case modes.periodicTweet:
action.chartPeriodic();
break;
case modes.spectrum:
case modes.spectrumTweet:
action.chartSpectrum();
break;
case modes.starTrail:
case modes.starTrailTweet:
action.starTrails();
break;
case modes.tweet:
action.print(testTweet);
break;
case modes.tweetTweet:
action.tweet(testTweet);
break;
default:
break;
}
}
init();
//-------------------------------------------------------------------------------------------
// INITIALISED CALLBACK
//-------------------------------------------------------------------------------------------
// NORMAL RUNNING - START THE SCHEDULER //
// callback once SoundCloud has initialised in action.init //
function soundCloudReady() {
if (opMode===modes.audioTweet) {
action.audio();
} else {
scheduler.init();
}
}