Skip to content

Commit 131d0ce

Browse files
authored
Update Admin tool - Verify.js
wrapping in iife
1 parent 41a7315 commit 131d0ce

1 file changed

Lines changed: 114 additions & 113 deletions

File tree

Parsers/Admin tool - Verify.js

Lines changed: 114 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,119 +4,120 @@ regex:^!(?:un)?verify-admin\u0020?
44
flags:gi
55
*/
66

7-
if (
8-
current.channel == "GD51HTR46" ||
9-
current.channel == "G9LAJG7G8" ||
10-
current.channel == "G7M4AP6U8"
11-
) {
12-
//admin channels on sndevs
13-
var messageBody = "";
14-
var userId = "";
15-
var description = "";
16-
var verificationStatus = null;
17-
var slacker = new x_snc_slackerbot.Slacker();
18-
19-
// Determine the base command to set default verification status
20-
// If it starts with !unverify, default is false. Otherwise (verify), default is true.
21-
var isUnverifyCommand = current.text.toLowerCase().indexOf("!unverify-admin") === 0;
22-
var defaultVerificationStatus = isUnverifyCommand ? false : true;
23-
24-
// Grab user ID and then prep invocation if User-visible info provided
25-
var invocation = current.text
26-
.replace(/^!(?:un)?verify-admin\u0020?/gi, "")
27-
.trim();
28-
var paramArr = invocation.split(" ");
29-
30-
// 1. Handle -help flag
31-
if (paramArr.length == 1 && paramArr[0] == "-help") {
32-
messageBody =
33-
"*Admin Tool - Verify User*\n" +
34-
"A parser for setting user verification and descriptions. \n" +
35-
"*Note:* This parser can only be triggered from admin channels.\n\n" +
36-
"*Usage:*\n" +
37-
"`!verify-admin @username [optional description]`\n" +
38-
"`!unverify-admin @username [optional description]`\n\n" +
39-
"*Examples:*\n" +
40-
"`!verify-admin @Astrid Is an Impasta`\n" +
41-
"`!unverify-admin @Astrid Is an Impasta`\n" +
42-
"`!verify-admin @Astrid Some Role, Some Company`\n" +
43-
"`!verify-admin @Astrid -v`\n\n" +
44-
"*Supported flags:*\n" +
45-
"`-v`: Verify the user (default for !verify-admin)\n" +
46-
"`-unv`: Unverify the user (default for !unverify-admin)\n" +
47-
"`-help`: Show this message";
48-
49-
slacker.send_chat(current, messageBody, true);
50-
return; // CRITICAL: Stop execution here
51-
}
52-
53-
// 2. Validate that a user tag is provided
54-
if (paramArr.length == 0 || !/^<@.*?>$/.test(paramArr[0])) {
55-
messageBody =
56-
"!verify-admin must be called with a user tag, followed by an optional parameter and optional description. For example: `!verify-admin @Astrid -unv Is an Impasta`\n\nThe full list of accepted triggers can be found by sending `!verify-admin -help`";
57-
slacker.send_chat(current, messageBody, true);
58-
return; // Stop execution
59-
}
60-
61-
// 3. Extract User ID
62-
userId = paramArr[0].replace(/[<>@]/g, "");
63-
paramArr.shift(); // Remove the user tag from the array
64-
65-
// 4. Validate Flags
66-
var hasV = paramArr.indexOf("-v") > -1;
67-
var hasUnv = paramArr.indexOf("-unv") > -1;
68-
69-
if (hasV && hasUnv) {
70-
messageBody =
71-
"Please only provide one verify parameter in your message. Verification message ignored.";
72-
slacker.send_chat(current, messageBody, true);
73-
return; // Stop execution
74-
}
75-
76-
// 5. Determine Verification Status
77-
// Flags override the default based on the command name
78-
if (hasUnv) {
79-
verificationStatus = false;
80-
} else if (hasV) {
81-
verificationStatus = true;
82-
} else {
83-
// No flag provided, use the default based on command name
84-
verificationStatus = defaultVerificationStatus;
85-
}
86-
87-
// 6. Extract Description
88-
// Filter out the flags from the description
89-
var descriptionArr = paramArr.filter(function(item) {
90-
return item !== "-v" && item !== "-unv";
91-
});
92-
description = descriptionArr.join(" ");
93-
94-
// 7. Update User Record
95-
var grUser = new GlideRecord("x_snc_slackerbot_user");
96-
if (grUser.get("user_id", userId)) {
97-
grUser.setValue("verified", verificationStatus);
98-
99-
if (description.length > 0) {
100-
grUser.setValue("user_info", description);
7+
(function(){
8+
if (
9+
current.channel == "GD51HTR46" ||
10+
current.channel == "G9LAJG7G8" ||
11+
current.channel == "G7M4AP6U8"
12+
) {
13+
//admin channels on sndevs
14+
var messageBody = "";
15+
var userId = "";
16+
var description = "";
17+
var verificationStatus = null;
18+
var slacker = new x_snc_slackerbot.Slacker();
19+
20+
// Determine the base command to set default verification status
21+
// If it starts with !unverify, default is false. Otherwise (verify), default is true.
22+
var isUnverifyCommand = current.text.toLowerCase().indexOf("!unverify-admin") === 0;
23+
var defaultVerificationStatus = isUnverifyCommand ? false : true;
24+
25+
// Grab user ID and then prep invocation if User-visible info provided
26+
var invocation = current.text
27+
.replace(/^!(?:un)?verify-admin\u0020?/gi, "")
28+
.trim();
29+
var paramArr = invocation.split(" ");
30+
31+
// 1. Handle -help flag
32+
if (paramArr.length == 1 && paramArr[0] == "-help") {
33+
messageBody =
34+
"*Admin Tool - Verify User*\n" +
35+
"A parser for setting user verification and descriptions. \n" +
36+
"*Note:* This parser can only be triggered from admin channels.\n\n" +
37+
"*Usage:*\n" +
38+
"`!verify-admin @username [optional description]`\n" +
39+
"`!unverify-admin @username [optional description]`\n\n" +
40+
"*Examples:*\n" +
41+
"`!verify-admin @Astrid Is an Impasta`\n" +
42+
"`!unverify-admin @Astrid Is an Impasta`\n" +
43+
"`!verify-admin @Astrid Some Role, Some Company`\n" +
44+
"`!verify-admin @Astrid -v`\n\n" +
45+
"*Supported flags:*\n" +
46+
"`-v`: Verify the user (default for !verify-admin)\n" +
47+
"`-unv`: Unverify the user (default for !unverify-admin)\n" +
48+
"`-help`: Show this message";
49+
50+
slacker.send_chat(current, messageBody, true);
51+
return;
52+
}
53+
54+
// 2. Validate that a user tag is provided
55+
if (paramArr.length == 0 || !/^<@.*?>$/.test(paramArr[0])) {
56+
messageBody =
57+
"!verify-admin must be called with a user tag, followed by an optional parameter and optional description. For example: `!verify-admin @Astrid -unv Is an Impasta`\n\nThe full list of accepted triggers can be found by sending `!verify-admin -help`";
58+
slacker.send_chat(current, messageBody, true);
59+
return;
60+
}
61+
62+
// 3. Extract User ID
63+
userId = paramArr[0].replace(/[<>@]/g, "");
64+
paramArr.shift();
65+
66+
// 4. Validate Flags
67+
var hasV = paramArr.indexOf("-v") > -1;
68+
var hasUnv = paramArr.indexOf("-unv") > -1;
69+
70+
if (hasV && hasUnv) {
71+
messageBody =
72+
"Please only provide one verify parameter in your message. Verification message ignored.";
73+
slacker.send_chat(current, messageBody, true);
74+
return;
75+
}
76+
77+
// 5. Determine Verification Status
78+
// Flags override the default based on the command name
79+
if (hasUnv) {
80+
verificationStatus = false;
81+
} else if (hasV) {
82+
verificationStatus = true;
10183
} else {
102-
// If no new description, keep the old one
103-
description = grUser.getValue("user_info");
84+
verificationStatus = defaultVerificationStatus;
10485
}
105-
106-
grUser.update();
107-
108-
messageBody =
109-
"Updated <@" +
110-
userId +
111-
">'s verification information:\n";
112-
messageBody +=
113-
"Verification status: " +
114-
(verificationStatus ? "*Verified*" : "*Unverified*") +
115-
"\n";
116-
messageBody += "User information:\n>" + description;
117-
} else {
118-
messageBody = "I'm afraid I can't do that as the user (<@" + userId + ">) does not exist.";
119-
}
12086

121-
slacker.send_chat(current, messageBody, true);
122-
}
87+
// 6. Extract Description
88+
// Filter out the flags from the description
89+
var descriptionArr = paramArr.filter(function(item) {
90+
return item !== "-v" && item !== "-unv";
91+
});
92+
description = descriptionArr.join(" ");
93+
94+
// 7. Update User Record
95+
var grUser = new GlideRecord("x_snc_slackerbot_user");
96+
if (grUser.get("user_id", userId)) {
97+
grUser.setValue("verified", verificationStatus);
98+
99+
if (description.length > 0) {
100+
grUser.setValue("user_info", description);
101+
} else {
102+
// If no new description, keep the old one
103+
description = grUser.getValue("user_info");
104+
}
105+
106+
grUser.update();
107+
108+
messageBody =
109+
"Updated <@" +
110+
userId +
111+
">'s verification information:\n";
112+
messageBody +=
113+
"Verification status: " +
114+
(verificationStatus ? "*Verified*" : "*Unverified*") +
115+
"\n";
116+
messageBody += "User information:\n>" + description;
117+
} else {
118+
messageBody = "I'm afraid I can't do that as the user (<@" + userId + ">) does not exist.";
119+
}
120+
121+
slacker.send_chat(current, messageBody, true);
122+
}
123+
})();

0 commit comments

Comments
 (0)