forked from jtgi/automod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmembership-fee.ts
72 lines (66 loc) · 2.08 KB
/
membership-fee.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
import { CheckFunction, CheckFunctionArgs, RuleDefinition } from "~/rules/rules.type";
import { db } from "~/lib/db.server";
export async function membershipFeeRequired(args: CheckFunctionArgs) {
const { user, rule, channel } = args;
const { tokenName, feeAmount, receiveAddress } = rule.args;
const channelOrder = await db.channelOrder.findFirst({
where: {
channelId: channel.id,
fid: user.fid.toString(),
address: receiveAddress,
status: 1,
},
});
const isPaid = !!channelOrder;
return {
result: isPaid,
message: isPaid
? `User has paid the membership fee to join the channel`
: `Membership fee required: ${feeAmount} ${tokenName}`,
};
}
type RuleName = "membershipFeeRequired";
export const membershipFeeRulesDefinitions: Record<RuleName, RuleDefinition> = {
membershipFeeRequired: {
name: "membershipFeeRequired",
author: "modbot",
authorUrl: "https://modbot.sh",
authorIcon: `/icons/modbot.png`,
allowMultiple: false,
category: "all",
friendlyName: " Membership Fee Required",
checkType: "user",
description: "Require the user pay a membership fee to join the channel",
invertedDescription: "Check for users who *do not* pay a membership fee to join the channel",
hidden: false,
invertable: true,
args: {
tokenName: {
type: "select",
friendlyName: "Token Name",
description: "",
required: true,
defaultValue: "ETH (Base Chain)",
options: [{ value: "ETH (Base Chain)", label: "ETH (Base Chain)" }],
},
feeAmount: {
type: "string",
required: true,
friendlyName: "Fee Amount",
placeholder: "0.01",
description: "",
},
receiveAddress: {
type: "string",
required: true,
pattern: "0x[a-fA-F0-9]{40}",
placeholder: "0xdead...",
friendlyName: "Address to receive fees",
description: "",
},
},
},
};
export const membershipFeeRulesFunction: Record<RuleName, CheckFunction> = {
membershipFeeRequired: membershipFeeRequired,
};