-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
81 lines (72 loc) · 2.94 KB
/
extension.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
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const Twit = require('twit');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate (context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "tinycarecode" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const config = vscode.workspace.getConfiguration('tcc');
let statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
let T;
if (config.consumer_key && config.consumer_secret && config.access_token && config.access_token_secret) {
T = new Twit({
consumer_key: config.consumer_key,
consumer_secret: config.consumer_secret,
access_token: config.access_token,
access_token_secret: config.access_token_secret,
});
statusBar.text = '🤗💖: please take care';
statusBar.show();
} else {
vscode.window.showErrorMessage('tinycarecode: set up the Twitter API keys in your settings and refresh!');
}
let params = {
screen_name: 'tinycarebot',
exclude_replies: true,
include_rts: false,
count: 1
}
let tinyCare = {
getTweet: function () {
return new Promise(function (resolve, reject) {
T.get('statuses/user_timeline', params, function (err, data) {
if (err) {
console.log(err);
reject('⚠️: error getting tweet!');
} else {
resolve(data[0].text);
}
});
});
},
sendAlert: function (status) {
vscode.window.showInformationMessage(status);
},
updateStatusBar: function (status) {
statusBar.text = status;
statusBar.show();
}
}
setInterval(function () {
tinyCare.getTweet().then(function (status) {
tinyCare.sendAlert(status);
tinyCare.updateStatusBar(status);
});
}, config.refresh_after * 60 * 1000);
context.subscriptions.push(config);
context.subscriptions.push(statusBar);
context.subscriptions.push(T);
context.subscriptions.push(params);
context.subscriptions.push(tinyCare);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate () {
}
exports.deactivate = deactivate;