Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links #56

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Cleanstr is a Google Cloud Function node application designed to filter and mode
- 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.
- Content flagged by Cleanstr is managed by this relay and marked as kind 1984 for prompt handling.
- Following the [Reportinator](https://njump.me/nprofile1qqs2m4gep0jxwdmg23kp3dt9mgaxnyjp7rsx5a0zm0qr7xrx85dhkfcpzemhxue69uhhyetvv9ujumn0wvh8xmmrd9skcl8vqu6) bot in your Nostr client is essential for proper integration with Cleanstr's moderation reports.
- Your client should properly process kind 1984 in a similar way that https://nos.social does.
- Your client should properly process kind 1984 in a similar way that https://nos.social does.

## Support

Expand Down
19 changes: 14 additions & 5 deletions src/lib/nostr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import NDK, { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { validateEvent, verifySignature } from "nostr-tools";
import OPENAI_CATEGORIES from "./openAICategories.js";
import { WebSocket } from "ws";
import { nip19 } from "nostr-tools";

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

export default class Nostr {
static async updateNjump(reportRequest, hexpubkey, fieldToUpdate) {
const profile = await this.fetchProfile(hexpubkey);

const njumpPath = profile?.nip05
? profile.nip05
: nip19.npubEncode(hexpubkey);
console.log("njumpPath", njumpPath, hexpubkey);

const njump = `https://njump.me/${njumpPath}`;
reportRequest[fieldToUpdate] = njump;
}

static async fetchProfile(hexpubkey) {
await connectedPromise;
const user = ndk.getUser({ hexpubkey });
const profile = await user.fetchProfile();
if (profile?.nip05) {
const njump = `https://njump.me/${profile.nip05}`;
reportRequest[fieldToUpdate] = njump;
}
return await user.fetchProfile();
}

static async maybeFetchNip05(reportRequest) {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/reportRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ export default class ReportRequest {
return new ReportRequest(json, null, null);
}

reporterNpub() {
console.log("this.reporterPubkey", this.reporterPubkey);
return nip19.npubEncode(this.reporterPubkey);
}

reportedNpub() {
return nip19.npubEncode(this.reportedEvent.pubkey);
}

nevent() {
return nip19.neventEncode(this.reportedEvent.id);
}
Expand Down
7 changes: 1 addition & 6 deletions src/lib/slack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WebClient } from "@slack/web-api";
import OPENAI_CATEGORIES from "./openAICategories.js";
import Nostr from "./nostr.js";

if (!process.env.SLACK_TOKEN) {
Expand Down Expand Up @@ -44,11 +43,7 @@ export default class Slack {
}

static createSlackMessagePayload(reportRequest) {
let text = `New Nostr Event to moderate requested by ${
reportRequest.njump || code(reportRequest.reporterNpub())
} reporting an event published by ${
reportRequest.reportedUserNjump || code(reportRequest.reportedNpub())
}`;
let text = `New Nostr Event to moderate requested by ${reportRequest.njump} reporting an event published by ${reportRequest.reportedUserNjump}`;

const elements = nip56_report_type.map((category) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/moderationFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("Moderation Cloud Function", async () => {
sinon.spy(console, "error");
sinon.spy(console, "log");
sinon.stub(Nostr, "publishNostrEvent").returns(Promise.resolve());
sinon.stub(Nostr, "updateNjump").returns(Promise.resolve());
sinon.stub(Nostr, "fetchProfile").returns(Promise.resolve());
sinon.stub(Slack, "postManualVerification").returns(Promise.resolve());
sinon.stub(Datastore.prototype, "get").resolves([]);
sinon.stub(Datastore.prototype, "save").resolves();
Expand Down
10 changes: 6 additions & 4 deletions test/slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import sinon from "sinon";
import Slack from "../src/lib/slack.js";
import ReportRequest from "../src/lib/reportRequest.js";
import fs from "fs";
import Nostr from "../src/lib/nostr.js";

describe("Slack", () => {
beforeEach(async () => {
sinon.spy(console, "error");
sinon.spy(console, "log");
sinon.stub(Slack, "postManualVerification").returns(Promise.resolve());
sinon.stub(Nostr, "fetchProfile").returns(Promise.resolve());
});

afterEach(async () => {
sinon.restore();
});

it("createSlackMessagePayload", () => {
it("createSlackMessagePayload", async () => {
const pubkey =
"56d4b3d6310fadb7294b7f041aab469c5ffc8991b1b1b331981b96a246f6ae65";
const nostrEvent = {
Expand Down Expand Up @@ -45,20 +47,20 @@ describe("Slack", () => {
};

const reportRequest = ReportRequest.fromCloudEvent(cloudEvent);
console.log(reportRequest);
await Nostr.maybeFetchNip05(reportRequest);
const slackMessagePayload = Slack.createSlackMessagePayload(reportRequest);

expect(slackMessagePayload).to.be.eql({
channel: "something",
text: "New Nostr Event to moderate requested by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j` reporting an event published by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j`",
text: "New Nostr Event to moderate requested by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j reporting an event published by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j",
unfurl_links: false,
unfurl_media: false,
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: "New Nostr Event to moderate requested by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j` reporting an event published by `npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j`",
text: "New Nostr Event to moderate requested by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j reporting an event published by https://njump.me/npub12m2t8433p7kmw22t0uzp426xn30lezv3kxcmxvvcrwt2y3hk4ejsvre68j",
},
},
{
Expand Down
Loading