@abdarrahmanabdelnasir/relay-node 0.1.9 → 0.1.11
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.
- package/bin/commandless-discord.js +45 -0
- package/package.json +6 -2
|
@@ -0,0 +1,45 @@
|
|
|
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 = process.env.COMMANDLESS_SERVICE_URL; // Optional - defaults to Commandless backend
|
|
18
|
+
const hmacSecret = process.env.COMMANDLESS_HMAC_SECRET;
|
|
19
|
+
|
|
20
|
+
const client = new Client({
|
|
21
|
+
intents: [
|
|
22
|
+
GatewayIntentBits.Guilds,
|
|
23
|
+
GatewayIntentBits.GuildMessages,
|
|
24
|
+
GatewayIntentBits.MessageContent,
|
|
25
|
+
GatewayIntentBits.DirectMessages,
|
|
26
|
+
],
|
|
27
|
+
partials: [Partials.Channel]
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const relay = new RelayClient({ apiKey, baseUrl, hmacSecret });
|
|
31
|
+
|
|
32
|
+
useDiscordAdapter({ client, relay, mentionRequired: true });
|
|
33
|
+
|
|
34
|
+
client.once('ready', async () => {
|
|
35
|
+
console.log(`[commandless] Logged in as ${client.user.tag}`);
|
|
36
|
+
try {
|
|
37
|
+
const botId = await relay.registerBot({ platform: 'discord', name: client.user.username, clientId: client.user.id });
|
|
38
|
+
if (botId) relay.botId = botId;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.warn('[commandless] registerBot failed:', e?.message || e);
|
|
41
|
+
}
|
|
42
|
+
setInterval(async () => { try { await relay.heartbeat(); } catch {} }, 30_000);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
client.login(token);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abdarrahmanabdelnasir/relay-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
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"
|