From a70be5599a28b16357f8aeb67868ffbd479a5d28 Mon Sep 17 00:00:00 2001 From: ashley zomo Date: Thu, 27 Jan 2022 17:04:21 -0600 Subject: [PATCH] discord client init --- .gitignore | 3 ++- dist/index.js | 45 +++++++++++++++++++++++++++++++++++++++++---- dist/queue.js | 6 ++++++ src/index.ts | 31 +++++++++++++++++++++++++++---- src/queue.ts | 3 +++ 5 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 dist/queue.js create mode 100644 src/queue.ts diff --git a/.gitignore b/.gitignore index b512c09..d7ce76c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +token \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index be7ccf1..2c648b0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,4 +1,23 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -9,7 +28,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -const api_1 = require("./api"); -(() => __awaiter(void 0, void 0, void 0, function* () { - console.log(yield (0, api_1.getPlayer)('asldhasuhdbla')); -}))(); +const discord_js_1 = require("discord.js"); +const fs = __importStar(require("fs")); +const discord_1 = require("./discord"); +const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] }); +if (!fs.existsSync('./token')) { + fs.writeFileSync('./token', ''); + console.error('Missing Discord Token, please enter the bot token into the token file'); + process.exit(1); +} +const TOKEN = fs.readFileSync('./token').toString(); +CLIENT.on('ready', client => { + console.log(`Logged in as ${client.user.tag}`); + client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id))); +}); +CLIENT.on('interactionCreate', (interaction) => __awaiter(void 0, void 0, void 0, function* () { + if (!interaction.isCommand()) + return; + if (interaction.commandName === 'queue') { + yield interaction.reply('Pong!'); + } +})); +CLIENT.login(TOKEN); diff --git a/dist/queue.js b/dist/queue.js new file mode 100644 index 0000000..0429988 --- /dev/null +++ b/dist/queue.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createQueue = void 0; +function createQueue() { +} +exports.createQueue = createQueue; diff --git a/src/index.ts b/src/index.ts index c4cc7e8..10e14db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,28 @@ -import { getPlayer } from "./api"; -(async () => { - console.log(await getPlayer('asldhasuhdbla')); -})() +import { Client, Intents } from 'discord.js'; +import * as fs from 'fs'; +import { registerCommands } from './discord'; +const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] }); + +if (!fs.existsSync('./token')) { + fs.writeFileSync('./token', ''); + console.error('Missing Discord Token, please enter the bot token into the token file'); + process.exit(1); +} +const TOKEN = fs.readFileSync('./token').toString(); + +CLIENT.on('ready', client => { + console.log(`Logged in as ${client.user.tag}`); + client.guilds.fetch().then(guilds => + registerCommands(TOKEN, client.user.id, guilds.map(g => g.id))); +}); + +CLIENT.on('interactionCreate', async interaction => { + if (!interaction.isCommand()) return; + + if (interaction.commandName === 'queue') { + await interaction.reply('Pong!'); + } +}); + +CLIENT.login(TOKEN); \ No newline at end of file diff --git a/src/queue.ts b/src/queue.ts new file mode 100644 index 0000000..f0d0c43 --- /dev/null +++ b/src/queue.ts @@ -0,0 +1,3 @@ +export function createQueue() { + +} \ No newline at end of file