Skip to content

Commit

Permalink
- Added help command
Browse files Browse the repository at this point in the history
- Fixed handler command
  • Loading branch information
Snailedlt committed Aug 15, 2021
1 parent e8443ed commit 2a62da4
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/
.idea/
.vscode/
settings-development.json
settings-development.json
15 changes: 8 additions & 7 deletions src/boot.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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();

const commandFiles = fs.readdirSync('./src/commands').filter(file => file.endsWith('.js'));
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) => {
Expand Down Expand Up @@ -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);
}
Expand Down
29 changes: 16 additions & 13 deletions src/commands/create.js
Original file line number Diff line number Diff line change
@@ -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`);
}
};
143 changes: 73 additions & 70 deletions src/commands/handler.js
Original file line number Diff line number Diff line change
@@ -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',
},
});
},
});
}
});
};
69 changes: 69 additions & 0 deletions src/commands/help.js
Original file line number Diff line number Diff line change
@@ -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',
},
},
});*/
};
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.prefix = "-"

0 comments on commit 2a62da4

Please sign in to comment.