Skip to content

Commit

Permalink
Add njump links to Slack message
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Apr 3, 2024
1 parent 1e84164 commit c224203
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ functions.cloudEvent("nostrEventsPubSub", async (cloudEvent) => {
return;
}

await Nostr.maybeFetchNip05(reportRequest);
await Slack.postManualVerification(reportRequest);
return;
}
Expand Down
22 changes: 22 additions & 0 deletions src/lib/nostr.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ const connectedPromise = ndk.connect();
export const REPORT_KIND = 1984;

export default class Nostr {
static async maybeFetchNip05(reportRequest) {
const user = ndk.getUser({ hexpubkey: reportRequest.reporterPubkey });
const profile = await user.fetchProfile();

if (profile?.nip05) {
const njump = `https://njump.me/${profile.nip05}`;
reportRequest.njump = njump;
return;
}

const reportedUser = ndk.getUser({
hexpubkey: reportRequest.reportedEvent.pubkey,
});
const reportedUserProfile = await reportedUser.fetchProfile();

if (reportedUserProfile?.nip05) {
const njump = `https://njump.me/${reportedUserProfile.nip05}`;
reportRequest.reportedUserNjump = njump;
return;
}
}

// Creates a NIP-32 event flagging a Nostr event.
// See: https://github.com/nostr-protocol/nips/blob/master/32.md
static async publishModeration(moderatedNostrEvent, moderation) {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export default class Slack {
}

static createSlackMessagePayload(reportRequest) {
const text = `New Nostr Event to moderate requested by pubkey \`${reportRequest.reporterPubkey}\``;
let text = `New Nostr Event to moderate requested by pubkey \`${reportRequest.reporterPubkey}\``;
if (reportRequest.njump) {
text = `New Nostr Event to moderate requested by ${reportRequest.njump}`;
}

if (reportRequest.reportedUserNjump) {
text += ` reporting an event published by ${reportRequest.reportedUserNjump}`;
}

const elements = Object.entries(OPENAI_CATEGORIES).map(
([category, categoryData]) => {
Expand Down
2 changes: 2 additions & 0 deletions test/moderationFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe("Moderation Cloud Function", async () => {
],
});
sinon.stub(Nostr, "publishModeration");
sinon.stub(Nostr, "maybeFetchNip05");
const cloudEvent = {
data: {
message: {
Expand Down Expand Up @@ -153,6 +154,7 @@ describe("Moderation Cloud Function", async () => {
],
});
sinon.stub(Nostr, "publishModeration");
sinon.stub(Nostr, "maybeFetchNip05");
const cloudEvent = {
data: {
message: {
Expand Down

0 comments on commit c224203

Please sign in to comment.