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

Commit 5f890a0

Browse files
authored
Merge pull request #54 from Sparkbots/Development
V0.1.0-beta 1
2 parents 5dad52d + 8688281 commit 5f890a0

File tree

11 files changed

+309
-219
lines changed

11 files changed

+309
-219
lines changed

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
language: node_js
22
node_js:
3+
- "7"
34
- "8"
5+
- "9"
6+
47
install: npm install
8+
script: node app
59
jobs:
610
include:
711
- stage: ESLint
12+
node_js: "8"
813
script: npm test
914
- stage: Mocha
15+
node_js: "8"
1016
script: npm run mocha-test
17+
18+
matrix:
19+
allow_failures:
20+
- node_js: "7"
21+
22+
notifications:
23+
webhooks:
24+
urls:
25+
- https://api.discordspark.com/travis
26+
on_success: always
27+
on_failure: always
28+
on_start: always
29+
on_cancel: always
30+
on_error: always
31+
email: false

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
## Spark is a powerful modular framework that makes creating Discord bots easy
33

44
[![Discord](https://discordapp.com/api/guilds/248505281741455360/embed.png)](https://discord.gg/TezD2Zg)
5-
[![Greenkeeper badge](https://badges.greenkeeper.io/TobiasFeld22/Spark.svg)](https://greenkeeper.io/)
6-
[![npm](https://img.shields.io/npm/v/sparkbots.svg)](https://npmjs/sparkbots)
7-
![Branch](https://img.shields.io/badge/Branch-Stable-orange.svg)
8-
[![Build Status](https://api.travis-ci.org/TobiasFeld22/Spark.svg?branch=Stable)](https://travis-ci.org/TobiasFeld22/Spark)
9-
![Branch_rewrite](https://img.shields.io/badge/Branch-Rewrite-orange.svg)
10-
[![Build Status rewrite](https://api.travis-ci.org/TobiasFeld22/Spark.svg)](https://travis-ci.org/TobiasFeld22/Spark)<br>
5+
[![npm](https://api.discordspark.com/badge/npm)](https://npmjs.com/sparkbots)
6+
[![Build Status](https://api.travis-ci.org/Sparkbots/Spark.svg?branch=Stable)](https://travis-ci.org/TobiasFeld22/Spark) <br>
117

128

139
##### About Spark.

app.js

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const chalk = require("chalk")
44
const startBot = require("./src/start.js")
55
const confirmConfig = require("./src/confirmConfig.js")
66
let Client;
7+
if (Number(process.version.slice(1).split(".")[0]) < 8) {
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");
9+
}
710

811
/*
912
All modular classes
@@ -44,94 +47,97 @@ exports.event = function(name, options) {
4447
}
4548

4649
exports.start = function(options) {
47-
if (!confirmConfig(options)) {
48-
return
49-
}
50-
if (typeof options.ignoreBots != "boolean" && typeof options.ignoreBots != "string" && options.ignoreBots != null) {
51-
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")}`)
52-
}
53-
if (options.ignoreBots == true) {
54-
options.ignoreBots = 4;
55-
} else if (options.ignoreBots == false) {
56-
options.ignoreBots = null
57-
} else if (options.ignoreBots == "message") {
58-
options.ignoreBots = 1
59-
} else if (options.ignoreBots == "command") {
60-
options.ignoreBots = 2
61-
}
50+
return new Promise(function(resolve, reject) {
6251

63-
Client = class Client extends discord.Client {
64-
constructor(config) {
65-
super(config)
66-
this.version = require("./package.json").version
67-
this.config = {}
68-
this.customConfig = new exports.DataStore()
69-
this.CustomConfig = exports.CustomConfig
52+
if (!confirmConfig(options)) {
53+
return reject("There was an error in your configuration setup, There may be additional messages above.")
7054
}
71-
72-
async search() {
73-
var data = await require("./src/search.js").func(this)
74-
return data;
55+
if (typeof options.ignoreBots != "boolean" && typeof options.ignoreBots != "string" && options.ignoreBots != null) {
56+
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")}`)
57+
return reject()
7558
}
76-
async start() {
77-
this.dataStore = await this.dataStore;
78-
if (this.config.first) {
79-
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-------------------`)
59+
if (options.ignoreBots == true) {
60+
options.ignoreBots = 4;
61+
} else if (options.ignoreBots == false) {
62+
options.ignoreBots = null
63+
} else if (options.ignoreBots == "message") {
64+
options.ignoreBots = 1
65+
} else if (options.ignoreBots == "command") {
66+
options.ignoreBots = 2
67+
}
68+
69+
Client = class Client extends discord.Client {
70+
constructor(config) {
71+
super(config)
72+
this.version = require("./package.json").version
73+
this.config = {}
74+
this.customConfig = new exports.DataStore()
75+
this.CustomConfig = exports.CustomConfig
8076
}
8177

82-
function colours(text, size) {
83-
if (size == 0) {
84-
return chalk.red(text)
85-
}
86-
return chalk.green(text)
78+
async search() {
79+
var data = await require("./src/search.js").func(this)
80+
return data;
8781
}
88-
var commandtext = colours(`${this.dataStore.commands.size} commands\n`, this.dataStore.commands.size)
89-
var observertext = colours(`${this.dataStore.functions.observer.size} observers\n`, this.dataStore.functions.observer.size)
90-
var enginetext = colours(`${this.dataStore.functions.engines.size} engines\n`, this.dataStore.functions.engines.size)
91-
var snippettext = colours(`${this.dataStore.functions.snippet.size} snippets\n`, this.dataStore.functions.snippet.size)
92-
var permissiontext = colours(`${this.dataStore.permissions.size} permissions\n`, this.dataStore.permissions.size)
93-
var eventtext = colours(`${this.dataStore.events.size} events\n`, this.dataStore.events.size)
94-
startBot(this)
82+
async start() {
83+
this.dataStore = await this.dataStore;
84+
if (this.config.first) {
85+
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-------------------`)
86+
}
9587

96-
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}`)
97-
}
88+
function colours(text, size) {
89+
if (size == 0) {
90+
return chalk.red(text)
91+
}
92+
return chalk.green(text)
93+
}
94+
var commandtext = colours(`${this.dataStore.commands.size} commands\n`, this.dataStore.commands.size)
95+
var observertext = colours(`${this.dataStore.functions.observer.size} observers\n`, this.dataStore.functions.observer.size)
96+
var enginetext = colours(`${this.dataStore.functions.engines.size} engines\n`, this.dataStore.functions.engines.size)
97+
var snippettext = colours(`${this.dataStore.functions.snippet.size} snippets\n`, this.dataStore.functions.snippet.size)
98+
var permissiontext = colours(`${this.dataStore.permissions.size} permissions\n`, this.dataStore.permissions.size)
99+
var eventtext = colours(`${this.dataStore.events.size} events\n`, this.dataStore.events.size)
100+
startBot(this)
101+
102+
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}`)
103+
}
98104

99-
}
100-
Client = new Client(options.clientOptions);
101-
Client.on("cc_update", function(data) {
102-
Client.customConfig.set(data.id, data)
103-
});
104-
Client.config = options
105-
Client.login(options.token).then(async () => {
106-
try {
107-
var application = await Client.fetchApplication()
108-
Client.config.ownerID = application.owner.id
109-
} catch (e) {
110-
console.log(e)
111-
throw Error("Couldn't fetch application, token may be a invalid / user token. ")
112105
}
113-
Client.guilds.forEach(i => {
114-
i.customConfig = new exports.CustomConfig(Client, i.id);
115-
Client.customConfig.set(i.id, i.customConfig)
116-
})
117-
Client.dataStore = await Client.search()
118-
Client.snippets = {
119-
list: (name) => {
120-
if (!name) {
121-
return Client.dataStore.functions.snippet.map((i, n) => n)
122-
} else if (Client.dataStore.functions.snippet.has(name)) {
123-
return Client.dataStore.functions.snippet.get(name)
106+
Client = new Client(options.clientOptions);
107+
Client.on("cc_update", function(data) {
108+
Client.customConfig.set(data.id, data)
109+
});
110+
Client.config = options
111+
Client.login(options.token).then(async () => {
112+
try {
113+
var application = await Client.fetchApplication()
114+
Client.config.ownerID = application.owner.id
115+
} catch (e) {
116+
console.log(e)
117+
throw Error("Couldn't fetch application, token may be a invalid / user token. ")
118+
}
119+
Client.guilds.forEach(i => {
120+
i.customConfig = new exports.CustomConfig(Client, i.id);
121+
Client.customConfig.set(i.id, i.customConfig)
122+
})
123+
Client.dataStore = await Client.search()
124+
Client.snippets = {
125+
list: (name) => {
126+
if (!name) {
127+
return Client.dataStore.functions.snippet.map((i, n) => n)
128+
} else if (Client.dataStore.functions.snippet.has(name)) {
129+
return Client.dataStore.functions.snippet.get(name)
130+
}
131+
return null;
124132
}
125-
return null;
126133
}
127-
}
128-
Client.dataStore.functions.snippet.forEach((i, n) => {
129-
Client.snippets[n] = i.snippet.code
134+
Client.dataStore.functions.snippet.forEach((i, n) => {
135+
Client.snippets[n] = i.snippet.code
136+
})
137+
Client.start(Client)
138+
}).catch(err => {
139+
return reject(console.error("An error occured while trying to login, check your token.", err))
130140
})
131-
Client.start(Client)
132-
133-
}).catch(err => {
134-
return console.error("An error occured while trying to login, check your token.", err)
135-
})
136141

142+
});
137143
}

commands/about.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
var Spark = require("../")
22
const Command = Spark.command("about")
3-
const embed = new Spark.methods.RichEmbed();
43

54
Command.setLevel(0)
65
Command.setDescription("Get information about this bot.")
76

87
Command.code = async (client, message) => {
98

109
var v = process.memoryUsage().heapUsed
11-
v = (v/1024/1024).toFixed(3);
10+
v = (v / 1024 / 1024).toFixed(3);
1211

13-
var prefixText = prefixList().map(i => i).join(", ")
14-
if (prefixList().length > 1){
15-
prefixText = prefixList().map(i => ("`" + i + "`")).join(", ")
12+
var prefixText = prefixList().map(i => i).join(", ")
13+
if (prefixList().length > 1) {
14+
prefixText = prefixList().map(i => ("`" + i + "`")).join(", ")
1615
}
1716
if (message.channel.permissionsFor(message.guild.members.get(client.user.id)).serialize().EMBED_LINKS) {
18-
embed.setTitle(`Information about ${client.user.username}`)
19-
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`+
20-
"Spark is a powerful modular framework that makes creating Discord bots easy.")
21-
embed.addField("Prefix(es):", prefixText, true)
22-
embed.addField("Servers:", client.guilds.size, true)
23-
embed.addField("Users:", client.users.size, true)
24-
embed.addField("Memory Usage:", `${v} MB`, false)
25-
embed.addField("Spark Version:", Spark.version, false)
26-
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)
27-
embed.setFooter("Made with Spark")
28-
embed.setTimestamp()
29-
embed.setColor(0xe1e818)
30-
return message.channel.send("", {embed})
17+
const embed = new Spark.methods.RichEmbed();
18+
embed.setTitle(`Information about ${client.user.username}`)
19+
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` +
20+
"Spark is a powerful modular framework that makes creating Discord bots easy.")
21+
embed.addField("Prefix(es):", prefixText, true)
22+
embed.addField("Servers:", client.guilds.size, true)
23+
embed.addField("Users:", client.users.size, true)
24+
embed.addField("Memory Usage:", `${v} MB`, false)
25+
embed.addField("Spark Version:", Spark.version, false)
26+
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)
27+
embed.setFooter("Made with Spark")
28+
embed.setTimestamp()
29+
embed.setColor(0xe1e818)
30+
return message.channel.send("", {embed})
3131
}
3232
var owner = await client.fetchUser(client.config.ownerID);
33-
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`+
34-
"Spark is a powerful modular framework that makes creating Discord bots easy.\n\n" +
35-
`My prefix(es) are: ${prefixText}.\n`+
36-
// "My ping is: {bot_latency}ms.\n"+
37-
`I am running on version \`${Spark.version}\` of spark.\n\n`+
38-
"__Statistics__\n"+
39-
`I am currently in \`${client.guilds.size}\` servers.\n`+
40-
`I am being used by \`${client.users.size}\` users.\n`+
41-
`I am using \`${v}\` MB of memory.\n\n`+
42-
"For more information about the **Spark** framework visit https://discord.gg/TezD2Zg or the website https://discordspark.com")
33+
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` +
34+
"Spark is a powerful modular framework that makes creating Discord bots easy.\n\n" +
35+
`My prefix(es) are: ${prefixText}.\n` +
36+
// "My ping is: {bot_latency}ms.\n"+
37+
`I am running on version \`${Spark.version}\` of spark.\n\n` +
38+
"__Statistics__\n" +
39+
`I am currently in \`${client.guilds.size}\` servers.\n` +
40+
`I am being used by \`${client.users.size}\` users.\n` +
41+
`I am using \`${v}\` MB of memory.\n\n` +
42+
"For more information about the **Spark** framework visit https://discord.gg/TezD2Zg or the website https://discordspark.com")
4343

4444
function prefixList() {
45-
if (client.customConfig.get(message.guild.id).prefix) {
46-
return client.customConfig.get(message.guild.id).prefix
47-
}
48-
return client.config.prefix
49-
}
45+
if (client.customConfig.get(message.guild.id).prefix) {
46+
return client.customConfig.get(message.guild.id).prefix
47+
}
48+
return client.config.prefix
49+
}
5050

5151
}
5252
module.exports = Command;

0 commit comments

Comments
 (0)