-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-patterns.ts
133 lines (116 loc) · 4.06 KB
/
test-patterns.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
// src/test-patterns.ts
import { BskyAgent } from "@atproto/api";
import {
DEFAULT_PATTERNS,
ADULT_CONTENT_PATTERN,
PROMO_LINK_PATTERN,
checkFollowRatio
} from "./patterns";
import type { BlockPattern } from "./types";
class PatternTester {
private agent: BskyAgent;
private patterns: BlockPattern[];
constructor(patterns: BlockPattern[] = DEFAULT_PATTERNS) {
this.agent = new BskyAgent({ service: "https://bsky.social" });
this.patterns = patterns;
}
async login(identifier: string, password: string): Promise<void> {
try {
await this.agent.login({ identifier, password });
console.log(`✅ Successfully logged in as ${identifier}`);
} catch (error) {
throw new Error(`Failed to login: ${(error as Error).message}`);
}
}
async testPatterns(handle: string) {
try {
console.log(`\n🔍 Testing patterns against @${handle}...\n`);
// Fetch profile
const profile = await this.agent.getProfile({ actor: handle });
console.log("Profile Information:");
console.log("-------------------");
console.log(`Display Name: ${profile.data.displayName || "(none)"}`);
console.log(`Handle: ${profile.data.handle}`);
console.log(`Followers: ${profile.data.followersCount || 0}`);
console.log(`Following: ${profile.data.followsCount || 0}`);
console.log(`Posts: ${profile.data.postsCount || 0}`);
console.log(`Description: ${profile.data.description || "(none)"}`);
console.log("\nPattern Tests:");
console.log("-------------");
// Test for adult content and promo links
const description = profile.data.description || "";
const hasAdultContent = ADULT_CONTENT_PATTERN.test(description);
const hasPromoLink = PROMO_LINK_PATTERN.test(description);
if (hasAdultContent) {
console.log("⚠️ Found adult content indicators");
}
if (hasPromoLink) {
console.log("⚠️ Found promotional link");
}
// Test follow ratio if both adult content and promo links are present
if (profile.data.followersCount && profile.data.followsCount) {
const result = checkFollowRatio(
profile.data.followsCount,
profile.data.followersCount,
description
);
if (result.matches) {
console.log(`⚠️ ${result.reason}`);
} else {
console.log(
`✓ Follow ratio: ${(
profile.data.followsCount / profile.data.followersCount
).toFixed(1)}x (following ${
profile.data.followsCount
} / followers ${profile.data.followersCount})`
);
}
}
// Test each pattern
for (const pattern of this.patterns) {
console.log("\nTesting pattern:");
if (pattern.displayNamePattern) {
const matches = pattern.displayNamePattern.test(
profile.data.displayName || ""
);
console.log(
`Display name vs ${pattern.displayNamePattern}: ${
matches ? "⚠️ MATCH" : "✓ no match"
}`
);
}
if (pattern.descriptionPattern) {
const matches = pattern.descriptionPattern.test(
profile.data.description || ""
);
console.log(
`Description vs ${pattern.descriptionPattern}: ${
matches ? "⚠️ MATCH" : "✓ no match"
}`
);
}
}
} catch (error) {
console.error("Error testing patterns:", error);
}
}
}
async function main() {
const handle = process.argv[2];
if (!handle) {
console.error(
"Please provide a handle to test. Usage: bun run test-patterns.ts <handle>"
);
process.exit(1);
}
const tester = new PatternTester();
const email = process.env.BLUESKY_EMAIL;
const password = process.env.BLUESKY_APP_PASSWORD;
if (!email || !password) {
console.error("BLUESKY_EMAIL and BLUESKY_APP_PASSWORD must be set");
process.exit(1);
}
await tester.login(email, password);
await tester.testPatterns(handle);
}
main().catch(console.error);