Skip to content

Commit

Permalink
Add an IS_DEV env var.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Aug 9, 2024
1 parent f0d8021 commit ae2c051
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
3 changes: 3 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ export const BADGE_CONTAINER_ID = "badge";
export const CONTENT_MINIMUM_LENGTH = 3;
export const CONTENT_MAXIMUM_LENGTH = 300;
export const EARLIEST_FILTER_SINCE = 1716736622;

export const DEV_PUBKEY =
"80789235a71a388074abfa5c482e270456d2357425266270f82071cf2b1de74a";
4 changes: 3 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ function getOrCreatePrivateKey(maybePrivateKeyNsec?: string) {
}

await new cliffy.Command()
.globalEnv("IS_DEV", "Set to true to run in development mode")
.globalEnv(
"PRIVATE_KEY_NSEC=<value:string>",
"Specify the private key in nsec format"
)
.action((options) => {
const { isDev } = options;
const privateKey = getOrCreatePrivateKey(options.privateKeyNsec);

repost(privateKey);
repost(privateKey, isDev);
})
.parse(Deno.args);
46 changes: 27 additions & 19 deletions validation/repost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MAP_NOTE_KIND,
MAP_NOTE_REPOST_KIND,
} from "../common/constants.ts";
import { DEV_PUBKEY } from "../common/constants.ts";

const RELAY = DEV_RELAYS[0];

Expand Down Expand Up @@ -55,23 +56,30 @@ function deriveContent(event: Event): string {
return event.content;
}

export async function repost(privateKey: Uint8Array) {
const sub = relay.subscribe(
[
{
kinds: [MAP_NOTE_KIND],
since: Math.floor(Date.now() / 1e3),
},
],
{
onevent: (event) => {
if (!validateEvent(event)) {
console.info(`Discarding event…`);
return;
}
const repostedEvent = generateRepostedEvent(event, privateKey);
publishEvent(repostedEvent);
},
}
);
function createFilter(isDev: true | undefined): nostrTools.Filter {
const baseFilter: nostrTools.Filter = {
kinds: [MAP_NOTE_KIND],
// since: Math.floor(Date.now() / 1e3),
};

if (isDev) {
return { ...baseFilter, authors: [DEV_PUBKEY] };
}

return baseFilter;
}

export async function repost(privateKey: Uint8Array, isDev: true | undefined) {
const filter = createFilter(isDev);

const sub = relay.subscribe([filter], {
onevent: (event) => {
if (!validateEvent(event)) {
console.info(`Discarding event…`);
return;
}
const repostedEvent = generateRepostedEvent(event, privateKey);
publishEvent(repostedEvent);
},
});
}

0 comments on commit ae2c051

Please sign in to comment.