Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #54 from Sparkbots/Development
Browse files Browse the repository at this point in the history
V0.1.0-beta 1
  • Loading branch information
TobiasFeld22 authored May 6, 2018
2 parents 5dad52d + 8688281 commit 5f890a0
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 219 deletions.
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<br>
[![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) <br>


##### About Spark.
Expand Down
160 changes: 83 additions & 77 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})

});
}
66 changes: 33 additions & 33 deletions commands/about.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
var Spark = require("../")
const Command = Spark.command("about")
const embed = new Spark.methods.RichEmbed();

Command.setLevel(0)
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;
Loading

0 comments on commit 5f890a0

Please sign in to comment.