@inner-dj/discord-receiver 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cory Sanin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ import { type ActivityOptions } from 'discord.js';
2
+ import { iReceiver } from '@inner-dj/common';
3
+ import type { iReceiverConfig } from '@inner-dj/common';
4
+ export interface InnerDJDiscordBotConfig extends iReceiverConfig {
5
+ token: string;
6
+ activity: ActivityOptions | undefined;
7
+ route: string | undefined;
8
+ }
9
+ export declare class InnerDJDiscordBot extends iReceiver<InnerDJDiscordBotConfig> {
10
+ private client;
11
+ static getConfig(cfg?: Partial<InnerDJDiscordBotConfig>): InnerDJDiscordBotConfig;
12
+ start: () => Promise<void>;
13
+ registerCommands: () => Promise<unknown>;
14
+ close: () => void;
15
+ }
@@ -0,0 +1,91 @@
1
+ import { REST, Client, GatewayIntentBits, Events, Routes, MessageFlags, SlashCommandBuilder } from 'discord.js';
2
+ import { iReceiver, getBoolean, throwNewError } from '@inner-dj/common';
3
+ ;
4
+ const COMMAND_NAME = 'request';
5
+ const COMMAND_OPTION = 'url';
6
+ export class InnerDJDiscordBot extends iReceiver {
7
+ client = null;
8
+ static getConfig(cfg) {
9
+ const enabled = getBoolean('DISCORDENABLED', cfg, 'enabled', false);
10
+ return {
11
+ enabled,
12
+ token: process.env['DISCORDTOKEN'] ?? cfg?.token ?? ((enabled && throwNewError('Discord Token is required.')) || ''),
13
+ activity: cfg?.activity,
14
+ route: process.env['DISCORDROUTE'] ?? cfg?.route,
15
+ };
16
+ }
17
+ start = async () => {
18
+ const client = this.client = new Client({
19
+ intents: [GatewayIntentBits.DirectMessages],
20
+ allowedMentions: { parse: [] },
21
+ });
22
+ client.on(Events.Error, err => {
23
+ console.error(`discord.js client error:\n`, err);
24
+ });
25
+ client.on(Events.ShardReady, () => {
26
+ this.config.activity?.name &&
27
+ this.client?.user?.setActivity(this.config.activity.name, this.config.activity);
28
+ });
29
+ client.on(Events.InteractionCreate, async (interaction) => {
30
+ if (!interaction?.isCommand()) {
31
+ return;
32
+ }
33
+ if (interaction.commandName !== COMMAND_NAME) {
34
+ interaction.reply({
35
+ content: '🛑 Unrecognized command',
36
+ flags: MessageFlags.Ephemeral
37
+ });
38
+ return;
39
+ }
40
+ const request = interaction.options.getString(COMMAND_OPTION);
41
+ if (!request) {
42
+ interaction.reply({
43
+ content: '⚠️ URL is required',
44
+ flags: MessageFlags.Ephemeral
45
+ });
46
+ return;
47
+ }
48
+ this.request(request);
49
+ interaction.reply({
50
+ content: `✅️ Sent to queue.`,
51
+ flags: MessageFlags.Ephemeral
52
+ });
53
+ });
54
+ await client.login(this.config.token);
55
+ await this.registerCommands();
56
+ const authUrl = `https://discord.com/oauth2/authorize?client_id=${client.application?.id}`;
57
+ console.log(`Install bot: ${authUrl}`);
58
+ if (!this.config.route) {
59
+ return;
60
+ }
61
+ this.registerRoute('get', this.config.route, (_req, res) => {
62
+ res.redirect(authUrl);
63
+ });
64
+ this.registerGuide(`
65
+ <h3 class="title is-3">Discord</h3>
66
+ <div>
67
+ Navigate to <a href="${this.config.route}"><span class="populate-url"></span>${this.config.route}</a> and authorize the app.
68
+ Then request a song using the <span class="has-text-weight-bold is-family-monospace">/request</span> command.
69
+ </div>
70
+ `);
71
+ };
72
+ registerCommands = () => {
73
+ const rest = new REST().setToken(this.config.token);
74
+ return rest.put(Routes.applicationCommands(this.client?.user?.id), {
75
+ body: [new SlashCommandBuilder()
76
+ .setName(COMMAND_NAME)
77
+ .setDescription("Request a song to add to the queue")
78
+ .addStringOption(op => op.setName(COMMAND_OPTION)
79
+ .setDescription('YouTube video URL')
80
+ .setRequired(true)
81
+ .setMinLength(5)
82
+ .setMaxLength(120)).toJSON()]
83
+ });
84
+ };
85
+ close = () => {
86
+ this.client?.destroy();
87
+ this.client = null;
88
+ };
89
+ }
90
+ InnerDJDiscordBot;
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAA0D,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxK,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOvE,CAAC;AAEF,MAAM,YAAY,GAAG,SAAS,CAAC;AAC/B,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,OAAO,iBAAkB,SAAQ,SAAkC;IAC7D,MAAM,GAAkB,IAAI,CAAC;IAErC,MAAM,CAAC,SAAS,CAAC,GAAsC;QACnD,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,GAAG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AGvG,CAAC,CAAC;IACP,CAAC,CAAA;IAED,gBAAgB,GAAG,GAAG,EAAE;QACpB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,GAAG,CACX,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,EAAG,CAAC,EAClD;YACI,IAAI,EAAE,CAAC,IAAI,mBAAmB,EAAE;qBAC3B,OAAO,CAAC,YAAY,CAAC;qBACrB,cAAc,CAAC,oCAAoC,CAAC;qBACpD,eAAe,CAAC,EAAE,CAAC,EAAE,CAClB,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC;qBACzB,cAAc,CAAC,mBAAmB,CAAC;qBACnC,WAAW,CAAC,IAAI,CAAC;qBACjB,YAAY,CAAC,CAAC,CAAC;qBACf,YAAY,CAAC,GAAG,CAAC,CACrB,CAAC,MAAM,EAAE,CAAC;SAClB,CACJ,CAAC;IACN,CAAC,CAAA;IAEQ,KAAK,GAAG,GAAG,EAAE;QAClB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC,CAAC;CACL;AAED,iBAAoE,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import fsp from 'fs/promises';
3
+ import path from 'path';
4
+ import { InnerDJDiscordBot } from './index.js';
5
+ import { DebugClientInterface } from '@inner-dj/common';
6
+ console.log('inner-dj-discord-bot - Developed by Cory Sanin - 2026');
7
+ const config = await (async function getConfig(cfgPath) {
8
+ const p = process.env['CONFIG'] || cfgPath || path.join('config', 'config.json');
9
+ const contents = JSON.parse(await fsp.readFile(p, { encoding: 'utf-8' }));
10
+ return InnerDJDiscordBot.getConfig(contents);
11
+ })();
12
+ const bot = new InnerDJDiscordBot(config, new DebugClientInterface());
13
+ await bot.start();
14
+ process.on('SIGTERM', () => {
15
+ bot.close();
16
+ });
17
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";AACA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAgC,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AAErE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAgB;IAC3D,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAW,IAAI,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAC3F,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAqC,CAAC;IAC9G,OAAO,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC,CAAC,EAAE,CAAA;AAEJ,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,MAAM,EAAE,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACtE,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;AAElB,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,GAAG,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@inner-dj/discord-receiver",
3
+ "version": "0.0.3",
4
+ "description": "Discord bot for taking song requests",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://codeberg.org/sanin/inner-dj.git"
8
+ },
9
+ "license": "MIT",
10
+ "author": "Cory Sanin",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./lib/src/index.d.ts",
15
+ "import": "./lib/src/index.js"
16
+ }
17
+ },
18
+ "main": "./lib/src/index.js",
19
+ "types": "./lib/src/index.d.ts",
20
+ "files": [
21
+ "lib/src",
22
+ "!lib/**/*.js.map"
23
+ ],
24
+ "dependencies": {
25
+ "@inner-dj/common": "0.0.3",
26
+ "bufferutil": "^4.1.0",
27
+ "discord.js": "^14.26.4",
28
+ "utf-8-validate": "^6.0.6"
29
+ },
30
+ "devDependencies": {
31
+ "@sindresorhus/tsconfig": "8.1.0",
32
+ "@types/node": "^24.12.4",
33
+ "typescript": "^6.0.3"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc && chmod +x ./lib/src/main.js",
37
+ "start": "./lib/src/main.js"
38
+ }
39
+ }