Skip to content

Commit ae40040

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 883b2e9 + 844efc8 commit ae40040

7 files changed

Lines changed: 141 additions & 77 deletions

Parsers/App Update Script.js

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@ regex:(!appupdate|!update|!app-update|!bulkupdate|!bulk-update|!plugin|!plugins)
44
flags:gmi
55
*/
66

7+
// NOTE!
8+
// When you update eric_script, you must find/replace \n with \\n and ` with \`
9+
710
const eric_script = `
8-
\`\`\`
911
/*----------------------------------------------------*/
10-
/* */
12+
/* AUTO */
1113
/* Have a bunch of apps that need to be updated? */
1214
/* Run this and follow the directions in the output */
13-
/* It will build a payload and use the CI/CD API to */
14-
/* run a batch install of all of the needed updates. */
15+
/* It will automaticallybuild and run a batch */
16+
/* install of all of the needed updates. */
17+
/* */
18+
/* Latest code always available at */
19+
/* https://snwizard.com/update-apps */
1520
/* */
1621
/*----------------------------------------------------*/
1722
1823
//Want Demo Data with the app?
1924
var loadDemoData = true;
20-
var updateCheck = false; //this can take some time to run and adds a LOT of stuff to the lod making the important bit harder to find
25+
var updateCheck = false; //this can take some time to run and adds a LOT of stuff to the log making the important bit harder to find
2126
22-
if (updateCheck)
23-
new sn_appclient.UpdateChecker().checkAvailableUpdates();
27+
if (updateCheck) new sn_appclient.UpdateChecker().checkAvailableUpdates();
2428
2529
var prevName;
2630
var appsArray = [];
27-
var grSSA = new GlideRecord('sys_store_app');
28-
grSSA.addEncodedQuery('install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY');
29-
grSSA.orderBy('name');
30-
grSSA.orderBy('version');
31+
var grSSA = new GlideRecord("sys_store_app");
32+
grSSA.addEncodedQuery(
33+
"install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY"
34+
);
35+
grSSA.orderBy("name");
36+
grSSA.orderBy("version");
3137
grSSA.query();
3238
while (grSSA.next()) {
33-
var curName = grSSA.getValue('name');
39+
var curName = grSSA.getValue("name");
3440
var latestVersion = updateAvailable(grSSA);
3541
if (curName == prevName) {
3642
continue;
@@ -42,16 +48,17 @@ while (grSSA.next()) {
4248
id: grSSA.getUniqueValue(),
4349
load_demo_data: loadDemoData,
4450
type: "application",
45-
requested_version: grSSA.getValue('latest_version')
51+
requested_version: grSSA.getValue("latest_version"),
4652
};
4753
appsArray.push(appObject);
4854
}
4955
}
56+
5057
function updateAvailable(grSSA) {
51-
var installedVersion = grSSA.getValue('version');
52-
var latestVersion = grSSA.getValue('latest_version');
53-
var installedArray = installedVersion.split('.');
54-
var latestArray = latestVersion.split('.');
58+
var installedVersion = grSSA.getValue("version");
59+
var latestVersion = grSSA.getValue("latest_version");
60+
var installedArray = installedVersion.split(".");
61+
var latestArray = latestVersion.split(".");
5562
var len = Math.max(installedArray.length, latestArray.length);
5663
for (var i = 0; i < len; i++) {
5764
var installed = installedArray[i] ? parseInt(installedArray[i]) : 0;
@@ -65,19 +72,63 @@ function updateAvailable(grSSA) {
6572
return false;
6673
}
6774
if (appsArray.length > 0) {
75+
gs.info("\\n\\n------------------------------------------------\\n\\nLinks to track progress below the payload information\\n\\n(scroll down)\\n\\n-----------------------------------------------\\n\\n");
76+
6877
var appsPackages = {};
6978
appsPackages.packages = appsArray;
70-
appsPackages.name = 'Update Apps';
79+
appsPackages.name = "Update Apps";
7180
var data = new global.JSON().encode(appsPackages);
7281
73-
var url = gs.getProperty('glide.servlet.uri') +'$restapi.do?ns=sn_cicd&service=CICD%20Batch%20Install%20API&version=latest';
74-
gs.info('\\nOpen the following URL in a new tab:\\n\\n' + url + '\\n\\ncopy/paste the following JSON into the "Raw" Request body\\n\\n' + data);
82+
var baseUrl = gs.getProperty("glide.servlet.uri");
83+
var update = new sn_appclient.AppUpgrader().installBatch(data);
84+
var updateObj = JSON.parse(update);
85+
gs.info(
86+
"\\n\\n------------------------------------------------\\n\\nOpen the Batch install link to monitor the installation progress. It may take some time for the apps to all populate in the related list. After all apps have populated the install will start and the State will change to In progress.\\n\\nBatch install:\\n" +
87+
baseUrl +
88+
"nav_to.do?uri=sys_batch_install_plan.do?sys_id=" +
89+
updateObj.batch_installation_id +
90+
"\\n\\nExecution tracker:\\n" +
91+
baseUrl +
92+
"nav_to.do?uri=sys_progress_worker.do?sys_id=" +
93+
updateObj.execution_tracker_id +
94+
"\\n\\n-----------------------------------------------\\n\\n"
95+
);
96+
var grSBIP = new GlideRecord('sys_batch_install_plan');
97+
if (grSBIP.get(updateObj.batch_installation_id)) {
98+
grSBIP.setValue('notes','It may take some time for the apps to all populate in the related list below (you can refresh the list as needed to see them populating). \\n\\nAfter all apps have populated the install will start and the State (above) will change to In progress. \\n\\nWhen the batch is done the state will update to Installed');
99+
grSBIP.update();
100+
}
75101
} else {
76-
gs.info("\\nNo apps to update found.\\nIf you think this is incorrect please try running this script again with \`updateCheck\` set to \`true\`. This will check the store for any new updates.\\n\\n(sometimes there are apps in the Application Manager that say that there are updates but you can't actually update them)");
102+
gs.info(
103+
"\\n\\n-----------------------------------------------\\n\\nAll apps appear to be up-to-date. \\n\\nIf you think this is incorrect please try running this script again with \`updateCheck\` set to \`true\`. This will check the store for any new updates.\\n(sometimes there are apps in the Application Manager that say that there are updates but you can't actually update them)\\n\\n-----------------------------------------------\\n\\n"
104+
);
77105
}
78-
\`\`\`
79106
`;
80107

