@abdarrahmanabdelnasir/relay-node 0.1.9 → 0.1.10

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.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ import { Client, GatewayIntentBits, Partials } from 'discord.js';
4
+ import { RelayClient, useDiscordAdapter } from '@abdarrahmanabdelnasir/relay-node';
5
+
6
+ function getEnv(name, optional = false) {
7
+ const v = process.env[name];
8
+ if (!v && !optional) {
9
+ console.error(`[commandless] Missing required env: ${name}`);
10
+ process.exit(1);
11
+ }
12
+ return v;
13
+ }
14
+
15
+ const token = getEnv('BOT_TOKEN');
16
+ const apiKey = getEnv('COMMANDLESS_API_KEY');
17
+ const baseUrl = getEnv('COMMANDLESS_SERVICE_URL');
18
+ const hmacSecret = process.env.COMMANDLESS_HMAC_SECRET;
19
+ const fixedBotId = getEnv('BOT_ID');
20
+
21
+ const client = new Client({
22
+ intents: [
23
+ GatewayIntentBits.Guilds,
24
+ GatewayIntentBits.GuildMessages,
25
+ GatewayIntentBits.MessageContent,
26
+ GatewayIntentBits.DirectMessages,
27
+ ],
28
+ partials: [Partials.Channel]
29
+ });
30
+
31
+ const relay = new RelayClient({ apiKey, baseUrl, hmacSecret });
32
+ relay.botId = fixedBotId;
33
+
34
+ useDiscordAdapter({ client, relay, mentionRequired: true });
35
+
36
+ client.once('ready', async () => {
37
+ console.log(`[commandless] Logged in as ${client.user.tag}`);
38
+ try {
39
+ await relay.registerBot({ platform: 'discord', name: client.user.username, clientId: client.user.id });
40
+ } catch (e) {
41
+ console.warn('[commandless] registerBot failed:', e?.message || e);
42
+ }
43
+ setInterval(async () => { try { await relay.heartbeat(); } catch {} }, 30_000);
44
+ });
45
+
46
+ client.login(token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abdarrahmanabdelnasir/relay-node",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,16 +13,20 @@
13
13
  "types": "./dist/index.d.ts"
14
14
  }
15
15
  },
16
+ "bin": {
17
+ "commandless-discord": "bin/commandless-discord.js"
18
+ },
16
19
  "files": [
17
20
  "dist",
18
21
  "dist-cjs",
22
+ "bin",
19
23
  "README.md",
20
24
  "LICENSE"
21
25
  ],
22
26
  "scripts": {
23
27
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist-cjs/package.cjs','')\" && node -e \"const fs=require('fs');fs.renameSync('dist-cjs/index.js','dist-cjs/index.cjs')\"",
24
28
  "clean": "rimraf dist || rm -rf dist",
25
- "prepublishOnly": "npm run clean && npm run build"
29
+ "prepublishOnly": "npm run clean && npm run build && node -e \"try{require('fs').chmodSync('bin/commandless-discord.js',0o755)}catch(e){}\""
26
30
  },
27
31
  "engines": {
28
32
  "node": ">=18"