diff --git a/.travis.yml b/.travis.yml
index b9e3131..410392f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,31 @@
language: node_js
node_js:
+ - "7"
- "8"
+ - "9"
+
install: npm install
+script: node app
jobs:
include:
- stage: ESLint
+ node_js: "8"
script: npm test
- stage: Mocha
+ node_js: "8"
script: npm run mocha-test
+
+matrix:
+ allow_failures:
+ - node_js: "7"
+
+notifications:
+ webhooks:
+ urls:
+ - https://api.discordspark.com/travis
+ on_success: always
+ on_failure: always
+ on_start: always
+ on_cancel: always
+ on_error: always
+ email: false
diff --git a/README.md b/README.md
index 08858e1..e3907d3 100644
--- a/README.md
+++ b/README.md
@@ -2,12 +2,8 @@
## Spark is a powerful modular framework that makes creating Discord bots easy
[![Discord](https://discordapp.com/api/guilds/248505281741455360/embed.png)](https://discord.gg/TezD2Zg)
-[![Greenkeeper badge](https://badges.greenkeeper.io/TobiasFeld22/Spark.svg)](https://greenkeeper.io/)
-[![npm](https://img.shields.io/npm/v/sparkbots.svg)](https://npmjs/sparkbots)
-![Branch](https://img.shields.io/badge/Branch-Stable-orange.svg)
-[![Build Status](https://api.travis-ci.org/TobiasFeld22/Spark.svg?branch=Stable)](https://travis-ci.org/TobiasFeld22/Spark)
-![Branch_rewrite](https://img.shields.io/badge/Branch-Rewrite-orange.svg)
-[![Build Status rewrite](https://api.travis-ci.org/TobiasFeld22/Spark.svg)](https://travis-ci.org/TobiasFeld22/Spark)
+[![npm](https://api.discordspark.com/badge/npm)](https://npmjs.com/sparkbots)
+[![Build Status](https://api.travis-ci.org/Sparkbots/Spark.svg?branch=Stable)](https://travis-ci.org/TobiasFeld22/Spark)
##### About Spark.
diff --git a/app.js b/app.js
index 5c914bc..3201fbe 100644
--- a/app.js
+++ b/app.js
@@ -4,6 +4,9 @@ const chalk = require("chalk")
const startBot = require("./src/start.js")
const confirmConfig = require("./src/confirmConfig.js")
let Client;
+if (Number(process.version.slice(1).split(".")[0]) < 8) {
+ throw new Error("Your node.js version isnt high enough " + chalk.red(process.version) + " < " + chalk.green("8.0.0+") + "\nInstall a higher version of " + chalk.yellow("node.js") + " by going to " + chalk.blue("https://nodejs.org/en/download") + "\n---\nDownload node.js version " + chalk.green("8") + " or higher.\n\n If you want more information go to \n " + chalk.blue("https://discordspark.com/errors/outdated_nodejs") + "\n\n");
+}
/*
All modular classes
@@ -44,94 +47,97 @@ exports.event = function(name, options) {
}
exports.start = function(options) {
- if (!confirmConfig(options)) {
- return
- }
- if (typeof options.ignoreBots != "boolean" && typeof options.ignoreBots != "string" && options.ignoreBots != null) {
- return console.log(`You're trying to start with ${chalk.red("an invalid option:")} ${chalk.red("ignoreBots")}, Please read this article on the docs on how to use this option: ${chalk.blue("https://discordspark.com/documentation/config")}`)
- }
- if (options.ignoreBots == true) {
- options.ignoreBots = 4;
- } else if (options.ignoreBots == false) {
- options.ignoreBots = null
- } else if (options.ignoreBots == "message") {
- options.ignoreBots = 1
- } else if (options.ignoreBots == "command") {
- options.ignoreBots = 2
- }
+ return new Promise(function(resolve, reject) {
- Client = class Client extends discord.Client {
- constructor(config) {
- super(config)
- this.version = require("./package.json").version
- this.config = {}
- this.customConfig = new exports.DataStore()
- this.CustomConfig = exports.CustomConfig
+ if (!confirmConfig(options)) {
+ return reject("There was an error in your configuration setup, There may be additional messages above.")
}
-
- async search() {
- var data = await require("./src/search.js").func(this)
- return data;
+ if (typeof options.ignoreBots != "boolean" && typeof options.ignoreBots != "string" && options.ignoreBots != null) {
+ console.log(`You're trying to start with ${chalk.red("an invalid option:")} ${chalk.red("ignoreBots")}, Please read this article on the docs on how to use this option: ${chalk.blue("https://discordspark.com/documentation/config")}`)
+ return reject()
}
- async start() {
- this.dataStore = await this.dataStore;
- if (this.config.first) {
- console.log(`Welcome to ${chalk.yellow(`Spark V${this.version}`)}!\nTo see the changelog for this update go to this page:\n${chalk.blue("https://github.com/TobiasFeld22/Spark/releases")}\nTo learn more about using Spark, please visit our docs:\n${chalk.blue("https://discordspark.com/")}\n-------------------`)
+ if (options.ignoreBots == true) {
+ options.ignoreBots = 4;
+ } else if (options.ignoreBots == false) {
+ options.ignoreBots = null
+ } else if (options.ignoreBots == "message") {
+ options.ignoreBots = 1
+ } else if (options.ignoreBots == "command") {
+ options.ignoreBots = 2
+ }
+
+ Client = class Client extends discord.Client {
+ constructor(config) {
+ super(config)
+ this.version = require("./package.json").version
+ this.config = {}
+ this.customConfig = new exports.DataStore()
+ this.CustomConfig = exports.CustomConfig
}
- function colours(text, size) {
- if (size == 0) {
- return chalk.red(text)
- }
- return chalk.green(text)
+ async search() {
+ var data = await require("./src/search.js").func(this)
+ return data;
}
- var commandtext = colours(`${this.dataStore.commands.size} commands\n`, this.dataStore.commands.size)
- var observertext = colours(`${this.dataStore.functions.observer.size} observers\n`, this.dataStore.functions.observer.size)
- var enginetext = colours(`${this.dataStore.functions.engines.size} engines\n`, this.dataStore.functions.engines.size)
- var snippettext = colours(`${this.dataStore.functions.snippet.size} snippets\n`, this.dataStore.functions.snippet.size)
- var permissiontext = colours(`${this.dataStore.permissions.size} permissions\n`, this.dataStore.permissions.size)
- var eventtext = colours(`${this.dataStore.events.size} events\n`, this.dataStore.events.size)
- startBot(this)
+ async start() {
+ this.dataStore = await this.dataStore;
+ if (this.config.first) {
+ console.log(`Welcome to ${chalk.yellow(`Spark V${this.version}`)}!\nTo see the changelog for this update go to this page:\n${chalk.blue("https://github.com/TobiasFeld22/Spark/releases")}\nTo learn more about using Spark, please visit our docs:\n${chalk.blue("https://discordspark.com/")}\n-------------------`)
+ }
- console.log(`Your bot (${chalk.yellow(this.user.tag)}) is now ${chalk.green("online!")} | Running on ${this.guilds.size} servers | ${chalk.yellow(`Spark v${this.version}`)}\nWe detected the following data:\n \n ${commandtext} ${observertext} ${enginetext} ${snippettext} ${permissiontext} ${eventtext}`)
- }
+ function colours(text, size) {
+ if (size == 0) {
+ return chalk.red(text)
+ }
+ return chalk.green(text)
+ }
+ var commandtext = colours(`${this.dataStore.commands.size} commands\n`, this.dataStore.commands.size)
+ var observertext = colours(`${this.dataStore.functions.observer.size} observers\n`, this.dataStore.functions.observer.size)
+ var enginetext = colours(`${this.dataStore.functions.engines.size} engines\n`, this.dataStore.functions.engines.size)
+ var snippettext = colours(`${this.dataStore.functions.snippet.size} snippets\n`, this.dataStore.functions.snippet.size)
+ var permissiontext = colours(`${this.dataStore.permissions.size} permissions\n`, this.dataStore.permissions.size)
+ var eventtext = colours(`${this.dataStore.events.size} events\n`, this.dataStore.events.size)
+ startBot(this)
+
+ console.log(`Your bot (${chalk.yellow(this.user.tag)}) is now ${chalk.green("online!")} | Running on ${this.guilds.size} servers | ${chalk.yellow(`Spark v${this.version}`)}\nWe detected the following data:\n \n ${commandtext} ${observertext} ${enginetext} ${snippettext} ${permissiontext} ${eventtext}`)
+ }
- }
- Client = new Client(options.clientOptions);
- Client.on("cc_update", function(data) {
- Client.customConfig.set(data.id, data)
- });
- Client.config = options
- Client.login(options.token).then(async () => {
- try {
- var application = await Client.fetchApplication()
- Client.config.ownerID = application.owner.id
- } catch (e) {
- console.log(e)
- throw Error("Couldn't fetch application, token may be a invalid / user token. ")
}
- Client.guilds.forEach(i => {
- i.customConfig = new exports.CustomConfig(Client, i.id);
- Client.customConfig.set(i.id, i.customConfig)
- })
- Client.dataStore = await Client.search()
- Client.snippets = {
- list: (name) => {
- if (!name) {
- return Client.dataStore.functions.snippet.map((i, n) => n)
- } else if (Client.dataStore.functions.snippet.has(name)) {
- return Client.dataStore.functions.snippet.get(name)
+ Client = new Client(options.clientOptions);
+ Client.on("cc_update", function(data) {
+ Client.customConfig.set(data.id, data)
+ });
+ Client.config = options
+ Client.login(options.token).then(async () => {
+ try {
+ var application = await Client.fetchApplication()
+ Client.config.ownerID = application.owner.id
+ } catch (e) {
+ console.log(e)
+ throw Error("Couldn't fetch application, token may be a invalid / user token. ")
+ }
+ Client.guilds.forEach(i => {
+ i.customConfig = new exports.CustomConfig(Client, i.id);
+ Client.customConfig.set(i.id, i.customConfig)
+ })
+ Client.dataStore = await Client.search()
+ Client.snippets = {
+ list: (name) => {
+ if (!name) {
+ return Client.dataStore.functions.snippet.map((i, n) => n)
+ } else if (Client.dataStore.functions.snippet.has(name)) {
+ return Client.dataStore.functions.snippet.get(name)
+ }
+ return null;
}
- return null;
}
- }
- Client.dataStore.functions.snippet.forEach((i, n) => {
- Client.snippets[n] = i.snippet.code
+ Client.dataStore.functions.snippet.forEach((i, n) => {
+ Client.snippets[n] = i.snippet.code
+ })
+ Client.start(Client)
+ }).catch(err => {
+ return reject(console.error("An error occured while trying to login, check your token.", err))
})
- Client.start(Client)
-
- }).catch(err => {
- return console.error("An error occured while trying to login, check your token.", err)
- })
+ });
}
diff --git a/commands/about.js b/commands/about.js
index b407c36..9fd7539 100644
--- a/commands/about.js
+++ b/commands/about.js
@@ -1,6 +1,5 @@
var Spark = require("../")
const Command = Spark.command("about")
-const embed = new Spark.methods.RichEmbed();
Command.setLevel(0)
Command.setDescription("Get information about this bot.")
@@ -8,45 +7,46 @@ Command.setDescription("Get information about this bot.")
Command.code = async (client, message) => {
var v = process.memoryUsage().heapUsed
- v = (v/1024/1024).toFixed(3);
+ v = (v / 1024 / 1024).toFixed(3);
- var prefixText = prefixList().map(i => i).join(", ")
- if (prefixList().length > 1){
- prefixText = prefixList().map(i => ("`" + i + "`")).join(", ")
+ var prefixText = prefixList().map(i => i).join(", ")
+ if (prefixList().length > 1) {
+ prefixText = prefixList().map(i => ("`" + i + "`")).join(", ")
}
if (message.channel.permissionsFor(message.guild.members.get(client.user.id)).serialize().EMBED_LINKS) {
- embed.setTitle(`Information about ${client.user.username}`)
- embed.setDescription(`Hello, I am ${client.user.tag}. I am owned and maintained by <@${client.config.ownerID}>, created with the Discord.JS framework known as **Spark**.\n\n`+
- "Spark is a powerful modular framework that makes creating Discord bots easy.")
- embed.addField("Prefix(es):", prefixText, true)
- embed.addField("Servers:", client.guilds.size, true)
- embed.addField("Users:", client.users.size, true)
- embed.addField("Memory Usage:", `${v} MB`, false)
- embed.addField("Spark Version:", Spark.version, false)
- embed.addField("More Information:", "Feel free to visit our [website](https://discordspark.com) or our discord [server](https://discord.gg/TezD2Zg) for more information about the Spark Framework.", false)
- embed.setFooter("Made with Spark")
- embed.setTimestamp()
- embed.setColor(0xe1e818)
- return message.channel.send("", {embed})
+ const embed = new Spark.methods.RichEmbed();
+ embed.setTitle(`Information about ${client.user.username}`)
+ embed.setDescription(`Hello, I am ${client.user.tag}. I am owned and maintained by <@${client.config.ownerID}>, created with the Discord.JS framework known as **Spark**.\n\n` +
+ "Spark is a powerful modular framework that makes creating Discord bots easy.")
+ embed.addField("Prefix(es):", prefixText, true)
+ embed.addField("Servers:", client.guilds.size, true)
+ embed.addField("Users:", client.users.size, true)
+ embed.addField("Memory Usage:", `${v} MB`, false)
+ embed.addField("Spark Version:", Spark.version, false)
+ embed.addField("More Information:", "Feel free to visit our [website](https://discordspark.com) or our discord [server](https://discord.gg/TezD2Zg) for more information about the Spark Framework.", false)
+ embed.setFooter("Made with Spark")
+ embed.setTimestamp()
+ embed.setColor(0xe1e818)
+ return message.channel.send("", {embed})
}
var owner = await client.fetchUser(client.config.ownerID);
- message.channel.send(`Hello, I am ${client.user.tag}. I am owned and maintained by ${owner.tag}, created with the Discord.JS framework known as **Spark**.\n\n`+
- "Spark is a powerful modular framework that makes creating Discord bots easy.\n\n" +
- `My prefix(es) are: ${prefixText}.\n`+
- // "My ping is: {bot_latency}ms.\n"+
- `I am running on version \`${Spark.version}\` of spark.\n\n`+
- "__Statistics__\n"+
- `I am currently in \`${client.guilds.size}\` servers.\n`+
- `I am being used by \`${client.users.size}\` users.\n`+
- `I am using \`${v}\` MB of memory.\n\n`+
- "For more information about the **Spark** framework visit https://discord.gg/TezD2Zg or the website https://discordspark.com")
+ message.channel.send(`Hello, I am ${client.user.tag}. I am owned and maintained by ${owner.tag}, created with the Discord.JS framework known as **Spark**.\n\n` +
+ "Spark is a powerful modular framework that makes creating Discord bots easy.\n\n" +
+ `My prefix(es) are: ${prefixText}.\n` +
+ // "My ping is: {bot_latency}ms.\n"+
+ `I am running on version \`${Spark.version}\` of spark.\n\n` +
+ "__Statistics__\n" +
+ `I am currently in \`${client.guilds.size}\` servers.\n` +
+ `I am being used by \`${client.users.size}\` users.\n` +
+ `I am using \`${v}\` MB of memory.\n\n` +
+ "For more information about the **Spark** framework visit https://discord.gg/TezD2Zg or the website https://discordspark.com")
function prefixList() {
- if (client.customConfig.get(message.guild.id).prefix) {
- return client.customConfig.get(message.guild.id).prefix
- }
- return client.config.prefix
- }
+ if (client.customConfig.get(message.guild.id).prefix) {
+ return client.customConfig.get(message.guild.id).prefix
+ }
+ return client.config.prefix
+ }
}
module.exports = Command;
diff --git a/commands/help.js b/commands/help.js
index ab9f689..c7599a7 100644
--- a/commands/help.js
+++ b/commands/help.js
@@ -1,3 +1,4 @@
+/* eslint prefer-destructuring: 0 */
var Spark = require("../")
const Command = Spark.command("help")
@@ -13,10 +14,15 @@ Command.code = async (client, message) => {
var {command} = client.dataStore.commands.get(message.content.split(" ")[1].toLowerCase())
var data = await getData()
if (message.channel.permissionsFor(message.guild.members.get(client.user.id)).serialize().EMBED_LINKS) {
- embed.setTitle(command.name + " command information")
+ embed.setTitle(cap(command.name) + " command information")
embed.addField("Name", command.name)
embed.addField("Level required", command.level)
embed.addField("Description", command.description)
+ command.helpFields.forEach(i => {
+ if (embed.fields.length < 25) {
+ embed.addField(i.title, i.desc, i.inline)
+ }
+ })
if (data.has(command.name.toLowerCase())) {
embed.setFooter("You have the permission to use this command.", message.author.avatarURL)
} else {
@@ -25,11 +31,16 @@ Command.code = async (client, message) => {
embed.setColor(client.config.embedColor || 0xffe13f)
message.channel.send("", {embed})
} else {
- var text = `**${command.name} command information**\n\n• **Name:**\n ${command.name}\n\n• **Level required:**\n ${command.level}\n\n• **Description:**\n ${command.description}\n\n\n`
+ var text = `**${command.name} command information**\n\n• **Name:**\n ${command.name}\n\n• **Level required:**\n ${command.level}\n\n• **Description:**\n ${command.description}\n\n`
+ command.helpFields.forEach(i => {
+ if (text.length < 1950) {
+ text = text + `• **${i.title}:**\n ${i.desc}\n\n`
+ }
+ })
if (data.has(command.name.toLowerCase())) {
- text = text + "You have the permission to use this command."
+ text = text + "\nYou have the permission to use this command."
} else {
- text = text + "You don't have the permission to use this command."
+ text = text + "\nYou don't have the permission to use this command."
}
message.channel.send(text)
}
@@ -42,12 +53,28 @@ Command.code = async (client, message) => {
if (message.channel.permissionsFor(message.guild.members.get(client.user.id)).serialize().EMBED_LINKS) {
embed.setTitle(`${client.user.username} help information`)
embed.setDescription(`Type ${client.config.prefix[0]}help command-name to get more information.`)
+ var oldData = data;
+ data = Array.from(data)
+ var n = 0
+ if (!isNaN(message.content.split(" ")[1])) {
+ if (parseInt(message.content.split(" ")[1]) >= 0 || (parseInt(message.content.split(" ")[1]) - 1) * 25 < data.length) {
+ n = (parseInt(message.content.split(" ")[1]) - 1) * 25;
+ }
+ }
+ data = data.splice(n, 25)
data.forEach((entry) => {
- var {command} = entry;
+ var {command} = entry[1];
+
return embed.addField("• " + command.name, command.description, false)
})
embed.setColor(client.config.embedColor || 0xffe13f)
- embed.setFooter("You can use " + data.size + " commands.")
+ var footer = "You can use " + oldData.size + " commands."
+ if (oldData.size > 25) {
+ footer = footer + " - do help < number > to see the next page"
+ }
+ embed.setFooter(footer)
+
+
return message.channel.send("", {embed});
}
var text = `**${client.user.username} help information**\nType \`${client.config.prefix[0]}help command-name\` to get more information.\n\n`
@@ -84,7 +111,9 @@ Command.code = async (client, message) => {
return levels.get(i.command.level) == false
})
}
+}
-
+function cap(string) {
+ return string.charAt(0).toUpperCase() + string.toLowerCase().slice(1);
}
module.exports = Command;
diff --git a/commands/reload.js b/commands/reload.js
index 578d862..6229b08 100644
--- a/commands/reload.js
+++ b/commands/reload.js
@@ -1,3 +1,4 @@
+/* eslint prefer-destructuring: 0 */
var Spark = require("../")
const Command = Spark.command("reload")
@@ -5,44 +6,55 @@ Command.setLevel(10)
Command.setDescription("Reload modules in your bot without restarting it.")
Command.code = async (client, message) => {
-
- if (!message.content.split(" ")[1]) {
- message.channel.send("Reloading all files...");
+ var edit = null;
+ var arg = message.content.split(" ")[1]
+ if (arg) {
+ arg = arg.toLowerCase()
+ }
+ if (!arg || arg == "all") {
+ edit = await message.channel.send("Reloading all files...");
reloadAll();
await reloadSearch();
- return message.channel.send("Successfully reloaded all files.");
- } else if (message.content.split(" ")[1] === "commands") {
- message.channel.send("Reloading all commands...");
+ return edit.edit("Successfully reloaded all files.");
+ } else if (arg === "commands") {
+ edit = await message.channel.send("Reloading all commands...");
reloadCommands();
await reloadSearch();
- return message.channel.send("Successfully reloaded all commands.");
- } else if (message.content.split(" ")[1] === "observers") {
- message.channel.send("Reloading all observers...");
+ return edit.edit("Successfully reloaded all commands.");
+ } else if (arg === "observers") {
+ edit = await message.channel.send("Reloading all observers...");
reloadObservers();
await reloadSearch();
- return message.channel.send("Successfully reloaded all observers.");
- } else if (message.content.split(" ")[1] === "engines") {
- message.channel.send("Reloading all engines...");
+ return edit.edit("Successfully reloaded all observers.");
+ } else if (arg === "engines") {
+ edit = await message.channel.send("Reloading all engines...");
reloadEngines();
await reloadSearch();
- return message.channel.send("Successfully reloaded engines.");
- } else if (message.content.split(" ")[1] === "snippets") {
- message.channel.send("Reloading all snippets...");
+ return edit.edit("Successfully reloaded engines.");
+ } else if (arg === "snippets") {
+ edit = await message.channel.send("Reloading all snippets...");
reloadSnippets();
await reloadSearch();
- return message.channel.send("Successfully reloaded all snippets.");
- } else if (message.content.split(" ")[1] === "permissions") {
- message.channel.send("Reloading all permission files...");
+ return edit.edit("Successfully reloaded all snippets.");
+ } else if (arg === "permissions") {
+ edit = await message.channel.send("Reloading all permission files...");
reloadPermissions();
await reloadSearch();
- return message.channel.send("Successfully reloaded all permission files.");
- } else if (message.content.split(" ")[1] === "events") {
- message.channel.send("Reloading all events...");
+ return edit.edit("Successfully reloaded all permission files.");
+ } else if (arg === "events") {
+ edit = await message.channel.send("Reloading all events...");
reloadEvents();
await reloadSearch();
- return message.channel.send("Successfully reloaded all events.");
- } else if (message.content.split(" ")[1] != "commands" && message.content.split(" ")[1] != "observers" && message.content.split(" ")[1] != "engines" && message.content.split(" ")[1] != "snippets" && message.content.split(" ")[1] != "permissions" && message.content.split(" ")[1] != "events") {
- return message.channel.send("That is an invalid option! \nPlease choose between `commands`, `observers`, `engines`, `snippets`, `permissions`, or `events`.")
+ return edit.edit("Successfully reloaded all events.");
+ } else if (![
+ "commands",
+ "observers",
+ "engines",
+ "snippets",
+ "permissions",
+ "events"
+ ].includes(arg)) {
+ return message.channel.send("Please enter a valid option! \nChoose between `commands`, `observers`, `engines`, `snippets`, `permissions`, or `events`.")
}
// Reload Functions
diff --git a/functions/engines/checkUpdate.js b/functions/engines/checkUpdate.js
index aaabddb..b7b6b80 100644
--- a/functions/engines/checkUpdate.js
+++ b/functions/engines/checkUpdate.js
@@ -26,11 +26,17 @@ Engine.code = async (client) => {
if (client.config.ignoreUpdate instanceof Array && client.config.ignoreUpdate.includes(version.version) == true) {
return
}
+ if (client.config.ignoreUpdate == true) {
+ return
+ }
}
- console.log(`${chalk.yellow("Spark")} update ${chalk.yellow(version.version)} has been released!\n\nTo update, type the following command: ${chalk.blue(command)}\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd ${chalk.red(`ignoreUpdate: ["${version.version}"]`)} to your start file.`)
- if (!discordStatus) {
+
+ if (discordStatus) {
+ console.log(`${chalk.yellow("Spark")} update ${chalk.yellow(version.version)} has been released!\n\nTo update, type the following command: ${chalk.blue(command)}\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd ${chalk.red(`ignoreUpdate: ["${version.version}"]`)} to your start file.`)
var owner = await client.fetchUser(client.config.ownerID);
owner.send(`Spark update **${version.version}** has been released!\n\nTo update, type the following command: **${command}**\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd this to your start file: \`\`\`json\nignoreUpdate: ["${version.version}"]\n\`\`\``)
+ } else {
+ console.log("You're running this bot on an unreleased version. (" + chalk.red(Spark.version) + ") compatibility and support may not be up to date with what you expect.\nIf you don't know what this means please stop the bot, and type: " + chalk.blue("npm install sparkbots") + " To get back to a stable release.")
}
}
} catch (e) {
diff --git a/package.json b/package.json
index af5180c..9d77114 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "sparkbots",
- "version": "0.1.0-beta.0",
+ "version": "0.1.0-beta.1",
"description": "Spark is a powerful modular framework that makes creating Discord bots easy.",
"main": "app.js",
"dependencies": {
diff --git a/src/CustomConfig.js b/src/CustomConfig.js
index be31257..48f329c 100644
--- a/src/CustomConfig.js
+++ b/src/CustomConfig.js
@@ -1,5 +1,5 @@
var DisableCache = require("./DisableCache.js")
-module.exports = class CustomConfig {
+class CustomConfig {
constructor(client, id) {
this.id = id;
@@ -10,11 +10,14 @@ module.exports = class CustomConfig {
setPrefix(prefix) {
if (typeof prefix == "string") {
- this.prefix = prefix;
+ this.prefix = [];
+ this.prefix.push(prefix)
this.client.emit("cc_update", this)
return "success"
} else if (typeof prefix == "object" && prefix.constructor.name == "Array") {
- if (prefix.filter(i => {return typeof i == "string"}).length === prefix.length) {
+ if (prefix.filter(i => {
+ return typeof i == "string"
+ }).length === prefix.length) {
this.prefix = prefix;
this.client.emit("cc_update", this)
return "success"
@@ -58,3 +61,4 @@ module.exports = class CustomConfig {
this.disabled.remove(type, name)
}
}
+module.exports = CustomConfig
diff --git a/src/module_classes/Command.js b/src/module_classes/Command.js
index 056cc31..39d4e0e 100644
--- a/src/module_classes/Command.js
+++ b/src/module_classes/Command.js
@@ -1,65 +1,73 @@
module.exports = function() {
- return class Command {
+ return class Command {
- constructor(name, options, client) {
- this.name = name;
- if (!options) {
- options = {}
- }
- this.options = options
- this.client = client
- this.aliases = []
- this.level = (options.level || 0)
- this.dms = false
- this.description = "No Description Provided"
- this.disabled = options.disabled
- if (this.disabled) {
- this.client.config.disabled.add("commands", this.name)
- }
+ constructor(name, options, client) {
+ this.name = name;
+ if (!options) {
+ options = {}
+ }
+ this.options = options
+ this.client = client
+ this.aliases = []
+ this.level = (options.level || 0)
+ this.helpFields = []
+ this.dms = false
+ this.description = "No Description Provided"
+ this.disabled = options.disabled
+ if (this.disabled) {
+ this.client.config.disabled.add("commands", this.name)
+ }
- }
+ }
- disable() {
- this.client.config.disabled.add("commands", this.name)
- }
+ disable() {
+ this.client.config.disabled.add("commands", this.name)
+ }
- addAlias(alias) {
- if (typeof alias != "string") {
- return console.log("Incorrect alias type, use a string")
- }
- if (this.aliases.map(i => (i.name)).indexOf == -1) {
- return console.log("This alias was already added.")
- }
- this.aliases.push({
- name: alias,
- command: this
- })
- }
+ addAlias(alias) {
+ if (typeof alias != "string") {
+ return console.log("Incorrect alias type, use a string")
+ }
+ if (this.aliases.map(i => (i.name)).indexOf == -1) {
+ return console.log("This alias was already added.")
+ }
+ this.aliases.push({
+ name: alias,
+ command: this
+ })
+ }
- setLevel(level) {
- if (typeof level != "number") {
- return console.log("To set a level, use a number")
- }
- this.level = level;
- }
+ setLevel(level) {
+ if (typeof level != "number") {
+ return console.log("To set a level, use a number")
+ }
+ this.level = level;
+ }
- allowDms(allow) {
- if (typeof allow != "boolean") {
- return console.log("To set allowDms, use a boolean")
- }
- this.dms = allow;
- }
+ allowDms(allow) {
+ if (typeof allow != "boolean") {
+ return console.log("To set allowDms, use a boolean")
+ }
+ this.dms = allow;
+ }
- setDescription(description) {
- if (typeof description != "string") {
- return console.log("To set a description, use a string")
+ setDescription(description) {
+ if (typeof description != "string") {
+ return console.log("To set a description, use a string")
+ }
+ this.description = description;
+ }
+ addHelpField(title, desc, inline) {
+ this.helpFields.push({
+ title,
+ desc,
+ inline
+ })
}
- this.description = description;
- }
- export (module) {
- module.exports = this;
- }
- }
+ export (module) {
+ module.exports = this;
+ }
+ }
}
diff --git a/src/start.js b/src/start.js
index 4922c32..0b2160b 100644
--- a/src/start.js
+++ b/src/start.js
@@ -1,6 +1,5 @@
var Chalk = require("chalk")
module.exports = (client) => {
-
function engine() {
client.dataStore.functions.engines.forEach(i => {
if (client.config.disabled.has("engines", i.engine.name)) {
@@ -36,7 +35,12 @@ module.exports = (client) => {
engine()
client.on("message", (message) => {
- client.config.prefix.forEach(async i => {
+ var p = client.config.prefix
+ if (message.channel.type == "text" && client.customConfig.has(message.guild.id) && client.customConfig.get(message.guild.id).prefix) {
+ p = client.customConfig.get(message.guild.id).prefix
+ }
+ var prefixMatched = false;
+ p.forEach(async (i, n) => {
if (message.content.startsWith(i)) {
var command = await isValidCommand(client, message, message.content.split(" ")[0].replace(i, "").toLowerCase())
if (client.config.disabled.has("commands", command.name)) {
@@ -48,22 +52,18 @@ module.exports = (client) => {
}
}
if (command.value == true) {
+ prefixMatched = true
if (await observer(client, message, command.value)) {
executeCommand(client, message, command.name)
}
- } else {
+ }
+ if ((n + 1) == p.length && prefixMatched == false) {
await observer(client, message)
}
- } else {
- await observer(client, message)
}
})
})
-
-
-
-
}
async function observer(client, message, command) {
@@ -90,10 +90,15 @@ async function observer(client, message, command) {
} catch (e) {
console.log(e)
}
- if (results.includes(true)) {
- return false;
+ try {
+ if (results.includes(true)) {
+ return false;
+ }
+ return true;
+ } catch (e) {
+ console.log(e)
+ return false
}
- return true;
}
if (ignoreBots == 2 || ignoreBots == 4) {
return
@@ -167,7 +172,10 @@ async function isValidCommand(client, message, commandName) {
}
function executeCommand(client, message, commandName) {
- var {command, location} = client.dataStore.commands.get(commandName)
+ var {
+ command,
+ location
+ } = client.dataStore.commands.get(commandName)
try {
if (message.channel.type == "dm" && command.dms) {
command.code(client, message)