-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtextMain.ts
More file actions
32 lines (31 loc) · 1.11 KB
/
textMain.ts
File metadata and controls
32 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Deno.env.set("TZ", "UTC");
import settings from "./settings.ts";
import { channelsIt, historyIt, MessageProcessor } from "./lib/slack.ts";
import { msgToRecord, recordsToJson, recordsToMarkdown } from "./lib/textOutput.ts";
import { Timestamp } from "./lib/timestamp.ts";
export default async function textMain(
format: "json" | "markdown",
oldest_: Date,
latest_: Date,
) {
const oldest = new Timestamp(oldest_);
const latest = new Timestamp(latest_);
const messageProcessor = await new MessageProcessor().asyncInit();
const channels: { name: string; records: ReturnType<typeof msgToRecord>[] }[] =
[];
for await (const c of channelsIt()) {
console.error(`Processing: ${c.name}`);
const records: ReturnType<typeof msgToRecord>[] = [];
for await (const msg of historyIt(c.id!, oldest.slack(), latest.slack())) {
records.push(msgToRecord(msg, messageProcessor));
}
if (records.length > 0) {
channels.push({ name: c.name!, records });
}
}
if (format === "json") {
console.log(recordsToJson(channels));
} else {
console.log(recordsToMarkdown(channels, settings.tz));
}
}