forked from jtgi/automod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
airstack.ts
55 lines (49 loc) · 1.73 KB
/
airstack.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
import { farRank } from "~/lib/airstack.server";
import { CheckFunction, CheckFunctionArgs, RuleDefinition } from "~/rules/rules.type";
async function airstackSocialCapitalRank(args: CheckFunctionArgs) {
const { user, rule } = args;
const { minRank } = rule.args as { minRank: number };
const rank = await farRank({ fid: user.fid }).then((res) => (res === null ? Infinity : res));
if (rank === Infinity) {
console.error(`User's FarRank is not available: ${user.fid}`);
return {
result: false,
message: "User's social FarRank is not available",
};
}
return {
result: rank <= minRank,
message:
rank <= minRank
? `User FarRank is #${rank.toLocaleString()}, higher than #${minRank.toLocaleString()}`
: `User's FarRank is #${rank.toLocaleString()}, lower than #${minRank.toLocaleString()}`,
};
}
type RuleName = "airstackSocialCapitalRank";
export const airstackRulesFunction: Record<RuleName, CheckFunction> = {
airstackSocialCapitalRank,
};
export const airstackRulesDefinitions: Record<RuleName, RuleDefinition> = {
airstackSocialCapitalRank: {
name: "airstackSocialCapitalRank",
author: "Airstack",
authorUrl: "https://airstack.xyz",
authorIcon: `/icons/airstack.png`,
allowMultiple: false,
hidden: false,
category: "all",
friendlyName: "FarRank by Airstack",
checkType: "user",
description: "Check if the user's Airstack FarRank is high enough.",
invertable: false,
args: {
minRank: {
type: "number",
friendlyName: "Minimum Rank",
required: true,
placeholder: "e.g. 100",
description: "Example: if you enter 100, the rule will check that the user's FarRank is 1 to 100.",
},
},
},
};