diff --git a/.gitignore b/.gitignore index 84cb39c..a0b6f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules/ .idea/ .vscode/ -settings-development.json +settings-development.json \ No newline at end of file diff --git a/src/boot.js b/src/boot.js index c33dbba..c7799f8 100644 --- a/src/boot.js +++ b/src/boot.js @@ -1,14 +1,13 @@ import Discord from "discord.js"; import Axios from "axios"; import fs from "fs"; +const { prefix } = require('../src/utils.js'); const publicSSMApiPath = "https://hub.splitscreen.me/api/v1/"; -const botPrefix = "-"; +const botPrefix = prefix; const DiscordInit = secretDiscordToken => { - const DiscordBot = new Discord.Client({ - commandPrefix: botPrefix - }); + const DiscordBot = new Discord.Client(); DiscordBot.commands = new Discord.Collection(); @@ -16,11 +15,13 @@ const DiscordInit = secretDiscordToken => { for (const file of commandFiles) { const command = require(`./commands/${file}`); const commandName = file.split('.')[0]; + console.log(commandName); DiscordBot.commands.set(commandName, command); } DiscordBot.on('ready', async () => { + console.log("prefix = " + botPrefix); console.log('[Debug] Connected as ' + DiscordBot.user.tag); console.log('[Debug] Servers:'); DiscordBot.guilds.cache.forEach((guild) => { @@ -64,18 +65,18 @@ const DiscordInit = secretDiscordToken => { if (!receivedMessage.content.startsWith(botPrefix)) return; //Ignore messages from users which not start with {botPrefix} const fullCommand = receivedMessage.content.substr(1); // Remove the leading {botPrefix} const splitCommand = fullCommand.split(' '); // Split the message up in to pieces for each space + const args = splitCommand.slice(1); //arguments const commandName = splitCommand[0].toLowerCase(); // The first word directly after the {botPrefix} is the command or alias const command = //get the command based on a command or alias - DiscordBot.commands.get(commandName) || DiscordBot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName.toString())); + DiscordBot.commands.get(commandName) || DiscordBot.commands.find(cmd => cmd.config.aliases && cmd.config.aliases.includes(commandName)); console.log(`commandName => ${commandName}`); - console.log(`command => ${command}`); if (command) { console.log("command recognized"); try { - command.execute(receivedMessage, DiscordBot); + command.execute(DiscordBot, receivedMessage, args); } catch (error) { console.error(error); } diff --git a/src/commands/create.js b/src/commands/create.js index de2dcfb..75fb612 100644 --- a/src/commands/create.js +++ b/src/commands/create.js @@ -1,17 +1,20 @@ import Axios from "axios"; import Settings from "../../src/settings" +const { prefix } = require('../../src/utils.js'); -module.exports = { - name: 'create', - aliases: ['c'], - description: 'Creates the handler from the provided information. Example: "-create GameName"', - async execute(receivedMessage, DiscordBot) { - console.log('settings: ',Settings.private.DEVELOPMENT_CHANNELS) - console.log('received: ',receivedMessage.guild.id); - if(Settings.private.DEVELOPMENT_CHANNELS.includes(receivedMessage.guild.id)){ - console.log("access granted") - receivedMessage.channel.send('-create access granted'); - } - // - } +exports.config = { + name: `create`, + aliases: [`c`, `make`], + description: `Creates the handler from the provided information. Example: "-create GameName"`, + usage: `${prefix}create [game name]`, + example: `${prefix}create Grand Theft Auto V` +} + +exports.execute = async (DiscordBot, receivedMessage, args) => { + console.log('settings: ', Settings.private.DEVELOPMENT_CHANNELS) + console.log('received: ', receivedMessage.guild.id); + if (Settings.private.DEVELOPMENT_CHANNELS.includes(receivedMessage.guild.id)) { + console.log("access granted") + receivedMessage.channel.send(`${prefix}create access granted`); + } }; \ No newline at end of file diff --git a/src/commands/handler.js b/src/commands/handler.js index 0040e61..eb395c3 100644 --- a/src/commands/handler.js +++ b/src/commands/handler.js @@ -1,81 +1,84 @@ import Axios from "axios"; +const { prefix } = require('../../src/utils.js'); const publicSSMApiPath = "https://hub.splitscreen.me/api/v1/"; +exports.config = { + name: `handler`, + aliases: [`h`, `script`], + description: `Return handler for the specified game.`, + usage: `${prefix}handler [game name]`, + example: `${prefix}handler Grand Theft Auto V` +} -module.exports = { - name: 'handler', - aliases: ['h', 'script'], - description: 'Return handler for the specified game. Example: "-handler Game name"', - async execute(receivedMessage, DiscordBot) { - let fullCommand = receivedMessage.content.substr(1); // Remove the leading exclamation mark - let splitCommand = fullCommand.split(' '); // Split the message up in to pieces for each space - let argume = splitCommand.slice(1); - // console.log(argume); - if (argume.length === 0) { - receivedMessage.channel.send('Please, provide a game name.'); - return; - } +exports.execute = async (DiscordBot, receivedMessage, args) => { + let fullCommand = receivedMessage.content.substr(1); // Remove the leading exclamation mark + let splitCommand = fullCommand.split(' '); // Split the message up in to pieces for each space + let argume = splitCommand.slice(1); + // console.log(argume); + if (argume.length === 0) { + receivedMessage.channel.send('Please, provide a game name.'); + return; + } - let totalGame = ''; - argume.forEach(value => { - totalGame = totalGame + ' ' + value; - }); - totalGame = totalGame.substr(1); - const allHandlers = await Axios.get(publicSSMApiPath + 'handlers/' + totalGame.replace(/[^a-z0-9 -]/g, "")); - if (!allHandlers.data.Handlers) { - receivedMessage.channel.send('Sorry, no handler found matching your query!'); - return; - } - const foundHandlers = allHandlers.data.Handlers.length > 3 ? allHandlers.data.Handlers.slice(0, 3) : allHandlers.data.Handlers; - var downloadLink = " "; - foundHandlers.forEach(handler => { - downloadLink = `https://hub.splitscreen.me/cdn/storage/packages/${handler.currentPackage}/original/handler-${handler._id}-v${handler.currentVersion}.nc?download=true` - receivedMessage.channel.send({ - embed: { - color: 3447003, - author: { - name: DiscordBot.user.username, - icon_url: DiscordBot.user.avatarURL, + let totalGame = ''; + argume.forEach(value => { + totalGame = totalGame + ' ' + value; + }); + totalGame = totalGame.substr(1); + const allHandlers = await Axios.get(publicSSMApiPath + 'handlers/' + totalGame.replace(/[^a-z0-9 -]/g, "")); + if (!allHandlers.data.Handlers) { + receivedMessage.channel.send('Sorry, no handler found matching your query!'); + return; + } + const foundHandlers = allHandlers.data.Handlers.length > 3 ? allHandlers.data.Handlers.slice(0, 3) : allHandlers.data.Handlers; + var downloadLink = " "; + foundHandlers.forEach(handler => { + downloadLink = `https://hub.splitscreen.me/cdn/storage/packages/${handler.currentPackage}/original/handler-${handler._id}-v${handler.currentVersion}.nc?download=true` + receivedMessage.channel.send({ + embed: { + color: 3447003, + author: { + name: DiscordBot.user.username, + icon_url: DiscordBot.user.avatarURL, + }, + title: handler.gameName, + url: `https://hub.splitscreen.me/handler/${handler._id}`, + thumbnail: { + url: `https://images.igdb.com/igdb/image/upload/t_cover_big/${handler.gameCover}.jpg`, + }, + fields: [ + { + name: 'Author', + inline: true, + value: `[${handler.ownerName}](https://hub.splitscreen.me/user/${handler.owner})` + }, + { + name: 'Hotness', + inline: true, + value: handler.stars, }, - title: handler.gameName, - url: `https://hub.splitscreen.me/handler/${handler._id}`, - thumbnail: { - url: `https://images.igdb.com/igdb/image/upload/t_cover_big/${handler.gameCover}.jpg`, + { + name: 'Total downloads', + inline: true, + value: handler.downloadCount, }, - fields: [ - { - name: 'Author', - inline: true, - value: `[${handler.ownerName}](https://hub.splitscreen.me/user/${handler.owner})` - }, - { - name: 'Hotness', - inline: true, - value: handler.stars, - }, - { - name: 'Total downloads', - inline: true, - value: handler.downloadCount, - }, - { - name: 'Status', - inline: true, - value: handler.verified ? 'Verified' : 'Unverified', - }, - { - name: `Download`, - inline: false, - value: `[Download Handler (v${handler.currentVersion})](${downloadLink})`, - }, - ], - timestamp: new Date(), - footer: { - icon_url: DiscordBot.user.avatarURL, - text: '© SplitScreen.Me', + { + name: 'Status', + inline: true, + value: handler.verified ? 'Verified' : 'Unverified', }, + { + name: `Download`, + inline: false, + value: `[Download Handler (v${handler.currentVersion})](${downloadLink})`, + }, + ], + timestamp: new Date(), + footer: { + icon_url: DiscordBot.user.avatarURL, + text: '© SplitScreen.Me', }, - }); + }, }); - } + }); }; \ No newline at end of file diff --git a/src/commands/help.js b/src/commands/help.js new file mode 100644 index 0000000..02a2a39 --- /dev/null +++ b/src/commands/help.js @@ -0,0 +1,69 @@ +import Axios from "axios"; +import Settings from "../settings"; +const { prefix } = require('../../src/utils.js'); + +const publicSSMApiPath = "https://hub.splitscreen.me/api/v1/"; + +exports.config = { + name: `help`, + aliases: [`commands`, `commandlist`], + description: `Shows a list of all available bot commands`, + usage: `${prefix}help [command_name]`, + example: `${prefix}help handler` +} +exports.execute = async (DiscordBot, receivedMessage, args) => { + const data = []; + const {commands} = receivedMessage.client; + console.log("args" + args) + if (!args.length) { + console.log("we got this far"); + data.push("Here is a list of all my commands"); + data.push( prefix + commands.map(c => ` ${c.config.name} \`${c.config.aliases.join(` , `)}\``).join(`\n-`)); + data.push(`\n use ${prefix}help [command name] to get info about a specific command`); + receivedMessage.channel.send(data); + return; + } + + const name = args[0]; + const cmd = commands.get(name) || commands.find(c => c.config.aliases && c.config.aliases.includes(name)); + + if (!cmd) { + receivedMessage.reply(`${name} is not a valid command`) + return; + } + + + if (cmd.config.name) data.push(`**Name**: ${cmd.config.name}`); + if (cmd.config.description) data.push(`**Description:** ${cmd.config.description}`); + if (cmd.config.aliases) data.push(`**Aliases:** ${cmd.config.aliases.join(` , `)}`); + if (cmd.config.usage) data.push(`**Usage:** ${cmd.config.usage}`); + if (cmd.config.example) data.push(`**Example:** ${cmd.config.example}`); + + receivedMessage.channel.send(data); + + /*receivedMessage.channel.send({ + + embed: { + color: 3447003, + author: { + name: DiscordBot.user.username, + icon_url: DiscordBot.user.avatarURL, + }, + title: "Commandlist", + thumbnail: { + url: `https://images.igdb.com/igdb/image/upload/t_cover_big/.jpg`, + }, + fields: [{ + name: DiscordBot.commands.name, + inline: true, + value: `[](https://hub.splitscreen.me/user/)` + }, + ], + timestamp: new Date(), + footer: { + icon_url: DiscordBot.user.avatarURL, + text: '© SplitScreen.Me', + }, + }, + });*/ +}; \ No newline at end of file diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..f64e53d --- /dev/null +++ b/src/utils.js @@ -0,0 +1 @@ +exports.prefix = "-" \ No newline at end of file