Skip to content

Commit a51d6e8

Browse files
committed
Fix links
1 parent a227b93 commit a51d6e8

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Cleanstr is a Google Cloud Function node application designed to filter and mode
5353
- If you don't want to host your own deployment you can use our relay. Add `wss://relay.nos.social` to your Nostr client's relay list.
5454
- Content flagged by Cleanstr is managed by this relay and marked as kind 1984 for prompt handling.
5555
- Following the [Reportinator](https://njump.me/nprofile1qqs2m4gep0jxwdmg23kp3dt9mgaxnyjp7rsx5a0zm0qr7xrx85dhkfcpzemhxue69uhhyetvv9ujumn0wvh8xmmrd9skcl8vqu6) bot in your Nostr client is essential for proper integration with Cleanstr's moderation reports.
56-
- Your client should properly process kind 1984 in a similar way that https://nos.social does.
56+
- Your client should properly process kind 1984 in a similar way that https://nos.social does.
5757

5858
## Support
5959

src/lib/nostr.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import NDK, { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
22
import { validateEvent, verifySignature } from "nostr-tools";
33
import OPENAI_CATEGORIES from "./openAICategories.js";
44
import { WebSocket } from "ws";
5+
import { nip19 } from "nostr-tools";
56

67
if (!process.env.NOSTR_PRIVATE_KEY) {
78
throw new Error("NOSTR_PRIVATE_KEY environment variable is required");
@@ -31,13 +32,21 @@ export const REPORT_KIND = 1984;
3132

3233
export default class Nostr {
3334
static async updateNjump(reportRequest, hexpubkey, fieldToUpdate) {
35+
const profile = await this.fetchProfile(hexpubkey);
36+
37+
const njumpPath = profile?.nip05
38+
? profile.nip05
39+
: nip19.npubEncode(hexpubkey);
40+
console.log("njumpPath", njumpPath, hexpubkey);
41+
42+
const njump = `https://njump.me/${njumpPath}`;
43+
reportRequest[fieldToUpdate] = njump;
44+
}
45+
46+
static async fetchProfile(hexpubkey) {
3447
await connectedPromise;
3548
const user = ndk.getUser({ hexpubkey });
36-
const profile = await user.fetchProfile();
37-
if (profile?.nip05) {
38-
const njump = `https://njump.me/${profile.nip05}`;
39-
reportRequest[fieldToUpdate] = njump;
40-
}
49+
return await user.fetchProfile();
4150
}
4251

4352
static async maybeFetchNip05(reportRequest) {

src/lib/reportRequest.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ export default class ReportRequest {
2222
return new ReportRequest(json, null, null);
2323
}
2424

25-
reporterNpub() {
26-
console.log("this.reporterPubkey", this.reporterPubkey);
27-
return nip19.npubEncode(this.reporterPubkey);
28-
}
29-
30-
reportedNpub() {
31-
return nip19.npubEncode(this.reportedEvent.pubkey);
32-
}
33-
3425
nevent() {
3526
return nip19.neventEncode(this.reportedEvent.id);
3627
}

src/lib/slack.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { WebClient } from "@slack/web-api";
2-
import OPENAI_CATEGORIES from "./openAICategories.js";
32
import Nostr from "./nostr.js";
43

54
if (!process.env.SLACK_TOKEN) {
@@ -44,11 +43,7 @@ export default class Slack {
4443
}
4544

4645
static createSlackMessagePayload(reportRequest) {
47-
let text = `New Nostr Event to moderate requested by ${
48-
reportRequest.njump || code(reportRequest.reporterNpub())
49-
} reporting an event published by ${
50-
reportRequest.reportedUserNjump || code(reportRequest.reportedNpub())
51-
}`;
46+
let text = `New Nostr Event to moderate requested by ${reportRequest.njump} reporting an event published by ${reportRequest.reportedUserNjump}`;
5247

5348
const elements = nip56_report_type.map((category) => {
5449
return {

test/moderationFunction.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("Moderation Cloud Function", async () => {
6060
sinon.spy(console, "error");
6161
sinon.spy(console, "log");
6262
sinon.stub(Nostr, "publishNostrEvent").returns(Promise.resolve());
63-
sinon.stub(Nostr, "updateNjump").returns(Promise.resolve());
63+
sinon.stub(Nostr, "fetchProfile").returns(Promise.resolve());
6464
sinon.stub(Slack, "postManualVerification").returns(Promise.resolve());
6565
sinon.stub(Datastore.prototype, "get").resolves([]);
6666
sinon.stub(Datastore.prototype, "save").resolves();

test/slack.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ import sinon from "sinon";
33
import Slack from "../src/lib/slack.js";
44
import ReportRequest from "../src/lib/reportRequest.js";
55
import fs from "fs";
6+
import Nostr from "../src/lib/nostr.js";
67

78
describe("Slack", () => {
89
beforeEach(async () => {
910
sinon.spy(console, "error");
1011
sinon.spy(console, "log");
1112
sinon.stub(Slack, "postManualVerification").returns(Promise.resolve());
13+
sinon.stub(Nostr, "fetchProfile").returns(Promise.resolve());
1214
});
1315

1416
afterEach(async () => {
1517
sinon.restore();
1618
});
1719

18-
it("createSlackMessagePayload", () => {
20+
it("createSlackMessagePayload", async () => {
1921
const pubkey =
2022
"56d4b3d6310fadb7294b7f041aab469c5ffc8991b1b1b331981b96a246f6ae65";
2123
const nostrEvent = {
@@ -45,20 +47,20 @@ describe("Slack", () => {
4547
};
4648

4749
const reportRequest = ReportRequest.fromCloudEvent(cloudEvent);
48-
console.log(reportRequest);
50+
await Nostr.maybeFetchNip05(reportRequest);
4951
const slackMessagePayload = Slack.createSlackMessagePayload(reportRequest);
5052

5153
expect(slackMessagePayload).to.be.eql({
5254
channel: "something",
53-
text: "New Nostr Event to moderate requested by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j` reporting an event published by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j`",
55+
text: "New Nostr Event to moderate requested by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j reporting an event published by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j",
5456
unfurl_links: false,
5557
unfurl_media: false,
5658
blocks: [
5759
{
5860
type: "section",
5961
text: {
6062
type: "mrkdwn",
61-
text: "New Nostr Event to moderate requested by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j` reporting an event published by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j`",
63+
text: "New Nostr Event to moderate requested by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j reporting an event published by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j",
6264
},
6365
},
6466
{

0 commit comments

Comments
 (0)