Skip to content

Commit 7a9f4f2

Browse files
authored
verify admin - fix unverify (#494)
1 parent 86130b1 commit 7a9f4f2

File tree

1 file changed

+69
-62
lines changed

1 file changed

+69
-62
lines changed

Parsers/Admin tool - Verify.js

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

7-
if (current.channel == 'GD51HTR46' || current.channel == 'G9LAJG7G8' || current.channel == 'G7M4AP6U8') { //admin channels on sndevs
8-
var messageBody = '';
9-
var userId = '';
10-
var description = '';
11-
var verificationStatus = null;
12-
var slacker = new x_snc_slackerbot.Slacker();
13-
14-
// Grab user ID and then prep invocation if User-visible info provided
15-
var invocation = current.text.replace(/^!(?:un)?verify-admin\u0020?/gi,'').trim();
16-
var paramArr = invocation.split(' ');
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();
1718

18-
if(paramArr.length == 0){
19-
messageBody = '!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`';
20-
}
19+
// Grab user ID and then prep invocation if User-visible info provided
20+
var invocation = current.text
21+
.replace(/^!(?:un)?verify-admin\u0020?/gi, "")
22+
.trim();
23+
var paramArr = invocation.split(" ");
2124

22-
if(paramArr.length == 1 && paramArr[0] == '-help'){
23-
messageBody = 'Admin Tool - Verify user\nA parser for setting user verification and descriptions. *Note:* This parser can only be triggered from admin channels specified.\n\nUsage: `!verify-admin @username [-v|-unv] [message]`\nExamples:\n`!verify-admin @Astrid -unv Is an Impasta`\n`!verify-admin @Astrid Some Role, Some Company`\n`!verify-admin @Astrid -v`\n\nSupported flags:\n-v: Verify the user\n-unv: Remove verification from user\n-help: Show this message';
24-
}
25+
if (paramArr.length == 0) {
26+
messageBody =
27+
"!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`";
28+
}
2529

26-
if(paramArr.length >= 2){
27-
if(/^<@.*?>$/.test(paramArr[0])){
28-
userId = paramArr[0].replace(/[<>@]/g,'');
29-
paramArr.shift();
30-
} else {
31-
messageBody = '!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`';
32-
}
33-
}
34-
35-
if(messageBody.length > 0 || userId.length == 0){
36-
if(messageBody.length == 0 && userId.length == 0){
37-
messageBody = 'The provided user details are malformed, meaning the user cannot be verified.';
38-
}
39-
slacker.send_chat(current, messageBody, true);
40-
} else {
41-
if(paramArr.indexOf('-v') > -1 && paramArr.indexOf('-unv') > -1){
42-
messageBody = 'Please only provide one verify parameter in your message. Verification message ignored.';
43-
slacker.send_chat(current, messageBody, true);
44-
} else {
45-
if(/^!unverify/.test(current.text)){
46-
verificationStatus = false;
47-
}
48-
else if(paramArr.indexOf('-v') > -1){
49-
verificationStatus = true;
50-
}
30+
if (paramArr.length == 1 && paramArr[0] == "-help") {
31+
messageBody =
32+
"Admin Tool - Verify user\nA parser for setting user verification and descriptions. *Note:* This parser can only be triggered from admin channels specified.\n\nUsage: `!verify-admin @username [-v|-unv] [message]`\nExamples:\n`!verify-admin @Astrid -unv Is an Impasta`\n`!verify-admin @Astrid Some Role, Some Company`\n`!verify-admin @Astrid -v`\n\nSupported flags:\n-v: Verify the user\n-unv: Remove verification from user\n-help: Show this message";
33+
}
5134

52-
else if(paramArr.indexOf('-unv') > -1){
53-
verificationStatus = false;
54-
}
35+
if (paramArr.length >= 2) {
36+
if (/^<@.*?>$/.test(paramArr[0])) {
37+
userId = paramArr[0].replace(/[<>@]/g, "");
38+
paramArr.shift();
39+
} else {
40+
messageBody =
41+
"!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`";
42+
}
43+
}
5544

56-
else if(verificationStatus == null){
57-
verificationStatus = true;
58-
}
45+
if (paramArr.indexOf("-v") > -1 && paramArr.indexOf("-unv") > -1) {
46+
messageBody =
47+
"Please only provide one verify parameter in your message. Verification message ignored.";
48+
slacker.send_chat(current, messageBody, true);
49+
} else {
50+
if (/^!unverify/.test(current.text)) {
51+
verificationStatus = false;
52+
} else if (paramArr.indexOf("-v") > -1) {
53+
verificationStatus = true;
54+
} else if (paramArr.indexOf("-unv") > -1) {
55+
verificationStatus = false;
56+
} else if (verificationStatus == null) {
57+
verificationStatus = true;
58+
}
5959

60-
description = paramArr.join(' ');
61-
var grUser = new GlideRecord('x_snc_slackerbot_user');
62-
if(grUser.get('user_id',userId)){
63-
verificationStatus != null ? grUser.setValue('verified',verificationStatus) : grUser.getValue('verified');
64-
description.length > 0 ? grUser.setValue('user_info',description) : null;
65-
grUser.update();
60+
description = paramArr.join(" ");
61+
var grUser = new GlideRecord("x_snc_slackerbot_user");
62+
if (grUser.get("user_id", userId)) {
63+
verificationStatus != null
64+
? grUser.setValue("verified", verificationStatus)
65+
: grUser.getValue("verified");
66+
description.length > 0 ? grUser.setValue("user_info", description) : null;
67+
grUser.update();
6668

67-
messageBody = 'Updated <@' + userId + '>\'s verification information with the following info:\n';
68-
messageBody += 'Verification status: ' + (verificationStatus ? '*Verified*' : '*Unverified*') + '\n';
69-
messageBody += 'User information:\n>' + description;
70-
71-
} else {
72-
messageBody += 'I\'m afraid I can\'t do that as the ~limit~ user does not exist.';
73-
}
74-
slacker.send_chat(current, messageBody, true);
75-
}
69+
messageBody =
70+
"Updated <@" +
71+
userId +
72+
">'s verification information with the following info:\n";
73+
messageBody +=
74+
"Verification status: " +
75+
(verificationStatus ? "*Verified*" : "*Unverified*") +
76+
"\n";
77+
messageBody += "User information:\n>" + description;
78+
} else {
79+
messageBody +=
80+
"I'm afraid I can't do that as the ~limit~ user does not exist.";
7681
}
82+
slacker.send_chat(current, messageBody, true);
7783
}
84+
}

0 commit comments

Comments
 (0)