-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (60 loc) · 2.36 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
69
70
71
72
73
74
75
console.log('Bot starting');
require('dotenv').config();
const fetch = require('cross-fetch');
const Twit = require('twit');
const twitter = Twit({
consumer_key: process.env.API_KEY,
consumer_secret: process.env.API_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
})
const runProgram = () => {
fetch('https://random-adjectives.herokuapp.com/adjectives?amount=1')
.then(res => res.json())
.then(jsonRes => {
var word = jsonRes[0];
var sentence = 'osu is ' + word;
twitter.post('statuses/update', { status: sentence }, (err, data, response) => {
if (err) {
console.log(err);
} else {
console.log("Sucess tweting: " + data.text);
console.log("Sucess: name changed");
fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`)
.then(res => res.json())
.then(jsonRes => {
if (jsonRes.title === "No Definitions Found") {
console.log('No definitions found for: ' + word);
twitter.post('statuses/update', { status: 'No definitions found for ' + word, in_reply_to_status_id: data.id_str }, (err, data, response) => {
if (err) {
console.log(err);
} else {
console.log("Sucess tweeting - no definitions found");
}
});
}
var definition = jsonRes[0].meanings[0].definitions[0].definition;
var phonetic = jsonRes[0].phonetic;
var partOfSPeech = jsonRes[0].meanings[0].partOfSpeech;
twitter.post('statuses/update', { status: word + ' (' + phonetic + ') - ' + partOfSPeech + '\nDefinition: ' + definition, in_reply_to_status_id: data.id_str }, (err, data, response) => {
if (err) {
console.log(err);
} else {
console.log("Success tweeting defintion");
}}
)})
.catch(err => console.log(err));
}
})
twitter.post('account/update_profile', { name: 'currently osu is - ' + word }, (err, data, response) => {
if (err) {
console.log(err);
} else {
console.log("Sucess: name changed");
}
})
})
.catch(err => console.log(err))
}
runProgram();
setInterval(runProgram, 1000*60*60*4);