Repository navigation
Expand file tree
/
Copy pathAdmin tool - Verify.js
More file actions
88 lines (79 loc) · 3.4 KB
/
Copy pathAdmin tool - Verify.js
File metadata and controls
88 lines (79 loc) · 3.4 KB
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
/*
activation_example:!verify-admin @Astrid, !verify-admin -help
regex:^!(?:un)?verify-admin\u0020?
flags:gi
*/
if (
current.channel == "GD51HTR46" ||
current.channel == "G9LAJG7G8" ||
current.channel == "G7M4AP6U8"
) {
//admin channels on sndevs
var messageBody = "";
var userId = "";
var description = "";
var verificationStatus = null;
var slacker = new x_snc_slackerbot.Slacker();
// Grab user ID and then prep invocation if User-visible info provided
var invocation = current.text
.replace(/^!(?:un)?verify-admin\u0020?/gi, "")
.trim();
var paramArr = invocation.split(" ");
if (paramArr.length == 0) {
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`";
}
if (paramArr.length == 1 && paramArr[0] == "-help") {
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";
}
if (/^<@.*?>$/.test(paramArr[0])) {
messageBody = paramArr[0];
userId = paramArr[0].replace(/[<>@]/g, "");
paramArr.shift();
} else {
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`";
slacker.send_chat(current, messageBody, true);
}
if (paramArr.indexOf("-v") > -1 && paramArr.indexOf("-unv") > -1) {
messageBody =
"Please only provide one verify parameter in your message. Verification message ignored.";
slacker.send_chat(current, messageBody, true);
} else {
if (/^!unverify/.test(current.text)) {
verificationStatus = false;
} else if (paramArr.indexOf("-v") > -1) {
verificationStatus = true;
} else if (paramArr.indexOf("-unv") > -1) {
verificationStatus = false;
} else if (verificationStatus == null) {
verificationStatus = true;
}
description = paramArr.join(" ");
var grUser = new GlideRecord("x_snc_slackerbot_user");
if (grUser.get("user_id", userId)) {
verificationStatus != null
? grUser.setValue("verified", verificationStatus)
: grUser.getValue("verified");
if (description.length > 0) {
grUser.setValue("user_info", description);
} else {
description = grUser.getValue("user_info");
}
grUser.update();
messageBody =
"Updated <@" +
userId +
">'s verification information with the following info:\n";
messageBody +=
"Verification status: " +
(verificationStatus ? "*Verified*" : "*Unverified*") +
"\n";
messageBody += "User information:\n>" + description;
} else {
messageBody += `I'm afraid I can't do that as the ~limit~ user (<@${userId}>) does not exist.`;
}
slacker.send_chat(current, messageBody, true);
}
}