@praise166/vire 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/vire.js +34 -6
  2. package/package.json +1 -2
package/dist/vire.js CHANGED
@@ -4,6 +4,7 @@ import { spawn } from 'node:child_process';
4
4
  import { access, copyFile, mkdir, readFile, writeFile } from 'node:fs/promises';
5
5
  import { dirname, join } from 'node:path';
6
6
  import process from 'node:process';
7
+ import { createInterface } from 'node:readline';
7
8
  import { fileURLToPath } from 'node:url';
8
9
  import { input, password, select } from '@inquirer/prompts';
9
10
  import boxen from 'boxen';
@@ -185,6 +186,10 @@ function telemetryUrl() {
185
186
  return target.toString();
186
187
  }
187
188
  function applyRemoteConfig(status) {
189
+ const url = statusUrl();
190
+ if (url && !process.env.VIRE_STATUS_URL) {
191
+ process.env.VIRE_STATUS_URL = url;
192
+ }
188
193
  if (status.database_url && !process.env.DATABASE_URL) {
189
194
  process.env.DATABASE_URL = status.database_url;
190
195
  }
@@ -397,17 +402,15 @@ async function saveSession(token, user) {
397
402
  async function ensureReleaseBinary(downloadedRuntime) {
398
403
  if (downloadedRuntime)
399
404
  return downloadedRuntime;
405
+ const updateBinary = await newestDownloadedRuntime();
406
+ if (updateBinary)
407
+ return updateBinary;
400
408
  const exe = process.platform === 'win32' ? 'vire.exe' : 'vire';
401
409
  const binary = join(root, 'target', 'release', exe);
402
410
  let exists = true;
403
411
  await access(binary).catch(() => {
404
412
  exists = false;
405
413
  });
406
- if (!exists) {
407
- const updateBinary = await newestDownloadedRuntime();
408
- if (updateBinary)
409
- return updateBinary;
410
- }
411
414
  if (!exists) {
412
415
  throw new Error('runtime missing; upload the exe to r2 or place it in updates');
413
416
  }
@@ -485,7 +488,7 @@ function startBot(binary, token, login) {
485
488
  const child = spawn(binary, [], {
486
489
  cwd: root,
487
490
  shell: false,
488
- stdio: ['inherit', 'pipe', 'pipe'],
491
+ stdio: ['pipe', 'pipe', 'pipe'],
489
492
  env: {
490
493
  ...process.env,
491
494
  DISCORD_TOKEN: token,
@@ -494,6 +497,7 @@ function startBot(binary, token, login) {
494
497
  },
495
498
  });
496
499
  ora().succeed('vire is online');
500
+ const terminal = attachTerminalCommands(child);
497
501
  let started = true;
498
502
  child.stdout.setEncoding('utf8');
499
503
  child.stderr.setEncoding('utf8');
@@ -514,6 +518,7 @@ function startBot(binary, token, login) {
514
518
  reject(error);
515
519
  });
516
520
  child.on('exit', code => {
521
+ terminal.close();
517
522
  if (!started) {
518
523
  console.log(chalk.red(`vire.self exited before connecting (${code ?? 0})`));
519
524
  }
@@ -524,6 +529,29 @@ function startBot(binary, token, login) {
524
529
  });
525
530
  });
526
531
  }
532
+ function attachTerminalCommands(child) {
533
+ console.log(chalk.dim('terminal commands: /rpc help'));
534
+ const terminal = createInterface({
535
+ input: process.stdin,
536
+ output: process.stdout,
537
+ terminal: true,
538
+ });
539
+ terminal.on('line', line => {
540
+ const input = line.trim();
541
+ if (!input)
542
+ return;
543
+ if (input === '/quit' || input === '/exit') {
544
+ child.kill();
545
+ return;
546
+ }
547
+ if (!input.startsWith('/')) {
548
+ console.log(chalk.dim('use /rpc help for terminal config'));
549
+ return;
550
+ }
551
+ child.stdin?.write(`${input}\n`);
552
+ });
553
+ return terminal;
554
+ }
527
555
  async function main() {
528
556
  banner();
529
557
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praise166/vire",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,6 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@inquirer/prompts": "^7.3.2",
25
- "@praise166/vire": "^0.1.3",
26
25
  "boxen": "^8.0.1",
27
26
  "chalk": "^5.4.1",
28
27
  "dotenv": "^16.4.7",