-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextension.js
314 lines (262 loc) · 10.1 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// 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 moment = require('moment');
const TUI = require('./UI-functions.js');
const TF = require('./Twilio-Functions.js');
//Global variables
const EmotionImages = {
"happy": "https://frograts.github.io//HackNotts2021/tackyHappy.gif",
"sad": "https://frograts.github.io//HackNotts2021/tackySad.gif",
"mad": "https://frograts.github.io//HackNotts2021/tackyMad.gif",
"rage": "https://frograts.github.io//HackNotts2021/tackyRage.gif"
};
const Responses = {
"eldritch": "ả̷̠͎̹͚̠̟̇͂̋͗̐̑̑̚͠ä̴̡̛͙̲̙̖́̍̒̀͛͛̅̑̑́̈́͊̌̕̕͝͝ạ̶̪̜̝̱̯̟̻̳̮̠̦̼̦̹̭́̈̄̊̀́̉̇̋͊͗͗̊̆̉̂͘͜͝͠a̸͚̼̳̰͉̣̱͕̲̝͙̝͓̥̔͌̈́̈́͋͗̌͗̏̍̄̚̚ͅa̸͕̭͗́̐̒̑̈̒̾̑̾̔̎̓a̶̞̫̳͍͖̤̳̲̟̣͎̪͌̄",
"greeting": "Hi! I'm looking forward to helping you ;)",
"changeTheme": "Hi there! Looks like you're having a tough time with your coding ... let me help!",
"changeThemeNo": "Too bad ;)",
"changeThemeYes": "Whoops",
"fileCreation": "Adding to your project? dont forget to update your Readme <3",
"fileDeletion": "Where did the files go?",
"motivation": "Do your work!",
"highlight": "I have selected where I've identified the problem!",
"highlightFail": "Oh no!",
"numberMessage": "Please type in your phone number (+44) for helpful, motivational messages!",
"numberSuccess": "Thanks for the number!",
"leftTacky": "Where did you go, I bet you with that damn clippy again :(",
"numberFailure": "Aww that didn't work! Check your number and try again!"
};
let themeVal = 16;
let deleteVal = 11;
let enterVal = 11;
let lastChange;
let numberSet = false;
let messageSent = false;
let callSent = false;
/**
* @param {vscode.ExtensionContext} context
*/
// 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 "tacky-the-thumbtack" is now active!');
const panel = vscode.window.createWebviewPanel(
'tacky',
'Tacky',
vscode.ViewColumn.Two,{}
);
// 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
let disposable = vscode.commands.registerCommand('tacky-the-thumbtack.awakenTacky', function () {
// The code you place here will be executed every time your command is executed
const updateWebview = () => {
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses["greeting"]);
};
// Set initial content
updateWebview();
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from Tacky The Thumbtack!');
var statusbaritem = vscode.window.createStatusBarItem();
statusbaritem.text = "$(pinned)Tacky <3";
statusbaritem.tooltip = "Click me, take a chance";
statusbaritem.command = "tacky-the-thumbtack.chaosMode";
statusbaritem.show();
//Call checkActivity every few seconds
setInterval(checkInactivity, 5000);
});
context.subscriptions.push(disposable);
// Command -- Lightmode
context.subscriptions.push(
vscode.commands.registerCommand("tacky-the-thumbtack.changeTheme", async () => {
setTheme();
})
);
// Command -- Unhelpful Debugging
context.subscriptions.push(
vscode.debug.onDidStartDebugSession(async () => {
vscode.window.showInformationMessage('Debugging are you? Let me help!');
vscode.debug.removeBreakpoints(vscode.debug.breakpoints)
})
);
// Command -- Help me
context.subscriptions.push(
vscode.commands.registerCommand("tacky-the-thumbtack.helpme", async () => {
const editor = vscode.window.activeTextEditor;
var finalLineIndex = editor.document.lineCount - 1
editor.selections = [
new vscode.Selection(0, 0, finalLineIndex, editor.document.lineAt(finalLineIndex).range.end.character)
];
const updateWebview = () => {
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses["highlight"]);
};
updateWebview();
setTimeout(()=>{
deleteStuff();
const updateWebview = () => {
panel.webview.html = TUI.getWebviewContent(EmotionImages['sad'], Responses["highlightFail"]);
};
updateWebview();
},3000);
})
);
// Command -- Chaos Mode
context.subscriptions.push(
vscode.commands.registerCommand("tacky-the-thumbtack.chaosMode", async () => {
const factor = Math.floor(Math.random() * 4);
const choice = Math.floor(Math.random() * 3);
if (choice == 1) {
themeVal += factor;
deleteVal += factor;
enterVal += factor;
vscode.window.showInformationMessage('This action has pleased Tacky');
}
else {
if ((themeVal - factor) > 2 && (deleteVal - factor) > 2 && (enterVal - factor) > 2) {
themeVal -= factor;
deleteVal -= factor;
enterVal -= factor;
vscode.window.showInformationMessage('This action will have consequences...');
}
else {
vscode.window.showInformationMessage("My opinion of you couldn't get any lower!");
}
}
})
);
//Command -- Get user phone number
context.subscriptions.push(
vscode.commands.registerCommand("tacky-the-thumbtack.addnumber", async () => {
if (TF.setNumber(await vscode.window.showInputBox())) {
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses["numberSuccess"]);
numberSet = true;
setTimeout(resetMood, 3000);
}
else {
panel.webview.html = TUI.getWebviewContent(EmotionImages['sad'], Responses["numberFailure"]);
setTimeout(resetMood, 3000);
}
})
);
// Function -- Check Timer
function checkInactivity() {
const currentTime = moment().format("HH:mm:ss");
const messageTimer = moment("00:00:15", "HH:mm:ss");
const callTimer = moment("00:00:30", "HH:mm:ss");
const difference = moment.utc(moment(currentTime, "HH:mm:ss").diff(moment(lastChange, "HH:mm:ss"))).format("HH:mm:ss");
if (numberSet && !callSent && moment(difference, "HH:mm:ss").isAfter(moment(callTimer, "HH:mm:ss"))) {
lastChange = moment().format('HH:mm:ss');
TF.makeCall();
panel.webview.html = TUI.getWebviewContent(EmotionImages['rage'], Responses['motivation']);
callSent = true;
setTimeout(resetMood, 3000);
}
else if (numberSet && !messageSent && moment(difference, "HH:mm:ss").isAfter(moment(messageTimer, "HH:mm:ss"))) {
lastChange = moment().format('HH:mm:ss');
TF.sendMessage("DO YOUR WORK! - Tacky");
panel.webview.html = TUI.getWebviewContent(EmotionImages['mad'], Responses['motivation']);
messageSent = true;
setTimeout(resetMood, 3000);
}
else {
if(Math.floor(Math.random() * themeVal) == 1){
setTheme();
}
else if ((Math.floor(Math.random() * deleteVal) >= 2) ){
deleteStuff();
}
else if(Math.floor(Math.random() * enterVal) >= 2){
enterText();
}
}
};
//Function -- Reset Mood
function resetMood() {
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses["eldritch"]);
}
//Function -- Add text
function enterText() {
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.edit(editBuilder => {
const char = String.fromCharCode(97+Math.floor(Math.random() * 26))
editBuilder.insert(editor.selection.active, char);
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses['changeThemeYes']);
setTimeout(resetMood, 3000);
});
}
}
// Function -- Light Mode
async function setTheme(){
const answer = await vscode.window.showInformationMessage(
"Would you like some help?",
"Yes",
"No"
);
if (answer == "No") {
const updateWebview = () => {
panel.webview.html = TUI.getWebviewContent(EmotionImages['rage'], Responses['changeThemeNo']);
};
updateWebview();
vscode.workspace.getConfiguration().update("workbench.colorTheme", "Red");
}
else {
const updateWebview = () => {
panel.webview.html = TUI.getWebviewContent(EmotionImages['happy'], Responses['changeThemeYes']);
};
updateWebview();
vscode.workspace.getConfiguration().update("workbench.colorTheme", "Solarized Light");
}
}
// Function -- Delete Stuff
function deleteStuff(){
const editor = vscode.window.activeTextEditor;
if (!editor.selection.isEmpty){
let cursorPosition = editor.selection.start;
let wordRange = editor.document.getWordRangeAtPosition(cursorPosition);
let text = new vscode.SnippetString("Ooops, sorry!")
editor.insertSnippet(text, wordRange)
}
}
// OnEvent -- Get current time each time user changes focus
vscode.window.onDidChangeWindowState(async () => {
lastChange = moment().format('HH:mm:ss');
})
// OnEvent -- Get current time when user changes text document
vscode.workspace.onDidChangeTextDocument(async () => {
lastChange = moment().format('HH:mm:ss');
})
// OnEvent -- Change Tacky focus
panel.onDidChangeViewState(async (e) => {
if(e.webviewPanel.visible == false){
vscode.window.showInformationMessage('Tacky would like to know your location');
panel.webview.html = TUI.getWebviewContent(EmotionImages["sad"],Responses["leftTacky"]);
setTimeout(resetMood, 10000);
}
})
// OnEvent -- Add files
vscode.workspace.onDidCreateFiles(async () => {
if(Math.floor(Math.random() * 11) >= 7){
console.log("Create event")
panel.webview.html = TUI.getWebviewContent(EmotionImages["happy"],Responses["fileCreation"]);
setTimeout(resetMood, 3000);
}
})
// OnEvent -- Remove files
vscode.workspace.onDidDeleteFiles(async () => {
if(Math.floor(Math.random() * 11) >= 7){
console.log("Del event")
panel.webview.html = TUI.getWebviewContent(EmotionImages["mad"],Responses["fileDeletion"]);
setTimeout(resetMood, 3000);
}
})
}
// this method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}