Repository navigation
Expand file tree
/
Copy pathexample.ts
More file actions
61 lines (52 loc) · 1.77 KB
/
Copy pathexample.ts
File metadata and controls
61 lines (52 loc) · 1.77 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
import { Transcripter } from './index';
import * as fs from 'fs';
import * as path from 'path';
/**
* Parse arguments manually to avoid dependencies.
* Expected format: --token "TOKEN" --guildId "ID" --channelId "ID"
*/
function parseArgs() {
const args = process.argv.slice(2);
const config: { [key: string]: string } = {};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg.startsWith('--')) {
const key = arg.slice(2).toLowerCase(); // token, guildid, channelid
const value = args[i + 1];
if (value && !value.startsWith('--')) {
config[key] = value;
i++;
}
}
}
return config;
}
async function main() {
const args = parseArgs();
const token = args['token'];
const guildId = args['guildid'];
const channelId = args['channelid'];
if (!token || !guildId || !channelId) {
console.error("Usage: node example-cli.js --token <TOKEN> --guildId <GUILD_ID> --channelId <CHANNEL_ID>");
process.exit(1);
}
console.log("Initializing Transcripter...");
const transcript = new Transcripter(token);
console.log(`Fetching messages for channel ${channelId}...`);
try {
const data = await transcript.fetch(guildId, channelId);
console.log("Fetch complete!");
console.log("Generating HTML...");
const outputDir = './output';
// Create output dir if not exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const html = data.generate({ dir: outputDir });
console.log(`HTML generated and saved to ${outputDir}`);
} catch (e) {
console.error("Error:", e);
}
}
main();