chore: formatting
This commit is contained in:
@ -5,21 +5,21 @@ import {
|
|||||||
type NostrEvent,
|
type NostrEvent,
|
||||||
type SystemInterface,
|
type SystemInterface,
|
||||||
NostrPrefix,
|
NostrPrefix,
|
||||||
EventKind
|
EventKind,
|
||||||
} from "@snort/system";
|
} from "@snort/system";
|
||||||
import EventEmitter from "eventemitter3";
|
import EventEmitter from "eventemitter3";
|
||||||
|
|
||||||
export interface BotEvents {
|
export interface BotEvents {
|
||||||
message: (msg: BotMessage) => void,
|
message: (msg: BotMessage) => void;
|
||||||
event: (ev: NostrEvent) => void,
|
event: (ev: NostrEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BotMessage {
|
export interface BotMessage {
|
||||||
link: NostrLink,
|
link: NostrLink;
|
||||||
from: string,
|
from: string;
|
||||||
message: string,
|
message: string;
|
||||||
event: NostrEvent,
|
event: NostrEvent;
|
||||||
reply: (msg: string) => void,
|
reply: (msg: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandHandler = (msg: BotMessage) => void;
|
export type CommandHandler = (msg: BotMessage) => void;
|
||||||
@ -32,13 +32,13 @@ export class SnortBot extends EventEmitter<BotEvents> {
|
|||||||
constructor(
|
constructor(
|
||||||
readonly name: string,
|
readonly name: string,
|
||||||
readonly system: SystemInterface,
|
readonly system: SystemInterface,
|
||||||
readonly publisher: EventPublisher
|
readonly publisher: EventPublisher,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
system.pool.on("event", (addr, sub, e) => {
|
system.pool.on("event", (addr, sub, e) => {
|
||||||
this.emit("event", e);
|
this.emit("event", e);
|
||||||
if (e.kind === 30311) {
|
if (e.kind === 30311) {
|
||||||
const links = [e, ...this.activeStreams].map(v => NostrLink.fromEvent(v))
|
const links = [e, ...this.activeStreams].map(v => NostrLink.fromEvent(v));
|
||||||
const linkStr = links.map(e => e.encode());
|
const linkStr = links.map(e => e.encode());
|
||||||
if (linkStr.every(a => this.#activeStreamSub.has(a))) {
|
if (linkStr.every(a => this.#activeStreamSub.has(a))) {
|
||||||
return;
|
return;
|
||||||
@ -72,7 +72,7 @@ export class SnortBot extends EventEmitter<BotEvents> {
|
|||||||
event: e,
|
event: e,
|
||||||
reply: (msg: string) => {
|
reply: (msg: string) => {
|
||||||
this.#sendReplyTo(link, msg);
|
this.#sendReplyTo(link, msg);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +80,10 @@ export class SnortBot extends EventEmitter<BotEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get activeStreams() {
|
get activeStreams() {
|
||||||
return this.system.GetQuery("streams")?.snapshot?.filter(a => a.tags.find(b => b[0] === "status")?.at(1) === "live") ?? []
|
return (
|
||||||
|
this.system.GetQuery("streams")?.snapshot?.filter(a => a.tags.find(b => b[0] === "status")?.at(1) === "live") ??
|
||||||
|
[]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user