81-
const message = "<@U6E2TEKQ9> made a cool script for bulk updating apps!\n\n" + eric_script;
82-
108+
// Using block kit because the script is too long for a regular message
109+
const message = {
110+
"blocks": [
111+
{
112+
"type": "section",
113+
"text": {
114+
"type": "mrkdwn",
115+
"text": "<@U6E2TEKQ9> made a cool script for bulk updating apps!\n\n"
116+
}
117+
},
118+
{
119+
"type": "rich_text",
120+
"elements": [
121+
{
122+
"type": "rich_text_preformatted",
123+
"elements": [
124+
{
125+
"type": "text",
126+
"text": eric_script
127+
}
128+
]
129+
}
130+
]
131+
}
132+
]
133+
}
83134
new x_snc_slackerbot.Slacker().send_chat(current, message, true);

Parsers/Check if user is verified.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ user_id = user_id.replace(/>.*/, '').trim();
1212

1313
var grUser = new GlideRecord('x_snc_slackerbot_user');
1414
if(grUser.get('user_id',user_id) && Object.keys(grUser).indexOf('verified') != -1){
15-
verification_status = (grUser.getValue('verified') == 1 ? true : false) ? 'has been verified and confirmed by the Slack admins.' : 'has not been verified and confirmed by the Slack admins.';
15+
verification_status = (grUser.getValue('verified') == 1 ? true : false) ? '*has been verified* and confirmed by the Slack admins.' : '*has not been verified* and confirmed by the Slack admins.';
1616
user_info = grUser.getValue('user_info') !== null ? grUser.getValue('user_info').toString() : '';
1717

1818
message_body += '' + grUser.getValue('name') + '\'s identity '+ verification_status;
19-
if(!gs.nil(user_info)) message_body += '\nThe following information has been noted about this user: ' + user_info;
19+
if(!gs.nil(user_info)) message_body += '\n\nThe following information has been noted about this user:\n\n> ' + user_info;
2020
}
2121
else {
2222
message_body += 'I\'m afraid I can\'t do that. Either the user does not exist, or the logic to support this functionality is not yet on the instance.';

Parsers/Convert Celsius to Fahrenheit.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

Parsers/Convert Fahrenheit to Celsius.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

Parsers/Convert temperatures.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
activation_example:30c or 30 degrees fahrenheit
3+
regex:(?:^|\s)(-?\d{1,3}\.?\d{0,2})°?\s?(?:degrees)?\s?(?:c(?:elsius)?|f(?:ahrenheit)?)\b
4+
flags:gmi
5+
*/
6+
7+
const formatNumber = num => Number(num).toFixed(2).replace(/\.00$/, '');
8+
const conversions = [];
9+
10+
// convert C to F
11+
const celsiusRegex = /(-?\d{1,3}(?:\.\d{1,2})?)°?\s?(?:degrees?)?\s?c(?:elsius)?\b/gi;
12+
const celsiusToFahrenheit = c => ((c * 9 / 5) + 32).toFixed(2);
13+
let cMatch;
14+
while ((cMatch = celsiusRegex.exec(current.text)) !== null) {
15+
const celsius = parseFloat(cMatch);
16+
const fahrenheit = celsiusToFahrenheit(celsius);
17+
conversions.push(`${formatNumber(celsius)}°C is ${formatNumber(fahrenheit)} degrees in freedom units (Fahrenheit).`);
18+
}
19+
20+
// convert F to C
21+
const fahrenheitRegex = /(-?\d{1,3}(?:\.\d{1,2})?)°?\s?(?:degrees?)?\s?f(?:ahrenheit)?\b/gi;
22+
const fahrenheitToCelsius = f => ((f - 32) * 5 / 9).toFixed(2);
23+
let fMatch;
24+
while ((fMatch = fahrenheitRegex.exec(current.text)) !== null) {
25+
const fahrenheit = parseFloat(fMatch);
26+
const celsius = fahrenheitToCelsius(fahrenheit);
27+
conversions.push(`${formatNumber(fahrenheit)}°F is ${formatNumber(celsius)} degrees in sane units (Celsius).`);
28+
}
29+
30+
const conversionMessage = conversions.join('\n');
31+
32+
new x_snc_slackerbot.Slacker().send_chat(current, conversionMessage);

Parsers/NDA.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
activation_example:!nda
3+
regex:(!nda|!confidential)
4+
flags:gmi
5+
*/
6+
7+
//Provides a response to the strings that will cause the `Summarize the thread so far` parser to not produce a summary.
8+
9+
var message = []; //Array of potential messages to respond with
10+
message.push(":zipper_mouth_face:");
11+
message.push(":shushing_face:");
12+
message.push("I got you :fingerguns:");
13+
message.push("Lips are sealed");
14+
message.push(":spill-the-tea:");
15+
message.push(":popcorn2:");
16+
message.push(":speak_no_evil:");
17+
message.push("Request for confidentiality acknowledged. Use of !summary, !catchmeup, and !catchup have been disabled.");
18+
19+
20+
//Select one at random.
21+
var randomIndex = Math.floor(Math.random() * message.length);
22+
23+
new x_snc_slackerbot.Slacker().send_chat(current, message[randomIndex], true);

Parsers/What time is it.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ flags:gmi
55
*/
66

77
var term = /^(?:!time )([^\s]+)/gmi.exec(current.text);
8-
var astrid = /!astrid/.test(current.text)
8+
var astrid = /!astrid/.test(current.text);
99
var tz = "";
1010
var text = "";
1111
var tza = getTimeZoneArray();
1212
var endText = "";
1313

14-
if (astrid) {
14+
if (!tz || !tza || tza.indexOf(tz.toLowerCase()) == -1) {
1515
tz = "Australia/Sydney";
1616
endText = "Astrid time!";
1717
}
@@ -25,26 +25,26 @@ if (!tz || !tza || tza.indexOf(tz.toLowerCase()) == -1) {
2525
new x_snc_slackerbot.Slacker().send_chat(current, text, true);
2626
}
2727
else {
28-
var uri = "https://worldtimeapi.org/api/timezone/"
28+
var uri = "https://timeapi.io/api/time/current/zone?timeZone=";
2929
var rm = new sn_ws.RESTMessageV2();
3030
rm.setEndpoint(uri + tz);
3131
rm.setHttpMethod('get');
3232
response = rm.execute();
3333
rb = JSON.parse(response.getBody());
34-
var timeString = rb.datetime.split('T')[1].split('.')[0];
34+
var timeString = rb.dateTime.split('T')[1].split('.')[0];
3535
var gd = new GlideDate();
36-
gd.setValue(rb.datetime.replace('T',' '));
36+
gd.setValue(rb.dateTime.replace('T',' '));
3737
dateString = gd.getByFormat('EEEE, MMMM dd, yyyy');
38-
endText = !endText ? rb.timezone : endText;
39-
var text = 'It is currently ' + timeString + ' on ' + dateString + ' in ' + endText;
38+
endText = !endText ? rb.timeZone : endText;
39+
text = 'It is currently ' + timeString + ' on ' + dateString + ' in ' + endText;
4040
new x_snc_slackerbot.Slacker().send_chat(current, text, false);
4141
}
4242

4343
function getTimeZoneArray(){
44-
var uri = "https://worldtimeapi.org/api/timezone/"
44+
var uri = "https://timeapi.io/api/timezone/availabletimezones";
4545
var rm = new sn_ws.RESTMessageV2();
4646
rm.setEndpoint(uri);
4747
rm.setHttpMethod('get');
4848
response = rm.execute();
49-
return JSON.parse(response.getBody()).map(function(e){return e.toLowerCase()});
49+
return JSON.parse(response.getBody()).map(function(e){return e.toLowerCase();});
5050
}

0 commit comments

Comments
 (0)