forked from jtgi/automod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser-profile.ts
160 lines (144 loc) · 4.39 KB
/
user-profile.ts
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
import { CheckFunction, CheckFunctionArgs, RuleDefinition } from "~/rules/rules.type";
function userProfileContainsText(args: CheckFunctionArgs) {
const { user, rule } = args;
const { searchText, caseSensitive } = rule.args;
const containsText = !caseSensitive
? user.profile.bio.text?.toLowerCase().includes(searchText.toLowerCase())
: user.profile.bio.text?.includes(searchText);
return {
result: containsText,
message: containsText ? `Profile contains "${searchText}"` : `Profile does not contain "${searchText}"`,
};
}
function userFollowerCount(props: CheckFunctionArgs) {
const { user, rule } = props;
const { min, max } = rule.args as { min?: number; max?: number };
if (min) {
if (user.follower_count < min) {
return {
result: true,
message: `User has less than ${min} followers`,
};
}
}
if (max) {
if (user.follower_count > max) {
return {
result: true,
message: `User has more than ${max} followers`,
};
}
}
return {
result: false,
message: "User follower count is within limits",
};
}
function userDisplayNameContainsText(args: CheckFunctionArgs) {
const { user, rule } = args;
const { searchText, caseSensitive } = rule.args;
if (!user.display_name) {
// Sentry.captureMessage(`Cast author has no display name: ${user.fid}`, {
// extra: {
// user,
// },
// });
return {
result: false,
message: "User has no display name",
};
}
const containsText = !caseSensitive
? user.display_name.toLowerCase().includes(searchText.toLowerCase())
: user.display_name.includes(searchText);
return {
result: containsText,
message: containsText ? `Display name contains "${searchText}"` : `Display name does not contain "${searchText}"`,
};
}
type RuleName = "userProfileContainsText" | "userDisplayNameContainsText" | "userFollowerCount";
export const userProfileRulesDefinitions: Record<RuleName, RuleDefinition> = {
userProfileContainsText: {
author: "modbot",
authorUrl: "https://modbot.sh",
authorIcon: `/icons/modbot.png`,
name: "userProfileContainsText",
allowMultiple: true,
category: "all",
friendlyName: "Profile Contains Text",
checkType: "user",
description: "Check if the user's profile contains a specific string",
hidden: false,
invertable: true,
args: {
searchText: {
type: "string",
friendlyName: "Search Text",
description: "The text to search for",
},
caseSensitive: {
type: "boolean",
friendlyName: "Case Sensitive",
description: "If checked, 'abc' is different from 'ABC'",
},
},
},
userDisplayNameContainsText: {
name: "userDisplayNameContainsText",
author: "modbot",
authorUrl: "https://modbot.sh",
authorIcon: `/icons/modbot.png`,
allowMultiple: true,
category: "all",
friendlyName: "User Display Name Contains Text",
checkType: "user",
description: "Check if the user's display name contains a specific string",
hidden: false,
invertable: true,
args: {
searchText: {
required: true,
type: "string",
friendlyName: "Search Text",
description: "The text to search for",
},
caseSensitive: {
type: "boolean",
friendlyName: "Case Sensitive",
description: "If checked 'abc' is different from 'ABC'",
},
},
},
userFollowerCount: {
name: "userFollowerCount",
author: "modbot",
authorUrl: "https://modbot.sh",
authorIcon: `/icons/modbot.png`,
allowMultiple: false,
category: "all",
friendlyName: "User Follower Count",
checkType: "user",
hidden: false,
invertable: false,
description: "Check if the user's follower count is within a range",
args: {
min: {
type: "number",
friendlyName: "Less than",
placeholder: "No Minimum",
description: "If you enter 10, the rule will trigger if the user has less than 10 followers.",
},
max: {
type: "number",
friendlyName: "More than",
placeholder: "No Maximum",
description: "If you enter 50, the rule will trigger if the user has more than 50 followers.",
},
},
},
};
export const userProfileRulesFunction: Record<RuleName, CheckFunction> = {
userProfileContainsText,
userDisplayNameContainsText,
userFollowerCount,
};